Skip to content

FreeBSD & ZFS Notes to self

ZFS Datarecovery:

If you have a ZFS pool with expired redundancy, you can try this in FreeBSD
Recover data of a zpool with I/O errors without redundancy

sysctl vfs.zfs.spa.load_verify_metadata=0
sysctl vfs.zfs.spa.load_verify_data=0
zpool import -F -R /mnt -N -f -o readonly=on *yourpool*

And what can be saved will be saved.
Remember to change back the sysctl’s after data recovery.

(the solution is for FreeBSD. Linux/Solaris uses other ways to set libzfs options, mdb for Solaris, different systl-s for Linux)

Resize bhyve vm image:

So you have a vm running low on disk space. Run the following commands to resize the image file.

pkg install e2fsprogs
cd /zroot/bhyve/<vm-name>

# Use truncate to allocate diskspace for the image
truncate -s<newsize> disk0.img

# Use mdconfig to be able to make changes to image
mdconfig disk0.img

# Reveal the partion scheme with gpart
gpart show md0
gpart recover md0      # Run if you get "gpart: table 'md0' is corrupt: Operation not permitted" This is sign of GPT scheme

gpart resize -iN md0   # N - the partition index

# Run fsck on the partition to be sure that everything is good
e2fsck -f /dev/md0pN   # N - the partition index

# The actual resize command, this will take a while depending on size
resize2fs /dev/md0pN   # could be md0pN in case of GPT scheme

# Close the image.
mdconfig -d -u0
Published inBSD

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.