Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Aug 2015 11:39:40 +0200
From:      Ganael Laplanche <ganael.laplanche@corp.ovh.com>
To:        <freebsd-hackers@freebsd.org>
Cc:        Eric McCorkle <eric@metricspace.net>
Subject:   EFI ZFS loader success story
Message-ID:  <201508121139.40852.ganael.laplanche@corp.ovh.com>

next in thread | raw e-mail | index | archive | help
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!

=46or those interested, here are the steps needed to get a working system. =
This=20
should be done on a live system to be able to operate freely on the hard di=
sk.

=46irst, create the partitions :
=2D-----------------------------

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
=3D>        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 o=
ne,=20
the zpool.

Create the zpool, ZFS and mount the root FS :
=2D--------------------------------------------

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

Install the system :
=2D-------------------

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 :
=2D--------------------------

We copy the (patched) loader.efi (*not* boot1.efi, which did not work for m=
e)=20
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=3Dzfs:root/ROOT/default:
load boot/kernel/kernel
load boot/kernel/zfs.ko
autoboot
EOF
# (cd /mnt && find .)
=2E
=2E/efi
=2E/efi/boot
=2E/efi/boot/BOOTx64.efi
=2E/boot
=2E/boot/loader.rc
# umount /mnt

Now, reboot and enjoy you new system :)

Pushing the limits :
=2D-------------------

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

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

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

=46inally, modify the /boot/loader.conf file within the ZFS root filesystem=
=20
(mounted on /mnt) :

# cat >> /mnt/boot/loader.conf << EOF
zfs_load=3D"YES"
vfs.root.mountfrom=3D"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=20
root mounted
Boot from UEFI -> 1 (BOOTx64.efi, a.k.a patched loader.efi) -> 3 (kernel) -=
>=20
zfs root mounted

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

Regards,

=2D-=20
Gana=EBl LAPLANCHE <ganael.laplanche@corp.ovh.com>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508121139.40852.ganael.laplanche>