diff options
4 files changed, 107 insertions, 12 deletions
diff --git a/raveos-calamares-theme/PKGBUILD b/raveos-calamares-theme/PKGBUILD index 63276af..0500c0b 100644 --- a/raveos-calamares-theme/PKGBUILD +++ b/raveos-calamares-theme/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: AlexC <alexc@alexc.hu> pkgname=raveos-calamares-theme pkgver=2.0.0 -pkgrel=43 +pkgrel=44 pkgdesc="RaveOS Calamares Theme" arch=('any') url="https://git.rp1.hu/RaveOS" diff --git a/raveos-calamares-theme/etc/calamares/modules/calamares-normalize-subvolumes.sh b/raveos-calamares-theme/etc/calamares/modules/calamares-normalize-subvolumes.sh new file mode 100644 index 0000000..83b42c4 --- /dev/null +++ b/raveos-calamares-theme/etc/calamares/modules/calamares-normalize-subvolumes.sh @@ -0,0 +1,88 @@ +#!/bin/bash +set -e + +echo ">>> [subvol-normalize] Running INSIDE target system" + +ROOT_DEV="$(findmnt -no SOURCE / | sed 's/\[.*\]//')" +ROOT_FS="$(findmnt -no FSTYPE /)" + +if [ "$ROOT_FS" != "btrfs" ]; then + echo ">>> [subvol-normalize] Root is not btrfs (${ROOT_FS}), skipping." + exit 0 +fi + +# Calamares' partition module ignores our btrfsSubvolumes config entirely +# and always creates its own hardcoded set: @, @home, @root, @srv, @cache, +# @log, @tmp. We only want @, @home, @log, @pkg (just /var/cache/pacman/pkg, +# not all of /var/cache) and @snapshots (created separately). Drop the rest +# here, after everything else has already run, merging any content back +# into the parent (@) subvolume first. + +mkdir -p /mnt/topvol +mount -o subvolid=5 "${ROOT_DEV}" /mnt/topvol + +unmount_retry() { + local path="$1" + local i + for i in 1 2 3 4 5; do + if umount "$path" 2>/dev/null; then + return 0 + fi + fuser -km "$path" >/dev/null 2>&1 || true + sleep 1 + done + umount -l "$path" 2>/dev/null || true +} + +for entry in "root:@root" "srv:@srv" "var/tmp:@tmp"; do + path="/${entry%%:*}" + subvol="${entry##*:}" + if findmnt -no SOURCE "$path" >/dev/null 2>&1; then + echo ">>> [subvol-normalize] Removing separate subvolume ${subvol} (${path})" + unmount_retry "$path" + # $path is now a plain empty dir in @ again -- copy the old + # subvolume's content back into it before deleting the subvolume. + if [ -d "/mnt/topvol/${subvol}" ] && ! findmnt -no SOURCE "$path" >/dev/null 2>&1; then + cp -a "/mnt/topvol/${subvol}/." "$path/" 2>/dev/null || true + btrfs subvolume delete "/mnt/topvol/${subvol}" || true + fi + fi + sed -i "\#[[:space:]]${path}[[:space:]]#d" /etc/fstab +done + +# Narrow /var/cache: drop the whole-@cache subvolume (keep it as a plain +# directory), and create a dedicated @pkg subvolume just for pacman's +# package cache -- that's the only part of /var/cache archinstall separates. +if findmnt -no SOURCE /var/cache >/dev/null 2>&1; then + echo ">>> [subvol-normalize] Narrowing /var/cache -> only pacman/pkg as @pkg" + unmount_retry /var/cache + if [ -d /mnt/topvol/@cache ] && ! findmnt -no SOURCE /var/cache >/dev/null 2>&1; then + cp -a /mnt/topvol/@cache/. /var/cache/ 2>/dev/null || true + btrfs subvolume delete /mnt/topvol/@cache || true + fi +fi +sed -i "\#[[:space:]]/var/cache[[:space:]]#d" /etc/fstab + +if [ ! -d /mnt/topvol/@pkg ]; then + btrfs subvolume create /mnt/topvol/@pkg + echo ">>> [subvol-normalize] Created @pkg subvolume" +fi + +unmount_retry /mnt/topvol +rmdir /mnt/topvol 2>/dev/null || true + +mkdir -p /var/cache/pacman +rm -rf /var/cache/pacman/pkg +mkdir -p /var/cache/pacman/pkg + +ROOT_UUID="$(blkid -s UUID -o value "${ROOT_DEV}")" +MOUNT_OPTS="rw,noatime,compress=zstd:3,discard=async,space_cache=v2" +if ! grep -q '/var/cache/pacman/pkg' /etc/fstab; then + echo "UUID=${ROOT_UUID} /var/cache/pacman/pkg btrfs ${MOUNT_OPTS},subvol=/@pkg 0 0" >> /etc/fstab + echo ">>> [subvol-normalize] Added /var/cache/pacman/pkg to fstab" +fi + +mount /var/cache/pacman/pkg + +echo ">>> [subvol-normalize] Done. Final subvolume list:" +btrfs subvolume list / diff --git a/raveos-calamares-theme/etc/calamares/modules/partition.conf b/raveos-calamares-theme/etc/calamares/modules/partition.conf index f67a679..732a5df 100644 --- a/raveos-calamares-theme/etc/calamares/modules/partition.conf +++ b/raveos-calamares-theme/etc/calamares/modules/partition.conf @@ -169,16 +169,16 @@ availableFileSystemTypes: ["ext4","btrfs"] # This mirrors archinstall's default btrfs layout, see: # https://gitlab.archlinux.org/archlinux/archinstall/-/blob/master/archinstall/lib/disk/disk_menu.py btrfsSubvolumes: - - mountPoint: "/" - subvolume: "/@" - - mountPoint: "/home" - subvolume: "/@home" - - mountPoint: "/var/log" - subvolume: "/@log" - - mountPoint: "/var/cache/pacman/pkg" - subvolume: "/@pkg" - - mountPoint: "/.snapshots" - subvolume: "/@snapshots" + - mountPoint: / + subvolume: /@ + - mountPoint: /home + subvolume: /@home + - mountPoint: /var/log + subvolume: /@log + - mountPoint: /var/cache/pacman/pkg + subvolume: /@pkg + - mountPoint: /.snapshots + subvolume: /@snapshots # Show/hide LUKS related functionality in automated partitioning modes. # Disable this if you choose not to deploy early unlocking support in GRUB2 diff --git a/raveos-calamares-theme/etc/calamares/modules/shellprocess-loader.conf b/raveos-calamares-theme/etc/calamares/modules/shellprocess-loader.conf index 13b7dca..62fd87d 100644 --- a/raveos-calamares-theme/etc/calamares/modules/shellprocess-loader.conf +++ b/raveos-calamares-theme/etc/calamares/modules/shellprocess-loader.conf @@ -11,7 +11,14 @@ script: - command: "install -Dm755 /etc/calamares/modules/calamares-fix-bootentry.sh ${ROOT}/root/calamares-fix-bootentry.sh" - command: "arch-chroot ${ROOT} /bin/bash /root/calamares-fix-bootentry.sh" - command: "-rm ${ROOT}/root/calamares-fix-bootentry.sh" - # 3. Calamares' hardcoded btrfs subvolume layout has no .snapshots -- + # 3. Calamares' btrfsSubvolumes config is silently ignored -- it always + # creates its own hardcoded set (@, @home, @root, @srv, @cache, @log, + # @tmp). Drop the ones we don't want (@root, @srv, @tmp) and narrow + # @cache down to just /var/cache/pacman/pkg as @pkg. + - command: "install -Dm755 /etc/calamares/modules/calamares-normalize-subvolumes.sh ${ROOT}/root/calamares-normalize-subvolumes.sh" + - command: "arch-chroot ${ROOT} /bin/bash /root/calamares-normalize-subvolumes.sh" + - command: "-rm ${ROOT}/root/calamares-normalize-subvolumes.sh" + # 4. Calamares' hardcoded btrfs subvolume layout has no .snapshots -- # create it by hand (needed by grub-btrfs/Snapper). - command: "install -Dm755 /etc/calamares/modules/calamares-create-snapshots-subvol.sh ${ROOT}/root/calamares-create-snapshots-subvol.sh" - command: "arch-chroot ${ROOT} /bin/bash /root/calamares-create-snapshots-subvol.sh" |