From a745d00acdd2363be215b52aceff9effacf4195c Mon Sep 17 00:00:00 2001 From: Neil Gerring Date: Wed, 11 Jan 2023 10:45:07 +0000 Subject: [PATCH] Ensure the encrypted swapfile is always created as it won't persist on a reboot Signed-off-by: Neil Gerring --- pkg/swap/swap.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/swap/swap.sh b/pkg/swap/swap.sh index 1bf9dc458..e860a78b1 100755 --- a/pkg/swap/swap.sh +++ b/pkg/swap/swap.sh @@ -114,7 +114,6 @@ done ## if a condition failed: ### Required? exit 1 ### Else? exit 0 - if [ "$ENCRYPT" == "true" ]; then SWAPDEV=/dev/mapper/swapfile else @@ -140,7 +139,11 @@ if [ ! -f $path ] || ! [ $(stat -c "%s" $path) == $(disksize_to_count 1 $size) ] cryptsetup open --type plain --key-file /dev/urandom --key-size=256 --cipher=aes-cbc-essiv:sha256 --offset=0 ${path} swapfile fi + /sbin/mkswap $SWAPDEV +elif [ "$ENCRYPT" == "true" ]; then + ## Ensure the encrypted swap is created as it won't persist on a reboot + cryptsetup open --type plain --key-file /dev/urandom --key-size=256 --cipher=aes-cbc-essiv:sha256 --offset=0 ${path} swapfile /sbin/mkswap $SWAPDEV fi -/sbin/swapon $SWAPDEV +/sbin/swapon $SWAPDEV \ No newline at end of file