From edad1469ace201e53f05ceeae2b779ac12c33990 Mon Sep 17 00:00:00 2001 From: Rasmus Thomsen Date: Sun, 6 Oct 2019 23:30:11 +0200 Subject: init: add support for force importing ZFS pool and ZFS native encryption --- initramfs-init.in | 22 ++++++++++++++++++++++ mkinitfs-bootparam.7.in | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/initramfs-init.in b/initramfs-init.in index 4f96b7c..496d93b 100755 --- a/initramfs-init.in +++ b/initramfs-init.in @@ -279,6 +279,25 @@ is_url() { esac } +# Do some tasks to make sure mounting the ZFS pool is A-OK +prepare_zfs_root() { + local _root_vol=${KOPT_root#ZFS=} + local _root_pool=${_rool_vol%%/*} + + # Force import if this has been imported on a different system previously + if [ "$KOPT_zfs_force" = 1 ]; then + zpool import -N -f $_root_vol + fi + + # Ask for encryption password + if [ $(zpool list -H -o feature@encryption $_root_pool) = "active" ]; then + local _encryption_root=$(zfs get -H -o value encryptionroot $_root_vol) + if [ "$_encryption_root" != "-" ]; then + eval zfs load-key $_encryption_root + fi + fi +} + /bin/busybox mkdir -p /usr/bin /usr/sbin /proc /sys /dev $sysroot \ /media/cdrom /media/usb /tmp /run @@ -484,6 +503,9 @@ if [ -n "$KOPT_root" ]; then mkdir -p /media/root-rw/work /media/root-rw/root mount -t overlay -o lowerdir=/media/root-ro,upperdir=/media/root-rw/root,workdir=/media/root-rw/work overlayfs $sysroot else + if [ $rootfstype = "zfs" ]; then + prepare_zfs_root + fi mount ${rootfstype:+-t} ${rootfstype} \ -o ${KOPT_rootflags:-ro} \ ${KOPT_root#ZFS=} $sysroot diff --git a/mkinitfs-bootparam.7.in b/mkinitfs-bootparam.7.in index d5a3aad..1589d0d 100644 --- a/mkinitfs-bootparam.7.in +++ b/mkinitfs-bootparam.7.in @@ -119,6 +119,10 @@ Enable splash screen \fBusbdelay=\fINUMBER\fR Wait \fINUMBER\fR seconds for USB devices to show up before searching for boot media. +.TP +\fBzfs_force=\fINUMBER\fR +Enable force importing the root zpool on boot, even if it was previously mounted +from a different system/OS. .SH FILES .TP \fI@datadir@/initramfs-init\fR -- cgit v1.2.3