Erase Every LUKS Keyslot with cryptsetup, Safely
You will finish with the exact command shape for erasing every keyslot from a LUKS container, plus checks that prevent you from applying it to the wrong device. This is a disposal or decommissioning operation, not a way to repair a damaged volume. The installed command here is cryptsetup 2.7.0 from cryptsetup-bin 2:2.7.0-1ubuntu4.2.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes for identification and review. You need a shell, the cryptsetup-bin package, and a device that you have positively identified. The command normally needs root privileges because it writes the device's encryption metadata. Reading information and checking the command line can usually be done without changing storage.
1. Read the boundary before touching storage
cryptsetup erase removes all LUKS keyslots. Without a keyslot, the volume key cannot be recovered through the LUKS header, so the container becomes permanently inaccessible. The operation is irreversible. It is not equivalent to removing one passphrase with luksRemoveKey, and it does not merely wipe the visible file data.
Stop here if you might need the data, any existing passphrase, or a future recovery path. A LUKS header backup does not make this operation safely reversible: restoring a backup can restore keyslots only if you still have the backup and understand the consequences, and the backup itself is sensitive encryption metadata. Make a verified backup before an operation that is meant to preserve access, not as a last-second rescue for an intentional erase.
Warning
Do not run the destructive command until the device, its role, and your disposal decision have been checked by a second person or by your change procedure.
2. Confirm the installed syntax
This read-only check confirms the version and shows the two command names. The old luksErase spelling is an alias for the same operation:
$ cryptsetup --version
cryptsetup 2.7.0 flags: UDEV BLKID KEYRING FIPS KERNEL_CAPI HW_OPAL
$ cryptsetup erase --help
Usage: cryptsetup erase <device>
$ cryptsetup luksErase --help
Usage: cryptsetup luksErase <device>
The full help output can include more global options. The relevant positional argument is the encrypted device, such as /dev/nvme0n1p3 or a stable path under /dev/disk/by-id/. Prefer a stable path when hardware enumeration could change.
Checkpoint: write down the exact device path you intend to erase, then compare it with your inventory and storage layout. Do not substitute a guessed partition number.
3. Check the target without erasing it
Use an inventory command to inspect the target and its neighbours. This does not alter storage:
$ lsblk -o NAME,PATH,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINTS /dev/nvme0n1
$ readlink -f /dev/disk/by-id/REPLACE_WITH_THE_DEVICE_ID
Replace both placeholders with values from your machine. Confirm the path resolves to the intended whole encrypted device or partition, not an active mapper path such as /dev/mapper/secure-data. Stop and unmount or close any active use according to your normal maintenance procedure. Erasing metadata under a live workload can disrupt that workload and leaves the running mapping in an unsafe state.
For a non-destructive command-line check, cryptsetup 2.7.0 accepts --test-args:
$ cryptsetup --test-args erase /dev/nvme0n1p3
No action taken. Invoked with --test-args option.
This checks argument handling only. It does not prove that the path is the right LUKS device, and it does not simulate the erase.
4. Erase all keyslots
Once the target and change decision are confirmed, run the operation with elevated privileges. Replace the example path exactly:
$ sudo cryptsetup erase /dev/nvme0n1p3
On a normal non-HW-OPAL LUKS device, the installed manual says that no password is required. A quiet return to the shell is the usual successful result. Check the exit status immediately:
$ printf 'exit status: %s\n' "$?"
exit status: 0
Do not add --batch-mode casually. It suppresses confirmation questions, so it is especially risky in a copied command or script. If you do use it for a controlled, reviewed automation job, treat the device path as a separately validated input.
5. Account for detached headers and HW OPAL
A detached LUKS2 header is separate from the data device. For an HW OPAL-enabled data device, the command can use --header HEADER_DEVICE_OR_FILE to identify that detached header. Do not invent this relationship from a file name; confirm it from your documented layout and a LUKS inspection performed before the change.
HW OPAL changes the safety boundary. The --hw-opal-factory-reset option performs a whole-device OPAL factory reset. The local manpage warns that all data on the device can be lost regardless of partition, and that a LUKS2 header backup does not protect it. It also says that a valid LUKS2 header is not required for that reset. Never add this option to an ordinary LUKS erase command as a troubleshooting step.
When HW OPAL credentials are required, --key-file FILE reads the Admin PIN, or the PSID with the factory-reset option. A value of - reads from standard input without stopping at newline characters. Avoid putting credentials directly in shell history. If you are not deliberately administering HW OPAL, omit both OPAL-specific options and stop if the device's encryption design is unclear.
6. Know the failure modes
A non-zero exit status means the operation did not complete successfully, but it is not a reason to repeat the command blindly. Record the error, confirm the path, check whether a device is busy, and inspect the storage change procedure. Use --debug when collecting diagnostics for the cryptsetup project, remembering that debug output may disclose device and metadata details:
$ sudo cryptsetup --debug erase /dev/nvme0n1p3
If the command reports that locking cannot be used, do not jump to --disable-locks. That option disables protection for on-disk metadata and is intended only for restricted environments where the /run directory cannot be used. Fix the environment or obtain an explicit, reviewed exception first.
There is no undo command. Recovery after an intentional erase requires a separately retained header backup and a sound recovery plan, and that plan may not apply to an OPAL factory reset. Otherwise, restore the device from a known-good backup or rebuild it as new storage. Do not assume that a surviving data area means the encrypted content is still recoverable.
Done means
- You confirmed cryptsetup 2.7.0 and selected the exact device from inventory.
- You treated keyslot erasure as irreversible and stopped active users of the device.
- You used
--test-argsonly as an argument check, not as a dry run. - You ran the destructive command with the correct device path and checked its exit status.
- You kept detached-header handling separate from HW OPAL factory reset decisions.
- You have a documented rebuild or backup plan, because this operation has no normal undo.