add swapfile fix

This commit is contained in:
Zackptg5 2022-03-07 09:13:29 -05:00
parent 8fb6610ee9
commit dde8cffeb3
2 changed files with 49 additions and 18 deletions

View File

@ -69,12 +69,35 @@ echo -ne "
Creating Filesystems Creating Filesystems
------------------------------------------------------------------------- -------------------------------------------------------------------------
" "
createswapfile() {
$SWAPFILE || return 0
if [[ "${FS}" == "ext4" ]]; then
local path=/opt/swap
mkdir -p /mnt$path # 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.
chattr +C /mnt$path #apply NOCOW, btrfs needs that.
else
local path=/swap
truncate -s 0 /mnt$path/swapfile
chattr +C /mnt$path/swapfile #apply NOCOW, btrfs needs that.
btrfs property set /mnt$path/swapfile compression none
fi
dd if=/dev/zero of=/mnt$path/swapfile bs=1M count=4096 status=progress
chmod 600 /mnt$path/swapfile # set permissions.
chown root /mnt$path/swapfile
mkswap /mnt$path/swapfile
swapon /mnt$path/swapfile
# The line below is written to /mnt/ but doesn't contain /mnt/, since it's just / for the system itself.
echo "$path/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
}
createsubvolumes () { createsubvolumes () {
btrfs subvolume create /mnt/@ btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@var btrfs subvolume create /mnt/@var
btrfs subvolume create /mnt/@tmp btrfs subvolume create /mnt/@tmp
btrfs subvolume create /mnt/@.snapshots btrfs subvolume create /mnt/@.snapshots
$SWAPFILE && btrfs subvolume create /mnt/@swap
} }
mountallsubvol () { mountallsubvol () {
@ -82,6 +105,7 @@ mountallsubvol () {
mount -o ${MOUNT_OPTIONS},subvol=@tmp ${partition3} /mnt/tmp mount -o ${MOUNT_OPTIONS},subvol=@tmp ${partition3} /mnt/tmp
mount -o ${MOUNT_OPTIONS},subvol=@var ${partition3} /mnt/var mount -o ${MOUNT_OPTIONS},subvol=@var ${partition3} /mnt/var
mount -o ${MOUNT_OPTIONS},subvol=@.snapshots ${partition3} /mnt/.snapshots mount -o ${MOUNT_OPTIONS},subvol=@.snapshots ${partition3} /mnt/.snapshots
$SWAPFILE && mount -o ${MOUNT_OPTIONS},subvol=@swap,x-mount.mkdir ${partition3} /mnt/swap
} }
subvolumesetup () { subvolumesetup () {
@ -110,10 +134,12 @@ if [[ "${FS}" == "btrfs" ]]; then
mkfs.btrfs -L ROOT ${partition3} -f mkfs.btrfs -L ROOT ${partition3} -f
mount -t btrfs ${partition3} /mnt mount -t btrfs ${partition3} /mnt
subvolumesetup subvolumesetup
createswapfile
elif [[ "${FS}" == "ext4" ]]; then elif [[ "${FS}" == "ext4" ]]; then
mkfs.vfat -F32 -n "EFIBOOT" ${partition2} mkfs.vfat -F32 -n "EFIBOOT" ${partition2}
mkfs.ext4 -L ROOT ${partition3} mkfs.ext4 -L ROOT ${partition3}
mount -t ext4 ${partition3} /mnt mount -t ext4 ${partition3} /mnt
createswapfile
elif [[ "${FS}" == "luks" ]]; then elif [[ "${FS}" == "luks" ]]; then
mkfs.vfat -F32 -n "EFIBOOT" ${partition2} mkfs.vfat -F32 -n "EFIBOOT" ${partition2}
# enter luks password to cryptsetup and format root partition # enter luks password to cryptsetup and format root partition
@ -125,6 +151,7 @@ elif [[ "${FS}" == "luks" ]]; then
# create subvolumes for btrfs # create subvolumes for btrfs
mount -t btrfs ${partition3} /mnt mount -t btrfs ${partition3} /mnt
subvolumesetup subvolumesetup
createswapfile
# store uuid of encrypted partition for grub # store uuid of encrypted partition for grub
echo ENCRYPTED_PARTITION_UUID=$(blkid -s UUID -o value ${partition3}) >> $CONFIGS_DIR/setup.conf echo ENCRYPTED_PARTITION_UUID=$(blkid -s UUID -o value ${partition3}) >> $CONFIGS_DIR/setup.conf
fi fi
@ -166,24 +193,6 @@ else
pacstrap /mnt efibootmgr --noconfirm --needed pacstrap /mnt efibootmgr --noconfirm --needed
fi fi
echo -ne " echo -ne "
-------------------------------------------------------------------------
Checking for low memory systems <8G
-------------------------------------------------------------------------
"
TOTAL_MEM=$(cat /proc/meminfo | grep -i 'memtotal' | grep -o '[[:digit:]]*')
if [[ $TOTAL_MEM -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 -p /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 system itself.
echo "/opt/swap/swapfile none swap sw 0 0" >> /mnt/etc/fstab # Add swap to fstab, so it KEEPS working after installation.
fi
echo -ne "
------------------------------------------------------------------------- -------------------------------------------------------------------------
SYSTEM READY FOR 1-setup.sh SYSTEM READY FOR 1-setup.sh
------------------------------------------------------------------------- -------------------------------------------------------------------------

View File

@ -140,6 +140,25 @@ echo -ne "
------------------------------------------------------------------------ ------------------------------------------------------------------------
" "
} }
swapfile() {
local TOTAL_MEM=$(cat /proc/meminfo | grep -i 'memtotal' | grep -o '[[:digit:]]*')
if [[ $TOTAL_MEM -lt 8000000 ]]; then
set_option SWAPFILE true
else
echo -ne "Add swap?
"
options=("Yes" "No")
select_option $? 1 "${options[@]}"
case ${options[$?]} in
y|Y|yes|Yes|YES)
set_option SWAPFILE true;;
n|N|no|NO|No)
set_option SWAPFILE false;;
*) echo "Wrong option. Try again"; swapfile;;
esac
fi
}
filesystem () { filesystem () {
# This function will handle file systems. At this movement we are handling only # This function will handle file systems. At this movement we are handling only
# btrfs and ext4. Others will be added in future. # btrfs and ext4. Others will be added in future.
@ -323,6 +342,9 @@ logo
diskpart diskpart
clear clear
logo logo
swapfile
clear
logo
filesystem filesystem
clear clear
logo logo