[Howto] migrate a bootable filesystem from UFS to mirrored ZFS

posted in: computer | 0

for example we use 2 new HDDs, which are called ada0 and ada1. Quick steps:

  • you have to create 2 partitions on the new disks (1st for the zfs-bootloader,  2nd for the zfs itself)
  • you have to set the first partition as bootable on both disks (= bootme-flag)
  • you have to install the protected-mbr (= pmbr) into the MBR (= sector 0) on both disks
  • you have to install the zfs-bootloader (= gptzfsboot) into the 1st partition on both disks
  • you have to create a new zpool and use for this both 2nd partitions (the zfs will be auto-created)
  • you have to set the zfs as bootable
  • you habe to set the correct mountpoint in zfs
  • you have to copy your existent bootable filesystem to zfs (e.g. all directories/files from ufs to zfs)
  • you have to edit the root-entry in /etc/fstab and change it to zfs
  • you have to copy the correct zpool.cache-file into your zfs (it’s essentially for importing the zpool while booting)

 

create a new GPT’s

gpart create -s gpt /dev/ada0
gpart create -s gpt /dev/ada1

 

create the partitions

gpart add -b 40 -s 512k -a 4k -t freebsd-boot /dev/ada0
gpart add -b 1064 -s 20g -a 4k -t freebsd-zfs /dev/ada0

gpart add -b 40 -s 512k -a 4k -t freebsd-boot /dev/ada1
gpart add -b 1064 -s 20g -a 4k -t freebsd-zfs /dev/ada1

 

set the partitions in GPT as bootable

gpart set -a bootme -i 1 /dev/ada0
gpart set -a bootme -i 1 /dev/ada1

 

install the protected-mbr and the zfs-bootloader

gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 /dev/ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 /dev/ada1

 

create the mirrored zpool with the corresponding zfs

zpool create tank mirror /dev/ada0p2 /dev/ada1p2

 

set the zfs as bootable

zpool set bootfs=tank tank

 

set the mountpoint in zfs

zfs set mountpoint=/ tank

 

copy your existent filesystem data

#mount your old ufs and the new zfs
cp -a /ufs-mountdir/* /zfs-mountdir/

 

edit the root-entry in your /etc/fstab

#Device    Mountpoint   FStype    Options   Dump    Pass
tank       /            zfs       sw        0       0

 

copy zpool.cache – file into zfs

zpool import -o altroot=/tmp/tank -o cachefile=/tmp/zpool.cache tankcp /tmp/zpool.cache /tmp/tank/boot/zfs/zpool.cache