From cb667c5fef418c42ccecd0c9f55dec7f54635a01 Mon Sep 17 00:00:00 2001 From: "pico.dev" Date: Fri, 19 Jun 2020 19:55:44 +0200 Subject: Refactor the swapfile creation based on the wiki commands --- README.md | 3 +-- alis.conf | 5 ++++- alis.sh | 24 ++++++++++++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a294805..2a110f1 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ For new features, improvements and bugs fill an issue in GitHub or make a pull r * Encryption: root partition encrypted and no encrypted * Partition: no LVM, LVM, LVM on LUKS, GPT on UEFI, MBR on BIOS * File system: ext4, btrfs (with subvols), xfs -* Optional file swap (not supported in btrfs) * Storage: SATA, NVMe and MMC * Kernels: linux-lts, linux-hardened, linux-zen * Desktop environment: GNOME, KDE, XFCE, Mate, Cinnamon, LXDE @@ -41,7 +40,7 @@ For new features, improvements and bugs fill an issue in GitHub or make a pull r * WPA WIFI network installation * Periodic TRIM for SSD storage * Intel and AMD processors microcode -* Optional file swap (not supported in btrfs) +* Optional swap file * VirtualBox guest utils * Kernel compression and custom parameters * Users creation and add to sudoers diff --git a/alis.conf b/alis.conf index 2829057..256127e 100644 --- a/alis.conf +++ b/alis.conf @@ -2,6 +2,9 @@ # # Some values are preceded by a ! character, this means that the value is ignored. # Some keys accept a single value others accept multiple values as annotated in the comments. +# +# Read the Arch Linux wiki pages to learn more about the variables values. +# https://github.com/picodotdev/alis/blob/master/README.md # init KEYS="es" @@ -14,7 +17,7 @@ LVM="true" # true if use LVM for partitioning LUKS_PASSWORD="archlinux" # LUKS encryption key, if LVM will be user LVM on LUKS. Empty for not use LUKS/encryption. Warning: change it! LUKS_PASSWORD_RETYPE="archlinux" FILE_SYSTEM_TYPE="ext4 !btrfs !xfs" # (single) -SWAP_SIZE="!2GiB !4GiB !8GiB" # (single) +SWAP_SIZE="!2048 !4096 !8192" # (single, in megabytes) PARTITION_MODE="auto !custom !manual" PARTITION_CUSTOM_PARTED_UEFI="mklabel gpt mkpart primary fat32 1MiB 512MiB mkpart primary $FILE_SYSTEM_TYPE 512MiB 100% set 1 boot" PARTITION_CUSTOM_PARTED_BIOS="mklabel msdos mkpart primary ext4 4MiB 512MiB mkpart primary $FILE_SYSTEM_TYPE 512MiB 100% set 1 boot on" diff --git a/alis.sh b/alis.sh index ede1712..6b4f3d6 100644 --- a/alis.sh +++ b/alis.sh @@ -51,7 +51,7 @@ DEVICE_LVM="" LUKS_DEVICE_NAME="cryptroot" LVM_VOLUME_GROUP="vg" LVM_VOLUME_LOGICAL="root" -SWAPFILE="" +SWAPFILE="/swapfile" BOOT_DIRECTORY="" ESP_DIRECTORY="" #PARTITION_BOOT_NUMBER=0 @@ -520,13 +520,17 @@ function partition() { fi # swap - # btrfs: https://btrfs.wiki.kernel.org/index.php/FAQ#Does_btrfs_support_swap_files.3F - # btrfs: https://wiki.archlinux.org/index.php/Btrfs#Disabling_CoW - # btrfs: https://jlk.fjfi.cvut.cz/arch/manpages/man/btrfs.5#MOUNT_OPTIONS - if [ -n "$SWAP_SIZE" -a "$FILE_SYSTEM_TYPE" != "btrfs" ]; then - fallocate -l $SWAP_SIZE "/mnt/swapfile" - chmod 600 "/mnt/swapfile" - mkswap "/mnt/swapfile" + if [ -n "$SWAP_SIZE" ]; then + if [ "$FILE_SYSTEM_TYPE" == "btrfs" ]; then + truncate -s 0 /mnt$SWAPFILE + chattr +C /mnt$SWAPFILE + btrfs property set /mnt$SWAPFILE compression none + fi + + dd if=/dev/zero of=/mnt$SWAPFILE bs=1M count=$SWAP_SIZE status=progress + chmod 600 /mnt$SWAPFILE + mkswap /mnt$SWAPFILE + swapon /mnt$SWAPFILE fi # set variables @@ -567,9 +571,9 @@ function configuration() { genfstab -U /mnt >> /mnt/etc/fstab - if [ -n "$SWAP_SIZE" -a "$FILE_SYSTEM_TYPE" != "btrfs" ]; then + if [ -n "$SWAP_SIZE" ]; then echo "# swap" >> /mnt/etc/fstab - echo "/swapfile none swap defaults 0 0" >> /mnt/etc/fstab + echo "$SWAPFILE none swap defaults 0 0" >> /mnt/etc/fstab echo "" >> /mnt/etc/fstab fi -- cgit v1.2.3