Skip to content

Instantly share code, notes, and snippets.

@danny8376
Created August 30, 2024 13:01
Show Gist options
  • Save danny8376/92654767a60d07ff358e6d50dba82ef4 to your computer and use it in GitHub Desktop.
Save danny8376/92654767a60d07ff358e6d50dba82ef4 to your computer and use it in GitHub Desktop.
Mainly for enabling swap encryption in WSL2?
#!/usr/bin/bash
mapfile -t swaps < <(cat /proc/swaps | awk '/^\/dev\// && /partition/ { print $1 }')
for swap in "${swaps[@]}"; do
swapoff "$swap"
name="swap-$(echo "$swap" | cut -c 6- | tr '/ ' '_-')"
cryptsetup plainOpen --batch-mode --cipher aes-xts-plain64 --key-size 512 --sector-size 4096 --key-file=/dev/urandom "$swap" "$name"
mkswap "/dev/mapper/$name" > /dev/null
swapon "/dev/mapper/$name"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment