Last active 2 days ago

Revision b9bcafe831152f5d6cbfed2badb2c97e80d09612

main.sh Raw
1#! /usr/bin/env bash
2# adapted from https://docs.zfsbootmenu.org/en/v2.3.x/guides/ubuntu/uefi.html
3
4sudo -i
5
6source /etc/os-release
7export ID
8
9export POOL_DISK="/dev/sdg"
10export POOL_PART="3"
11export POOL_DEVICE="${POOL_DISK}${POOL_PART}"
12
13echo 'passphrase' > /etc/zfs/zroot.key
14chmod 000 /etc/zfs/zroot.key
15
16zpool create -f -o ashift=12 \
17 -O compression=zstd \
18 -O acltype=posixacl \
19 -O xattr=sa \
20 -O relatime=on \
21 -O encryption=aes-256-gcm \
22 -O keylocation=file:///etc/zfs/zroot.key \
23 -O keyformat=passphrase \
24 -o autotrim=on \
25 -o compatibility=openzfs-2.1-linux \
26 -m none zroot "$POOL_DEVICE"
27
28zfs create -o mountpoint=none zroot/ROOT
29zfs create -o mountpoint=/ -o canmount=noauto zroot/ROOT/${ID}
30zfs create -o mountpoint=/home zroot/home
31
32zpool set bootfs=zroot/ROOT/${ID} zroot
33
34zpool export zroot
35zpool import -N -R /mnt zroot
36zfs load-key -L prompt zroot
37
38zfs mount zroot/ROOT/${ID}
39zfs mount zroot/home
40
41udevadm trigger
42
43rsync -avAHXx --numeric-ids --exclude='/home' --exclude='/timeshift' /media/curiouser/5b30118c-3837-4895-9c60-70ea27dd36d9/ mnt/
44rsync -av --numeric-ids /media/curiouser/5b30118c-3837-4895-9c60-70ea27dd36d9/home/ mnt/home/
45
46mount -t proc proc mnt/proc
47mount -t sysfs sys mnt/sys
48mount -B /dev mnt/dev
49mount -t devpts pts mnt/dev/pts
50chroot mnt /bin/bash
51
52source /etc/os-release
53export ID
54
55apt update
56apt install zfs-initramfs zfsutils-linux
57
58systemctl enable zfs.target
59systemctl enable zfs-import-cache
60systemctl enable zfs-mount
61systemctl enable zfs-import.target
62
63echo "UMASK=0077" > /etc/initramfs-tools/conf.d/umask.conf
64
65update-initramfs -c -k all
66
67zfs set org.zfsbootmenu:commandline="systemd.show_status=false splash loglevel=0 quiet resume=UUID=9a4e4168-0964-4895-8d40-0e1ee0bf5d9a" zroot/ROOT
68zfs set org.zfsbootmenu:keysource="zroot/ROOT/${ID}" zroot
69
70exit
71
72umount -n -R /mnt
73zpool export zroot
74
75sudo -i
76apt remove kernelstub
77cat <<EOF > /etc/apt/preferences.d/blacklist-kernelstub
78Package: kernelstub
79Pin: release *
80Pin-Priority: -1
81EOF
82
83# assumes your ESP is mounted at /boot/efi
84
85sudo -i
86
87# copy zbm boot files
88wget -qO- https://get.zfsboot.menu/components/release | tar xvz -C /boot/efi/EFI
89# ignore ownership errors
90mv /boot/efi/EFI/zfsbootmenu-release-x86_64-v* /boot/efi/EFI/zbm
91
92# add entries
93cat <EOF > /boot/efi/loader/entries/pop.conf
94title Pop!_OS
95linux /EFI/zbm/vmlinuz-bootmenu
96initrd /EFI/zbm/initramfs-bootmenu.img
97options zbm.skip systemd.show_status=false splash loglevel=0 quiet
98EOF
99
100cat <EOF > /boot/efi/loader/entries/zbm.conf
101title ZFSBootMenu
102linux /EFI/zbm/vmlinuz-bootmenu
103initrd /EFI/zbm/initramfs-bootmenu.img
104options zbm.show
105EOF
106
107echo 'default pop' > /boot/efi/loader/loader.conf
108
109# removing kernelstub entries and boot files
110rm /boot/efi/loader/entries/Pop-*
111rm -r /boot/efi/EFI/Pop*
112
113# reboot into system
114systemctl reboot