Moving a FreeBSD installation onto gmirror

Assume an already installed FreeBSD 9 system living on ada0:

ada0p1    freebsd-boot
ada0p2    freebsd-ufs    /
ada0p3    freebsd-swap

We now want to create a mirror that spans ada0 and ada1 and migrate the system onto that. This takes a few simple steps.

Load geom_mirror module

kldload geom_mirror
echo 'geom_mirror_load="YES"' >> /boot/loader.conf

Create the mirror

gmirror label m0 ada1
gmirror list

Create partitions

gpart backup ada0 > /tmp/part.txt
gpart restore mirror/m0 < /tmp/part.txt

gpart bootcode -b /boot/pmbr mirror/m0
gpart bootcode -p /boot/gptboot -i 1 mirror/m0

newfs -U /dev/mirror/m0p2

Copy the system to the mirror

mount /dev/mirror/m0p2 /mnt
cd /
tar --one-file-system -cpf - . | (cd /mnt; tar -xvpf -)

Change fstab

vi /mnt/etc/fstab

Change all occurrences of "ada0" to "mirror/m0".


umount /mnt
shutdown -r now

You should now be able to select the other hard disk from the BIOS and boot from that. You will get a warning from gptboot about an invalid backup GPT header, but it is mostly harmless. The cause is that the backup header lives at the end of the disk but is offset one block because of the mirror metadata.

Add the first disk to the mirror

Check by running "mount" and "swapinfo" that you are indeed running on your mirror.


The last remaining step is now to add ada0 to the mirror.

gmirror insert m0 ada0

The mirror will now synchronize. You can check the status with "gmirror list" or "gmirror status".

gmirror status

Booting from ada0 might not work before the initial synchronization completes. I recommend not turning off or rebooting before that is done.

E-mail Valid XHTML 1.1 Valid CSS!