Skip to content

Instantly share code, notes, and snippets.

@curiousercreative
Last active September 16, 2024 20:24
Show Gist options
  • Save curiousercreative/80b00df57d3fbe1107a524f4e59cf4b5 to your computer and use it in GitHub Desktop.
Save curiousercreative/80b00df57d3fbe1107a524f4e59cf4b5 to your computer and use it in GitHub Desktop.
Migrate Pop! install to ZFS
#! /usr/bin/env bash
# adapted from https://docs.zfsbootmenu.org/en/v2.3.x/guides/ubuntu/uefi.html
# script is not meant to be run non-interactively. read and understand before executing
sudo -i
source /etc/os-release
export ID
export POOL_DISK="/dev/sdg"
export POOL_PART="3"
export POOL_DEVICE="${POOL_DISK}${POOL_PART}"
echo 'passphrase' > /etc/zfs/zroot.key
chmod 000 /etc/zfs/zroot.key
zpool create -f -o ashift=12 \
-O compression=zstd \
-O acltype=posixacl \
-O xattr=sa \
-O relatime=on \
-O encryption=aes-256-gcm \
-O keylocation=file:///etc/zfs/zroot.key \
-O keyformat=passphrase \
-o autotrim=on \
-o compatibility=openzfs-2.1-linux \
-m none zroot "$POOL_DEVICE"
zfs create -o mountpoint=none zroot/ROOT
zfs create -o mountpoint=/ -o canmount=noauto zroot/ROOT/${ID}
zfs create -o mountpoint=/home zroot/home
zpool set bootfs=zroot/ROOT/${ID} zroot
zpool export zroot
zpool import -N -R /mnt zroot
zfs load-key -L prompt zroot
zfs mount zroot/ROOT/${ID}
zfs mount zroot/home
udevadm trigger
rsync -avAHXx --numeric-ids --exclude='/home' --exclude='/timeshift' /media/curiouser/5b30118c-3837-4895-9c60-70ea27dd36d9/ mnt/
rsync -av --numeric-ids /media/curiouser/5b30118c-3837-4895-9c60-70ea27dd36d9/home/ mnt/home/
mount -t proc proc mnt/proc
mount -t sysfs sys mnt/sys
mount -B /dev mnt/dev
mount -t devpts pts mnt/dev/pts
chroot mnt /bin/bash
source /etc/os-release
export ID
apt update
apt install zfs-initramfs zfsutils-linux
systemctl enable zfs.target
systemctl enable zfs-import-cache
systemctl enable zfs-mount
systemctl enable zfs-import.target
echo "UMASK=0077" > /etc/initramfs-tools/conf.d/umask.conf
update-initramfs -c -k all
zfs set org.zfsbootmenu:commandline="systemd.show_status=false splash loglevel=0 quiet resume=UUID=9a4e4168-0964-4895-8d40-0e1ee0bf5d9a" zroot/ROOT
zfs set org.zfsbootmenu:keysource="zroot/ROOT/${ID}" zroot
exit
umount -n -R /mnt
zpool export zroot
sudo -i
apt remove kernelstub
apt-mark hold efibootmgr \
grub-common grub-common:i386 \
grub-efi-amd64-signed grub-efi-amd64:i386 grub-efi-amd64-bin grub-efi-ia32 grub-efi-amd64 grub-efi-amd64-bin:i386 \
grub-pc grub2-common kernelstub lilo
# next time you have a kernel update, you'll likely have to upgrade with flags since we've held back dependencies
sudo apt upgrade --with-new-pkgs linux-generic
# assumes your ESP is mounted at /boot/efi
# copy zbm boot files
wget -qO- https://get.zfsboot.menu/components/release | tar xvz -C /boot/efi/EFI
# ignore ownership errors
mv /boot/efi/EFI/zfsbootmenu-release-x86_64-v* /boot/efi/EFI/zbm
# add entries
cat << EOF > /boot/efi/loader/entries/pop.conf
title Pop!_OS
linux /EFI/zbm/vmlinuz-bootmenu
initrd /EFI/zbm/initramfs-bootmenu.img
options zbm.skip systemd.show_status=false splash loglevel=0 quiet
EOF
cat << EOF > /boot/efi/loader/entries/zbm.conf
title ZFSBootMenu
linux /EFI/zbm/vmlinuz-bootmenu
initrd /EFI/zbm/initramfs-bootmenu.img
options zbm.show
EOF
echo 'default pop' > /boot/efi/loader/loader.conf
# removing kernelstub entries and boot files
rm /boot/efi/loader/entries/Pop-*
rm -r /boot/efi/EFI/Pop*
# reboot into system
systemctl reboot
#! /usr/bin/env bash
# adapted from https://docs.zfsbootmenu.org/en/v2.3.x/guides/ubuntu/uefi.html
# script is not meant to be run non-interactively. read and understand before executing
sudo -i
source /etc/os-release
export ID
export POOL_DEVICE="/dev/nvme1n1p3"
zpool create -f -o ashift=12 \
-O compression=zstd \
-O acltype=posixacl \
-O xattr=sa \
-O relatime=on \
-o autotrim=on \
-o compatibility=openzfs-2.1-linux \
-m none zroot "$POOL_DEVICE"
zfs create -o mountpoint=none zroot/ROOT
zfs create -o mountpoint=/ -o canmount=noauto zroot/ROOT/${ID}
zfs create -o mountpoint=/home zroot/home
zpool set bootfs=zroot/ROOT/${ID} zroot
zpool export zroot
zpool import -N -R /mnt/shredder-zfs zroot
zfs mount zroot/ROOT/${ID}
zfs mount zroot/home
udevadm trigger
rsync -avAHXx --numeric-ids --exclude='/home' --exclude='/timeshift' /mnt/shredder/ /mnt/shredder-zfs/
rsync -av --numeric-ids /mnt/shredder/home/ /mnt/shredder-zfs/home/
umount /mnt/shredder
mount -t proc /proc /mnt/shredder-zfs/proc
mount -t sysfs /sys /mnt/shredder-zfs/sys
mount -B /dev /mnt/shredder-zfs/dev
mount -t devpts pts /mnt/shredder-zfs/dev/pts
mount /dev/nvme1n1p1 /mnt/shredder-zfs/boot/efi
chroot /mnt/shredder-zfs /bin/bash
### now in zroot
source /etc/os-release
export ID
apt update
apt remove kernelstub
apt-mark hold efibootmgr \
grub-common grub-common:i386 \
grub-efi-amd64-signed grub-efi-amd64:i386 grub-efi-amd64-bin grub-efi-ia32 grub-efi-amd64 grub-efi-amd64-bin:i386 \
grub-pc grub2-common kernelstub lilo
apt install zfs-initramfs zfsutils-linux zfs-dkms
# next time you have a kernel update, you'll likely have to upgrade with flags since we've held back dependencies
sudo apt upgrade --with-new-pkgs linux-generic
systemctl enable zfs.target
systemctl enable zfs-import-cache
systemctl enable zfs-mount
systemctl enable zfs-import.target
echo "UMASK=0077" > /etc/initramfs-tools/conf.d/umask.conf
update-initramfs -c -k all
zfs set org.zfsbootmenu:commandline="systemd.show_status=false splash loglevel=0 quiet" zroot/ROOT
# assumes your ESP is mounted at /boot/efi
# removing kernelstub entries and boot files
rm /boot/efi/loader/entries/Pop*
rm -r /boot/efi/EFI/Pop*
# copy zbm boot files
wget -qO- https://get.zfsboot.menu/components/release | tar xvz -C /boot/efi/EFI
# ignore ownership errors
mv /boot/efi/EFI/zfsbootmenu-release-x86_64-v* /boot/efi/EFI/zbm
# add entries
cat << EOF > /boot/efi/loader/entries/pop.conf
title Pop!_OS
linux /EFI/zbm/vmlinuz-bootmenu
initrd /EFI/zbm/initramfs-bootmenu.img
options zbm.skip systemd.show_status=false splash loglevel=0 quiet
EOF
cat << EOF > /boot/efi/loader/entries/zbm.conf
title ZFSBootMenu
linux /EFI/zbm/vmlinuz-bootmenu
initrd /EFI/zbm/initramfs-bootmenu.img
options zbm.show
EOF
echo 'default pop' > /boot/efi/loader/loader.conf
exit
### out of zroot
umount -n -R /mnt/shredder-zfs
zpool export zroot
# reboot into system
systemctl reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment