FreeBSD 9.0 ZFS root on OVH

- zfs freebsd

I had so much pain to make it work so here is how to have a ZFS root with a raidz pool on 5 disks, specially with OVH without any console or kvm to debug the boot process.

The server has 5 disks that I put in raidz and boot on it, but this should apply to most installation.

gpart destroy -F ada0
gpart destroy -F ada1
gpart destroy -F ada2
gpart destroy -F ada3
gpart destroy -F ada4

gpart create -s gpt ada0
gpart create -s gpt ada1
gpart create -s gpt ada2
gpart create -s gpt ada3
gpart create -s gpt ada4

gpart add -b 34 -s 64k -t freebsd-boot ada0
gpart add -b 34 -s 64k -t freebsd-boot ada1
gpart add -b 34 -s 64k -t freebsd-boot ada2
gpart add -b 34 -s 64k -t freebsd-boot ada3
gpart add -b 34 -s 64k -t freebsd-boot ada4

# if you are very low on ram use a real partition for swap otherwise don't  
gpart add -s 4G -t freebsd-swap -l swap0 ada0 
gpart add -s 4G -t freebsd-swap -l swap1 ada1 
gpart add -s 4G -t freebsd-swap -l swap2 ada2 
gpart add -s 4G -t freebsd-swap -l swap3 ada3 
gpart add -s 4G -t freebsd-swap -l swap4 ada4  

gpart add -t freebsd-zfs -l disk0 ada0 
gpart add -t freebsd-zfs -l disk1 ada1 
gpart add -t freebsd-zfs -l disk2 ada2 
gpart add -t freebsd-zfs -l disk3 ada3 
gpart add -t freebsd-zfs -l disk4 ada4  

gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0 
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1 
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada2 
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada3 
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada4  

zpool create -o cachefile=/boot/zfs/zpool.cache -m none -f rpool raidz /dev/gpt/disk0 /dev/gpt/disk1 /dev/gpt/disk2 /dev/gpt/disk3 /dev/gpt/disk4 
#cannot mount '/rpool': failed to create mountpoint  
zfs set checksum=fletcher4 rpool 
zfs create rpool/root 
mkdir /tmp/mntzfs 
zfs set mountpoint=/tmp/mntzfs rpool/root  
zfs create -o canmount=off  rpool/root/usr 
zfs create  -o canmount=off rpool/root/var 
zfs create -o compression=on -o exec=on -o setuid=off rpool/root/tmp 
zfs create -o compression=gzip -o setuid=off  rpool/root/usr/ports 
zfs create -o compression=off -o exec=off -o setuid=off rpool/root/usr/ports/distfiles 
zfs create -o compression=off -o exec=off -o setuid=off rpool/root/usr/ports/packages 
zfs create -o compression=gzip -o exec=off -o setuid=off  rpool/root/usr/src 
zfs create -o compression=lzjb rpool/root/usr/obj zfs create -o compression=lzjb  -o exec=off     -o setuid=off   rpool/root/var/crash 
zfs create -o compression=off -o exec=off -o setuid=off   rpool/root/var/empty 
zfs create -o compression=lzjb  -o exec=on -o setuid=off   rpool/root/var/tmp  
zpool export rpool 
zpool import -o cachefile=/tmp/zpool.cache rpool chmod 1777 /tmp/mntzfs/tmp chmod 1777 /tmp/mntzfs/var/tmp  
sh cd /tmp/mntzfs 
mkdir fileinstall 
cd fileinstall 
export DESTDIR=/tmp/mntzfs 
for file in base.txz kernel.txz doc.txz src.txz; 
do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); 

cp /tmp/zpool.cache /tmp/mntzfs/boot/zfs/zpool.cache 
echo 'zfs_enable="YES"' >> /tmp/mntzfs/etc/rc.conf 
echo 'zfs_load="YES"' >> /tmp/mntzfs/boot/loader.conf 
echo 'if_em_load="YES"' >> /tmp/mntzfs/boot/loader.conf 
echo 'vfs.root.mountfrom="zfs:rpool/root"' >> /tmp/mntzfs/boot/loader.conf  
echo 'sshd_enable="YES"' >> /tmp/mntzfs/etc/rc.conf 
echo 'ifconfig_em0="inet 188.165.XXX.XXX netmask broadcast 188.165.XXX.255"' >> /tmp/mntzfs/etc/rc.conf 
echo 'defaultrouter="188.165.XXX.254"' >> /tmp/mntzfs/etc/rc.conf 
echo 'hostname=""' >> /tmp/mntzfs/etc/rc.conf  
chroot /tmp/mntzfs /bin/sh 
passwd root 
vi /etc/ssh/sshd_config 
# Change PermitRootLogin to yes for debug only exit  

zfs set mountpoint=legacy rpool/root
zfs set mountpoint=/tmp rpool/root/tmp 
zfs set mountpoint=/usr rpool/root/usr 
zfs set mountpoint=/var rpool/root/var 
zpool set bootfs=rpool/root rpool  

# not if you are low on RAM 
zfs create -V 8G rpool/swap 
zfs set checksum=off rpool/swap 
zfs set org.freebsd:swap=on rpool/swap  

zfs set readonly=on rpool/root/var/empty 
touch /tmp/mntzfs/etc/fstab 
# or add the swap if you use real partition 
cd /   
zfs umount -a

EDIT: as mentioned here do not put the swap in the zpool if you are low on ram or unstability will occur. [ current/2007-September/076831.html]( /freebsd-current/2007-September/076831.html)