home · contact · privacy
Add swapping! master
authorPlom Heller <plom@plomlompom.com>
Mon, 31 Aug 2026 21:58:32 +0000 (23:58 +0200)
committerPlom Heller <plom@plomlompom.com>
Mon, 31 Aug 2026 21:58:32 +0000 (23:58 +0200)
_lib.sh
install_debian.sh
make_luksvg.sh

diff --git a/_lib.sh b/_lib.sh
index 94e5288b1b53b9c0f1980fb3ff95659e8e8b86e8..2e24cc7a76d77e7a3cde1245e4a792a78ead927b 100644 (file)
--- a/_lib.sh
+++ b/_lib.sh
@@ -8,6 +8,7 @@ TO_RBIND="${NAME_DEV} proc sys"
 
 # constants we might want to change at some point
 NAME_DATA=data
+NAME_SWAP=swap
 PATH_MNT=/mnt/debinst
 
 # path constructors
@@ -139,6 +140,13 @@ unmount_unrbind() {
 chroot_sh() {
     LANG=C.UTF-8 chroot "${PATH_MNT}" /bin/sh -c "$@"
 }
+create_lv() {
+    local VG=$1
+    local LV=$2
+    local SIZE=$3
+    msg 'Creating logical volume "%s" inside volume group …' "${LV}"
+    lvcreate -L "${SIZE}" -n "${LV}" "${VG}"
+}
 usage() {
     local COUNT_INPUTS=$1
     shift
index ba73daee7b6996ac9d83b251be1c4c95f191f2a1..c212aefcb091408de348d455a1011a9febb849fa 100755 (executable)
@@ -32,6 +32,7 @@ PATH_MNT_NM_CONNECTIONS="${PATH_MNT}${PATH_NM_CONNECTIONS}"
 PATH_VG=$(path_vg "${NAME_LUKSVG}")
 PATH_VG_DATA=${PATH_VG}/${NAME_DATA}
 PATH_VG_ROOT=${PATH_VG}/${NAME_ROOT}
+PATH_VG_SWAP=${PATH_VG}/${NAME_SWAP}
 
 # sanity checks
 check_tools cryptsetup debootstrap efibootmgr lvcreate mkfs.ext4 vgs
@@ -54,8 +55,7 @@ msg '- name for new boot option: [ %s ]' "${NAME_BOOT}"
 
 # set up logival volume and filesystem
 open_luksvg "${PARTITION}" "${NAME_LUKSVG}"
-msg 'Creating logical volume "%s" there …' "${NAME_ROOT}"
-lvcreate -L '10G' -n "${NAME_ROOT}" "${NAME_LUKSVG}"
+create_lv "${NAME_LUKSVG}" "${NAME_ROOT}" 10G
 await_path "${PATH_VG_ROOT}"
 msg 'Creating EXT4 filesystem …'
 mkfs.ext4 -q "${PATH_VG_ROOT}"
@@ -68,10 +68,11 @@ rbind_mnt
 
 # set up minimal fstab
 msg 'Writing fstab …'
-printf '%s / ext4 errors=remount-ro 0 1\n' "${PATH_VG_ROOT}"\
-        >| "${PATH_MNT_FSTAB}"
-printf '%s /data ext4 errors=remount-ro 0 2\n' "${PATH_VG_DATA}"\
-        >> "${PATH_MNT_FSTAB}"
+cat <<EOF >| "${PATH_MNT_FSTAB}"
+${PATH_VG_ROOT} / ext4 errors=remount-ro 0 1
+${PATH_VG_DATA} /${NAME_DATA} ext4 errors=remount-ro 0 2
+${PATH_VG_SWAP} none swap sw 0 0
+EOF
 
 # set up crypttab
 msg 'Writing crypttab …'
index 674e0b937506f728e0be2297b038d298acc34a56..8db13dc31e8fd09884d27ad9ffab84241896281a 100755 (executable)
@@ -8,10 +8,12 @@ NAME_LUKSVG=$2
 
 # constants derived from changeables
 PATH_LUKS_MAPPER=$(path_luks_mapper "${NAME_LUKSVG}")
-PATH_VG_DATA=$(path_vg "${NAME_LUKSVG}")/${NAME_DATA}
+PATH_VG=$(path_vg "${NAME_LUKSVG}")
+PATH_VG_DATA=${PATH_VG}/${NAME_DATA}
+PATH_VG_SWAP=${PATH_VG}/${NAME_SWAP}
 
 # sanity checks
-check_tools cryptsetup lvcreate mkfs.ext4 pvcreate vgcreate vgs
+check_tools cryptsetup lvcreate mkfs.ext4 mkswap pvcreate vgcreate vgs
 check_input_partition_mountable "${PARTITION}"
 check_input_new_luksvg "${NAME_LUKSVG}"
 try_quiet cryptsetup isLuks "${PARTITION}"\
@@ -30,12 +32,13 @@ msg 'Formatting %s as LUKS container …' "${PARTITION}"
 cryptsetup luksFormat --batch-mode "${PARTITION}"
 open_luksvg "${PARTITION}" "${NAME_LUKSVG}"
 
-# set up LVM and filesystem
+# set up LVM and filesystems
 msg 'Creating volume group "%s" inside LUKS container …' "${NAME_LUKSVG}"
 vgcreate "${NAME_LUKSVG}" "${PATH_LUKS_MAPPER}"
-
-msg 'Creating logical volume "%s" inside volume group …' "${NAME_DATA}"
-lvcreate -L '256G' -n "${NAME_DATA}" "${NAME_LUKSVG}"
+create_lv "${NAME_LUKSVG}" "${NAME_SWAP}" 64G
+msg 'Configuring as swap area …'
+mkswap "${PATH_VG_SWAP}"
+create_lv "${NAME_LUKSVG}" "${NAME_DATA}" 256G
 msg 'Creating EXT4 filesystem …'
 mkfs.ext4 -q "${PATH_VG_DATA}"