summaryrefslogtreecommitdiffstats
path: root/init
blob: dad01b309cbdcb939dd39a85b6dc28960b61f695 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh

set -x

export PATH="/bin"

# mounts
mount -t proc proc /proc
mount -t devtmpfs devtmp /dev
mount -t sysfs sys /sys
mount -o size=1G -t tmpfs tmpfs /tmp

# modules
for mod in mbcache fscrypto jbd2 ext4; do
    modprobe "${mod}"
done

for mod in spl znvpair zcommon zunicode zavl icp zfs; do
    modprobe "${mod}"
done

# populating useful additional /dev entries
mkdir -p /dev/disk/by-uuid
blkid | tr -d : | while read dev uuidvar rest; do
    eval "${uuidvar}"
    ln -s "${dev}" "/dev/disk/by-uuid/${UUID}"
done

# argument parsing
for var in $(cat /proc/cmdline | sed 's/[.]/_/g'); do
    eval $var
done
eval "${root}"
pool=${ZFS/\/*}

if [ "${zfs_force}" = y ]; then
    FORCE_FLAG=" -f"
else
    FORCE_FLAG=""
fi

# meat
cryptsetup open UUID="${rd_luks_uuid}" "${pool}"
zpool import -N ${FORCE_FLAG} "${pool}"
mount -t zfs -o zfsutil "${ZFS}" /src

cp "$(readlink -f /src/boot/vmlinuz)" /tmp/vmlinuz
cp "$(readlink -f /src/boot/initrd)" /tmp/initrd

umount /src
# prevent zpool import moaning
zpool export "${pool}"
cryptsetup close "${pool}"

kexec --reuse-cmdline -f --initrd /tmp/initrd /tmp/vmlinuz

exec sh