ZFS: Maintenance

Cloning a live FreeBSD ZFS System

by ken at 11:46:54 on April 11, 2016

This is the default bsdinstall zfs partition layout we're cloning:

ken@ras00005 ~ % gpart show
=>       34  976773101  ada0  GPT  (466G)
         34          6        - free -  (3.0K)
         40       1024     1  freebsd-boot  (512K)
       1064        984        - free -  (492K)
       2048    4194304     2  freebsd-swap  (2.0G)
    4196352  972576768     3  freebsd-zfs  (464G)
  976773120         15        - free -  (7.5K)

These are the default filesystems created by bsdinstall. We're going to replicate this on a new computer:

root@ras00005 ~ # zfs list
NAME                 USED  AVAIL  REFER  MOUNTPOINT
zroot               1.65G   444G    96K  /zroot
zroot/ROOT           767M   444G    96K  none
zroot/ROOT/default   767M   444G   761M  /
zroot/tmp            160K   444G    96K  /tmp
zroot/usr            917M   444G    96K  /usr
zroot/usr/home       256K   444G   180K  /usr/home
zroot/usr/ports      917M   444G   917M  /usr/ports
zroot/usr/src         96K   444G    96K  /usr/src
zroot/var           1.02M   444G    96K  /var
zroot/var/audit       96K   444G    96K  /var/audit
zroot/var/crash       96K   444G    96K  /var/crash
zroot/var/log        452K   444G   280K  /var/log
zroot/var/mail       204K   444G   124K  /var/mail
zroot/var/tmp        104K   444G    96K  /var/tmp

1. On the new server, run the FreeBSD 10.2 setup program. Choose LiveCD and login as root.

2. Enable SSH (thanks to brainbugs.net):

# mkdir /tmp/etc
# mount_unionfs /tmp/etc /etc
# mkdir /tmp/root
# mount_unionfs /tmp/root /root

Edit /etc/ssh/sshd_config and set PermitRootLogin to yes.

Configure the network adapter. Set the device node and IP addresses appropriately for your network:

# ifconfig bge0 inet 10.0.0.10 netmask 255..255.0.0
# route add default 10.0.0.1

3. Start sshd:

# echo sshd_enable="YES" >> /etc/rc.conf
# service sshd start

4. Set a password:

# passwd

5. Back on the host system that you're replicating, backup the partition information. Set the device node accordingly for your computer:

# gpart backup ada0 > ada0.gpart

6. Copy the partition backup file to the new computer:

# scp ada0.gpart root@10.0.0.10:/tmp

7. Destroy any existing partitions on the new computer. On a new Dell I had to do this:

# gpart show ada0 (this will show the existing partitions)
# gpart delete -i 2 ada0
# gpart delete -i 1 ada0
# gpart destroy ada0

8. Create the partitions on the new computer

# gpart  restore ada0 < /tmp/ada0.gpart

9. On the new computer, make the disk bootable:

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

10. On the new computer, create the ZFS pool:

# zpool create -R /tmp/zroot zroot /dev/ada0p3

11. On the host computer, create a full system snapshot:

# zfs snapshot -r zroot@backup

12. Send the snapshot to the new computer:

# zfs send -R zroot@backup | ssh root@10.0.0.10 zfs recv -Fduv zroot

13. When the send operation completes, on the new computer, set bootfs:

# zpool set bootfs=zroot/ROOT/default zroot

14. On the new computer, mount the root :

# zfs mount zroot/ROOT/default

15. Unless the new computer is going to replace the old computer, edit rc.conf and change the IP address and hostname

# vi /tmp/zroot/etc/rc.conf

16. Reboot - that's it, you just cloned your FreeBSD 10.2 ZFS system.

Comments