for swap in $swaps; do
info `gettext "Setting up swap:"` "[$swap]"
uuid=$(blkid -o value -s UUID $swap)
- for target in "UUID=$uuid" $swap; do
+ # /etc/fstab might use a symlink like /dev/mapper/ubuntu--vg-swap_1
+ links=$(for d in $(udevadm info --query=symlink -n $swap); do echo /dev/$d; done)
+ for target in "UUID=$uuid" $swap $links; do
if [ -n "$target" ] && grep -qs "^$target\s\+" /etc/fstab; then
sed -i "s:^$target\s\+:\#$target :" /etc/fstab
warn "Commented out your unencrypted swap from /etc/fstab"
i=$((i+1))
[ -e "/dev/mapper/cryptswap$i" ] || break
done
+
+ # If this is a GPT partition, mark it as no-auto mounting, to avoid
+ # auto-activating it on boot
+ if [ "$(blkid -p -s PART_ENTRY_SCHEME -o value "$swap")" = "gpt" ]; then
+ drive="${swap%[0-9]*}"
+ partno="${swap#$drive}"
+ if [ -b "$drive" ]; then
+ if printf "x\np\n" | fdisk "$drive" | grep -q "^$swap .* GUID:.*\b63\b"; then
+ echo "$swap is already marked as no-auto"
+ else
+ # toggle flag 63 ("no auto")
+ echo "marking GPT swap partition $swap as no-auto..."
+ # unfortunately fdisk fails on "cannot re-read part table" and is very verbose
+ printf "x\nS\n$partno\n63\nr\nw\n" | fdisk "$drive" >/dev/null 2>&1 || true
+ fi
+ fi
+ fi
+
# Add crypttab entry
# Use /dev/urandom, since this is not a long lived key (generated each boot),
# and so that we don't block booting while waiting for entropy