Posted in: Uncategorized

Geom Root mirror & ZFS Data

Just a Quick post to record how to install freebsd on a system with 2 internal disks that are mirrored via geom for the o/s (root, swap, boot, tmp, var, usr) and the data is on the remainder of the disks again mirrored but this time by a zfs pool

Install FreeBSD on system with 3 disks,  ensuring disk #1 & #2 are the same size and are the target mirror pair,  disk 3 should be large enough to hold the base o/s at your partition sizes (64Gb in my case)

initial install disk is ada2, and the final mirror pair is ada0, ada1

Script to run once o/s installed initally

gpart destroy -F ada0
gpart destroy -F ada1
gpart create -s gpt ada0
gpart add -s 64k -t freebsd-boot ada0
gpart add -s 4G -t freebsd-ufs ada0
gpart add -s 4G -t freebsd-swap ada0
gpart add -s 8G -t freebsd-ufs ada0
gpart add -s 16G -t freebsd-ufs ada0
gpart add -s 32G -t freebsd-ufs ada0
gpart add -t freebsd-zfs ada0
gpart create -s gpt ada1
gpart add -s 64k -t freebsd-boot ada1
gpart add -s 4G -t freebsd-ufs ada1
gpart add -s 4G -t freebsd-swap ada1
gpart add -s 8G -t freebsd-ufs ada1
gpart add -s 16G -t freebsd-ufs ada1
gpart add -s 32G -t freebsd-ufs ada1
gpart add -t freebsd-zfs ada1
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada0
gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 ada1
gpart modify -i 1 -l boot0 ada0
gpart modify -i 1 -l boot1 ada1
gpart modify -i 2 -l root0 ada0
gpart modify -i 2 -l root1 ada1
gpart modify -i 3 -l swap0 ada0
gpart modify -i 3 -l swap1 ada1
gpart modify -i 4 -l tmp0 ada0
gpart modify -i 4 -l tmp1 ada1
gpart modify -i 5 -l var0 ada0
gpart modify -i 5 -l var1 ada1
gpart modify -i 6 -l usr0 ada0
gpart modify -i 6 -l usr1 ada1
gpart modify -i 7 -l zfs0 ada0
gpart modify -i 7 -l zfs1 ada1
true > /dev/ada0
true > /dev/ada1
gmirror label boot /dev/gpt/boot0 /dev/gpt/boot1
gmirror label root /dev/gpt/root0 /dev/gpt/root1
gmirror label swap /dev/gpt/swap0 /dev/gpt/swap1
gmirror label tmp /dev/gpt/tmp0 /dev/gpt/tmp1
gmirror label var /dev/gpt/var0 /dev/gpt/var1
gmirror label usr /dev/gpt/usr0 /dev/gpt/usr1
newfs -U -L root /dev/mirror/root
mount /dev/mirror/root /mnt
dump -C 32 -0af - / | (cd /mnt && restore -rf -)
newfs -U -L tmp /dev/mirror/tmp
newfs -U -L var /dev/mirror/var
newfs -U -L usr /dev/mirror/usr
mount /dev/mirror/tmp /mnt/tmp
mount /dev/mirror/var /mnt/var
mount /dev/mirror/usr /mnt/usr
dump -C 32 -0af - /tmp | (cd /mnt/tmp && restore -rf -)
dump -C 32 -0af - /var | (cd /mnt/var && restore -rf -)
dump -C 32 -0af - /usr | (cd /mnt/usr && restore -rf -)
zpool create -f -m none samba mirror gpt/zfs0 gpt/zfs1
zfs create -o mountpoint=/u01 samba/u01
zfs create -o mountpoint=/u02 samba/u02
zfs create -o mountpoint=/u03 samba/u03
zfs create -o mountpoint=/u04 samba/u04
zfs create -o mountpoint=/u05 samba/u05
zfs create -o mountpoint=/u06 samba/u06
zfs create -o mountpoint=/u07 samba/u07
zfs create -o mountpoint=/u08 samba/u08
zfs create -o mountpoint=/u09 samba/u09
zfs create -o mountpoint=/u10 samba/u10
zfs create -o mountpoint=/u11 samba/u11
zfs create -o mountpoint=/u12 samba/u12
zfs create -o mountpoint=/home samba/home
zfs set quota=1G samba/u01
zfs set quota=6G samba/u02
zfs set quota=10G samba/u03
zfs set quota=6G samba/u04
zfs set quota=8G samba/u05
zfs set quota=8G samba/u06
zfs set quota=2G samba/u07
zfs set quota=2G samba/u08
zfs set quota=6G samba/u09
zfs set quota=1G samba/u10
zfs set quota=3G samba/u11
zfs set quota=4G samba/u12
zfs set quota=16G samba/home
echo 'zfs_enable="YES"' >> /etc/rc.conf

You will need to add geom_mirror_load=”YES” to /boot/loader.conf,  edit /etc/fstab to reflect the new mount points for root, swap etc (these will be the labels we gave the geom mirrors (/dev/mirror/root etc..)

Now reboot from ada0 …

References

http://www.ateamsystems.com/blog/Installing-FreeBSD-9-gmirror-GPT-partitions-raid-1

http://scratching.psybermonkey.net/2010/06/freebsd-how-to-format-partition.html

http://www.freebsd.org/doc/handbook/geom-mirror.html