Dernière activité 2 days ago

Révision 0f4f043821f0552cc5b753904a883a17b02d5863

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