Here's how I closed that gap on my own [Gentoo] setup.
Execute:
How this command works:~ # dd bs=4M count=2560 if=/dev/zero of=swapfile conv=fsync oflag=direct status=progress && chattr +C swapfile && \ lsattr swapfile && chmod 0600 swapfile && ls -l swapfile && cryptsetup luksFormat swapfile ~ # cryptsetup luksOpen swapfile swap_crypt && mkswap /dev/mapper/swap_crypt && swapon /dev/mapper/swap_crypt
on systems with strong privacy requirements, running swap on disk without encryption is a real risk (RAM data exposed on hibernation or physical extraction).
dd bs=4M count=2560 ...→ creates a 10GB file (block size × count = total size, adjust count for whatever size you need).chattr +C swapfile→ disables Copy-on-Write. this only does anything on Btrfs — on ext4 the command runs and silently does nothing, so check your filesystem first instead of trusting the flag blindly.chmod 0600→ strict permissions (rwfor the owner only).cryptsetup luksFormat→ creates an encrypted LUKS container.cryptsetup luksOpen + mkswap + swapon→ opens it, formats it as swap, and activates it.
Advantages: protects in-memory data against cold boot attacks and disk forensics — anyone pulling the drive lands on ciphertext instead of raw pages.
Risks: performance overhead from encryption (more noticeable on spinning disks than SSDs) and extra complexity at boot.
To make it persistent: configure it in /etc/crypttab and /etc/fstab (Gentoo/OpenRC) or set up a systemd unit. either way, the LUKS container has to be open before swapon runs — that ordering is the part that actually breaks if you get it wrong.
Nenhum comentário:
Postar um comentário
Observação: somente um membro deste blog pode postar um comentário.