EFI ZFS loader success story

Ganael Laplanche ganael.laplanche at corp.ovh.com
Wed Aug 12 12:05:19 UTC 2015


Hi folks, hi Eric,

Using the patch from this post :

https://lists.freebsd.org/pipermail/freebsd-hackers/2015-June/047823.html

against -CURRENT (r286279), I've been able to boot my ZFS-root system, yeah!

For those interested, here are the steps needed to get a working system. This 
should be done on a live system to be able to operate freely on the hard disk.

First, create the partitions :
------------------------------

We will work on a single disk, detected as ada0.

# gpart create -s gpt ada0
# gpart add -s 800K -t efi ada0
# gpart add -t freebsd-zfs ada0
# gpart show
=>        34  3907029101  ada0  GPT  (1.8T)
          34        1600     1  efi  (800K)
        1634  3907027501     2  freebsd-zfs  (1.8T)

We use two partitions : the first one will host the loader and the second one, 
the zpool.

Create the zpool, ZFS and mount the root FS :
---------------------------------------------

# zpool create -f -m none -o altroot=/mnt root ada0p2
# zfs create root/ROOT
# zfs create root/ROOT/default
# zfs set mountpoint=/ root/ROOT/default
# zpool set bootfs=root/ROOT/default root
# zfs mount -a
# mkdir /mnt/dev
# mount -t devfs none /mnt/dev

Install the system :
--------------------

Now it is time to install the system within /mnt.

[ not detailed here, use your favourite method ]

You can then unmount and export the zpool.

# umount /mnt/dev
# zpool export root

Prepare the EFI partition :
---------------------------

We copy the (patched) loader.efi (*not* boot1.efi, which did not work for me) 
to efi/boot/BOOTx64.efi and set currdev within loader.rc :

# newfs_msdos ada0p1
# mount -t msdosfs /dev/ada0p1 /mnt
# mkdir -p /mnt/efi/boot/
# cp loader-zfs.efi /mnt/efi/boot/BOOTx64.efi
# mkdir -p /mnt/boot
# cat > /mnt/boot/loader.rc << EOF
unload
set currdev=zfs:root/ROOT/default:
load boot/kernel/kernel
load boot/kernel/zfs.ko
autoboot
EOF
# (cd /mnt && find .)
.
./efi
./efi/boot
./efi/boot/BOOTx64.efi
./boot
./boot/loader.rc
# umount /mnt

Now, reboot and enjoy you new system :)

Pushing the limits :
--------------------

Using this method, it is even possible to get a system bootable from UEFI *or* 
legacy BIOS.

Just insert a freebsd-boot (64K) partition between the efi and freebsd-zfs 
ones and install the pmbr + gptzfsboot loaders :

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

Finally, modify the /boot/loader.conf file within the ZFS root filesystem 
(mounted on /mnt) :

# cat >> /mnt/boot/loader.conf << EOF
zfs_load="YES"
vfs.root.mountfrom="zfs:root/ROOT/default"
EOF

Now, you can reboot either from BIOS or UEFI, the system will handle both.

Given the following partition scheme :

1  efi  (800K)
2  freebsd-boot  (64K)
3  freebsd-zfs  (1.8T)

The boot process will use the following paths :

Boot from BIOS -> MBR (pmbr) -> 2 (gptboot) -> 3 (loader) -> 3 (kernel) -> zfs 
root mounted
Boot from UEFI -> 1 (BOOTx64.efi, a.k.a patched loader.efi) -> 3 (kernel) -> 
zfs root mounted

Eric, thanks for your great work, I hope your patch will be committed soon :)

Regards,

-- 
Ganaël LAPLANCHE <ganael.laplanche at corp.ovh.com>


More information about the freebsd-hackers mailing list