How to migrate from UFS to ZFS

I have working FreeBSD 15.0-RELEASE installation on a disk which is using UFS.

How would I go about converting it to ZFS?

Can I back it up elsewhere and then restore it? Or do I need to install FreeBSD to create a ZFS system on the disk first in the first place?
 
Or do I need to install FreeBSD to create a ZFS system on the disk first in the first place?
That's the cleanest and easiest to do. It's all doable by hand but there's a lot of ZFS datasets (with specific options) that should be created and the installer does it all automagically for you. And it's always nice to start with a fresh new install every once in a while. Definitely create a backup of the old system, you can selectively restore some items from it, like specific configuration files. Files from your home directory perhaps.
 
I encountered the same situation.
I backed up my data.
The system configuration /usr/local/* & co.
I reinstalled the system in new filesystem zfs and restored datas and the third-party packages from a .txt list
 
I came across this shell script for installing FreeBSD on ZFS. It supposed to be run when is booted from mfsbsd

Unfortunately I can't get it woking. Can anyone see any errors.

It runs initially but then says 'zfs not found'


sh:
#!/bin/sh
set -e

DISK="ada0"
POOL="zroot"
HOSTNAME="freebsd"

echo "=== Destroying disk ==="
gpart destroy -F ${DISK} || true
gpart create -s gpt ${DISK}

echo "=== Creating partitions ==="
gpart add -t efi -s 260M ${DISK}
gpart add -t freebsd-zfs ${DISK}

echo "=== Formatting EFI ==="
newfs_msdos -F 32 /dev/${DISK}p1

echo "=== Loading ZFS ==="
kldload zfs || true

echo "=== Creating ZFS pool ==="
zpool create -f -o ashift=12 \
  -O atime=off \
  -O compression=lz4 \
  -O mountpoint=none \
  ${POOL} /dev/${DISK}p2

echo "=== Creating datasets ==="
zfs create -o mountpoint=none ${POOL}/ROOT
zfs create -o mountpoint=/ ${POOL}/ROOT/default
zfs create -o mountpoint=/tmp ${POOL}/tmp
zfs create -o mountpoint=/usr ${POOL}/usr
zfs create ${POOL}/usr/home

chmod 1777 /tmp
zpool set bootfs=${POOL}/ROOT/default ${POOL}

echo "=== Mounting target ==="
mkdir -p /mnt
mount -t zfs ${POOL}/ROOT/default /mnt
mkdir -p /mnt/boot/efi
mount -t msdosfs /dev/${DISK}p1 /mnt/boot/efi

echo "=== Installing base system ==="
cd /usr/freebsd-dist
tar -xpf base.txz -C /mnt
tar -xpf kernel.txz -C /mnt

echo "=== Configuring system ==="
cat << EOF > /mnt/etc/fstab
/dev/${DISK}p1  /boot/efi  msdosfs  rw  2  2
EOF

echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
echo "hostname=\"${HOSTNAME}\"" >> /mnt/etc/rc.conf
echo 'ifconfig_DEFAULT="DHCP"' >> /mnt/etc/rc.conf

echo "=== Setting root password ==="
chroot /mnt passwd

echo "=== Installing EFI bootloader ==="
mkdir -p /mnt/boot/efi/EFI/FreeBSD
cp /mnt/boot/loader.efi /mnt/boot/efi/EFI/FreeBSD/bootx64.efi

echo "=== Cleanup ==="
zfs unmount -a
zpool export ${POOL}

echo "=== DONE ==="
echo "Remove install media and reboot."
 
No need to play around with mfsbsd. Don't know why you use it in the first place. The only reason i can think of is maybe something diskless/pxe.
ok,
-First check there is disk place free :
gpart show -l
gpart show -p

gpart add -t freebsd-zfs /dev/XXX
zpool create /dev/XXX MYZFS

Boot with freebsd usb image
- Go to shell
- mount -o rw /
- kbdmap
- Mount your UFS partition
- Mount your ZFS partition
- Copy everything from UFS to ZFS with the command clone.

-Verify the bootloader , to boot "zfs" and mount the good MYZFS partition as root.

The files /boot/loader.conf & /etc/fstab can be important.
 
Note, how i personnaly installed ZFS,
-boot with usb image.
-Go to shell
-mount -o rw /
-kbdmap
-gpart add -l MYZFS -t freebsd-zfs -s mysize /dev/XXX
-zpool create /dev/XXX MYZFS
-pkg install wget
Go to the zfs mount , normally it gets mounted automaticly , "zfs mount"
-Grabbed the files with wget kernel.txz & base.txz from
https://download.freebsd.org/releases/amd64/15.0-RELEASE/
- tar xvfz kernel.txz
- tar xvfz base.txz

OS install is ready.
The only thing now to check is the boot & loader. But this config can be different for everyone. So i cannot give an answer.
There are Windows loader , you can use grub , you can use a separate boot partition, you can boot (u)efi or MBR.

Feel free to ask.
On booting SirDice might give good answers if you provide information on your personal setup.
 
That's the cleanest and easiest to do. It's all doable by hand but there's a lot of ZFS datasets (with specific options) that should be created and the installer does it all automagically for you. And it's always nice to start with a fresh new install every once in a while. Definitely create a backup of the old system, you can selectively restore some items from it, like specific configuration files. Files from your home directory perhaps.

Can I copy the contents of /usr/local from my backup to the new system?

I'm hoping to avoid reinstalling all the pkgs but have no idea if this is possible.
 
Your new package database will be unaware of your copy.
So if you do "pkg info" on your new system it will not list the packages you copied from /usr/local.
 
Make sure you restore /var/db/pkg along with /usr/local. And /boot/module for any kernel modules from packages.
 
Why not just Keep It Simple, Stupid?

Sometimes, keeping things simple is actually the smartest thing to do, because no amount of RTFMing on the technical intricacies is gonna save OP's system from disaster. The easiest thing for OP to do is to make a backup of personal stuff, and then go for a clean install, and pay attention to choose the ZFS option in the installer, as per the Hanbdook. That will save a LOT of time down the road. Debugging the mistakes and untangling train wrecks can be completely avoided if OP keeps it simple.
 
Reinstalling skips a valuable learning experience.

/var/db/pkg and /usr/local can be tarred up and restored. As mentioned above, you want to drag around kernel modules installed by packages. I would reinstall those packages.
 
Note , once i was un-knowledgable and i installed a bootloader in the MBR of a disk. My windows became un bootable. Valuable lesson.
 
In answer to my own question, that works fine. Sigh of relief..
Too soon!

pkg list shows a number of pkgs, Some I can run, some I can't.

When i try to install the ones I can't run, I'm told they are already installed!

Just wondered if there was a '-f' parameter to force an installation.

I don't see one listed in the man page, but tried it anyway, and it worked!
 
Back
Top