diff --git a/scripts/0-preinstall.sh b/scripts/0-preinstall.sh index b289307..067c6f2 100755 --- a/scripts/0-preinstall.sh +++ b/scripts/0-preinstall.sh @@ -69,12 +69,35 @@ echo -ne " 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 () { btrfs subvolume create /mnt/@ btrfs subvolume create /mnt/@home btrfs subvolume create /mnt/@var btrfs subvolume create /mnt/@tmp btrfs subvolume create /mnt/@.snapshots + $SWAPFILE && btrfs subvolume create /mnt/@swap } mountallsubvol () { @@ -82,6 +105,7 @@ mountallsubvol () { mount -o ${MOUNT_OPTIONS},subvol=@tmp ${partition3} /mnt/tmp mount -o ${MOUNT_OPTIONS},subvol=@var ${partition3} /mnt/var mount -o ${MOUNT_OPTIONS},subvol=@.snapshots ${partition3} /mnt/.snapshots + $SWAPFILE && mount -o ${MOUNT_OPTIONS},subvol=@swap,x-mount.mkdir ${partition3} /mnt/swap } subvolumesetup () { @@ -110,10 +134,12 @@ if [[ "${FS}" == "btrfs" ]]; then mkfs.btrfs -L ROOT ${partition3} -f mount -t btrfs ${partition3} /mnt subvolumesetup + createswapfile elif [[ "${FS}" == "ext4" ]]; then mkfs.vfat -F32 -n "EFIBOOT" ${partition2} mkfs.ext4 -L ROOT ${partition3} mount -t ext4 ${partition3} /mnt + createswapfile elif [[ "${FS}" == "luks" ]]; then mkfs.vfat -F32 -n "EFIBOOT" ${partition2} # enter luks password to cryptsetup and format root partition @@ -125,6 +151,7 @@ elif [[ "${FS}" == "luks" ]]; then # create subvolumes for btrfs mount -t btrfs ${partition3} /mnt subvolumesetup + createswapfile # store uuid of encrypted partition for grub echo ENCRYPTED_PARTITION_UUID=$(blkid -s UUID -o value ${partition3}) >> $CONFIGS_DIR/setup.conf fi @@ -166,24 +193,6 @@ else pacstrap /mnt efibootmgr --noconfirm --needed fi 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 ------------------------------------------------------------------------- diff --git a/scripts/startup.sh b/scripts/startup.sh index baf0e75..56b1f17 100755 --- a/scripts/startup.sh +++ b/scripts/startup.sh @@ -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 () { # This function will handle file systems. At this movement we are handling only # btrfs and ext4. Others will be added in future. @@ -323,6 +342,9 @@ logo diskpart clear logo +swapfile +clear +logo filesystem clear logo