From 01e03e865e744fea8db1d808ff1fb3823511c0fb Mon Sep 17 00:00:00 2001 From: Zackptg5 <5107713+Zackptg5@users.noreply.github.com> Date: Mon, 6 Dec 2021 00:40:22 -0500 Subject: [PATCH] Fix swapfile Snapshots won't work on swapfile containing subvolume, best to move it to it's own --- 0-preinstall.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/0-preinstall.sh b/0-preinstall.sh index ddc03c9..7e9f162 100755 --- a/0-preinstall.sh +++ b/0-preinstall.sh @@ -177,16 +177,18 @@ echo -ne " " TOTALMEM=$(cat /proc/meminfo | grep -i 'memtotal' | grep -o '[[:digit:]]*') if [[ $TOTALMEM -lt 8000000 ]]; then - #Put swap into the actual system, not into RAM disk, otherwise there is no point in it, it'll cache RAM into RAM. So, /mnt/ everything. - mkdir /mnt/opt/swap #make a dir that we can apply NOCOW to to make it btrfs-friendly. - chattr +C /mnt/opt/swap #apply NOCOW, btrfs needs that. - dd if=/dev/zero of=/mnt/opt/swap/swapfile bs=1M count=2048 status=progress - chmod 600 /mnt/opt/swap/swapfile #set permissions. - chown root /mnt/opt/swap/swapfile - mkswap /mnt/opt/swap/swapfile - swapon /mnt/opt/swap/swapfile - #The line below is written to /mnt/ but doesn't contain /mnt/, since it's just / for the sysytem itself. - echo "/opt/swap/swapfile none swap sw 0 0" >> /mnt/etc/fstab #Add swap to fstab, so it KEEPS working after installation. + # Put swapfile into separate subvolume or else you wouldn't be able to make snapshots of root + btrfs subvolume create /mnt/swap + truncate -s 0 /mnt/swap/swapfile + chattr +C /mnt/swap/swapfile #apply NOCOW, btrfs needs that. + btrfs property set /mnt/swap/swapfile compression none + dd if=/dev/zero of=/mnt/swap/swapfile bs=1M count=4096 status=progress + chmod 600 /mnt/swap/swapfile #set permissions. + chown root /mnt/swap/swapfile + mkswap /mnt/swap/swapfile + swapon /mnt/swap/swapfile + echo "/swap/swapfile none swap sw 0 0" >> /mnt/etc/fstab #Add swap to fstab, so it KEEPS working after installation. + echo "vm.swappiness=10" >> /mnt/etc/sysctl.conf # Lower swappiness fi echo -ne " -------------------------------------------------------------------------