Created
August 30, 2024 13:01
-
-
Save danny8376/92654767a60d07ff358e6d50dba82ef4 to your computer and use it in GitHub Desktop.
Mainly for enabling swap encryption in WSL2?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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