Prove that shred does not erase an SSD
Task
Demonstrate why overwriting is the wrong tool for flash, and cryptographic erasure is the right one. You will not have a real SSD to dissect, so you will reason from the mechanism and prove the reliable alternative end to end.
Steps
- Make a plain filesystem on the image and mount it (
mkfs.ext4 -q /tmp/disk.img,mkdir -p /mnt/lab,mount -o loop /tmp/disk.img /mnt/lab). Write a file containingMARKER, runsync, delete the file, andumount /mnt/lab. Show that the content is still recoverable from the raw image withgrep -ac MARKER /tmp/disk.img. Deletion frees the inode, not the blocks. Thesyncmatters: ext4 delays allocating blocks for new data, and a file deleted before its data is written back never reaches the disk at all, so the grep finds nothing and proves nothing. - Mount it again, write a second file containing
SHREDMARKER,sync, runshred -uon it, unmount, and grep the raw image forSHREDMARKER. On this setup it is gone: ext4 on a plain file overwrites in place, which is exactly the magnetic-disk assumptionshredmakes. Now reason through why a real SSD breaks it -- the controller remaps every write to fresh cells (wear levelling), so the overwrite lands somewhere new and the old cells keep the data until the controller gets round to erasing them. Nothing in the operating system can see or address those cells. - State the conclusion:
shredwas designed for magnetic disks where a write replaces a sector, and gives no guarantee on flash whose controller chooses where writes land. - Now do it the reliable way. Put the passphrase in a key file so the Verify can use it --
printf 'lab-passphrase' > /tmp/lab.key-- thencryptsetup luksFormat -q --key-file /tmp/lab.key /tmp/disk.img,cryptsetup open --key-file /tmp/lab.key /tmp/disk.img lab, make a filesystem on/dev/mapper/lab, mount it, write a file containingLUKSMARKER,sync, and confirm you can read it back. Unmount andcryptsetup close lab. Grep the raw image forLUKSMARKER: zero, because the device only ever held ciphertext. (Grep forMARKERtoo. luksFormat rewrites only the header at the front of the image, so the plaintext from step 1 may still be there -- encrypting a disk that once held plaintext does not remove the plaintext. That is why the advice is to encrypt from first use.) - Destroy the data by destroying the key:
cryptsetup luksErase -q /tmp/disk.img. The header and the ciphertext are still there --cryptsetup isLuks /tmp/disk.imgstill succeeds -- but every key slot is gone, so the correct passphrase no longer opens it. It took an instant, and nothing in the payload was overwritten. - Contrast the effort: erasing a 4TB encrypted disk this way is one fast command, where overwriting it three times is hours and still not guaranteed on flash.
- Note the hardware alternative for an unencrypted disk: the drive's own secure-erase or sanitize command, which the firmware can apply to every cell including those the host cannot address.
Verify
# after step 1: the deleted file's marker is still on the raw image
grep -ac MARKER /tmp/disk.img # non-zero
# on the encrypted volume, before AND after luksErase: only ciphertext
grep -ac 'LUKSMARKER' /tmp/disk.img # 0
# after luksErase: still a LUKS device, and the RIGHT passphrase no longer opens it
cryptsetup isLuks /tmp/disk.img && ! cryptsetup open --test-passphrase --key-file /tmp/lab.key /tmp/disk.img 2>/dev/null && echo "keys destroyed"
Run the last line before step 5 as well: it prints nothing then, because the passphrase still works. The deleted plaintext being recoverable in step 1, and the correct passphrase failing after luksErase, is the whole argument: destroying a small key beats overwriting a large payload, and on flash it is the only method that actually works.
Notes
The takeaway is architectural, not procedural: encrypt from first use, and decommissioning is a one-command key destruction regardless of the medium. Trying to shred your way to a clean SSD is effort spent on a guarantee the hardware will not give you.
This is an independent study companion for CompTIA Linux+ and is not produced by or endorsed by CompTIA.