Fix swapfile

Snapshots won't work on swapfile containing subvolume, best to move it to it's own
This commit is contained in:
Zackptg5 2021-12-06 00:40:22 -05:00
parent afbacbe3c2
commit 01e03e865e
1 changed files with 12 additions and 10 deletions

View File

@ -177,16 +177,18 @@ echo -ne "
" "
TOTALMEM=$(cat /proc/meminfo | grep -i 'memtotal' | grep -o '[[:digit:]]*') TOTALMEM=$(cat /proc/meminfo | grep -i 'memtotal' | grep -o '[[:digit:]]*')
if [[ $TOTALMEM -lt 8000000 ]]; then 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. # Put swapfile into separate subvolume or else you wouldn't be able to make snapshots of root
mkdir /mnt/opt/swap #make a dir that we can apply NOCOW to to make it btrfs-friendly. btrfs subvolume create /mnt/swap
chattr +C /mnt/opt/swap #apply NOCOW, btrfs needs that. truncate -s 0 /mnt/swap/swapfile
dd if=/dev/zero of=/mnt/opt/swap/swapfile bs=1M count=2048 status=progress chattr +C /mnt/swap/swapfile #apply NOCOW, btrfs needs that.
chmod 600 /mnt/opt/swap/swapfile #set permissions. btrfs property set /mnt/swap/swapfile compression none
chown root /mnt/opt/swap/swapfile dd if=/dev/zero of=/mnt/swap/swapfile bs=1M count=4096 status=progress
mkswap /mnt/opt/swap/swapfile chmod 600 /mnt/swap/swapfile #set permissions.
swapon /mnt/opt/swap/swapfile chown root /mnt/swap/swapfile
#The line below is written to /mnt/ but doesn't contain /mnt/, since it's just / for the sysytem itself. mkswap /mnt/swap/swapfile
echo "/opt/swap/swapfile none swap sw 0 0" >> /mnt/etc/fstab #Add swap to fstab, so it KEEPS working after installation. 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 fi
echo -ne " echo -ne "
------------------------------------------------------------------------- -------------------------------------------------------------------------