# info > CRYPTSETUP

---
type: CommandReference
command: cryptsetup
mode: man
section: 8
source: man-pages
---

## Quick Reference

- `cryptsetup --type luks2 luksFormat /dev/sdX` — create LUKS2 container
- `cryptsetup open /dev/sdX sdX_crypt` — open encrypted device and map to sdX_crypt
- `cryptsetup close sdX_crypt` — remove mapping and wipe key
- `cryptsetup luksAddKey --key-slot 5 /dev/sdX` — add new passphrase to key slot 5
- `cryptsetup luksRemoveKey /dev/sdX` — remove a passphrase
- `cryptsetup luksDump /dev/sdX` — dump header information
- `cryptsetup resize <name>` — resize active mapping
- `cryptsetup status <name>` — show mapping status

## Name

manage plain dm-crypt and LUKS encrypted volumes

## Synopsis

`cryptsetup [options] <action> [action_args]`

Actions: open, close, status, resize, refresh, reencrypt, luksFormat, luksOpen, luksSuspend, luksResume, luksAddKey, luksRemoveKey, luksChangeKey, luksConvertKey, luksKillSlot, erase, luksUUID, isLuks, luksDump, luksHeaderBackup, luksHeaderRestore, token, convert, config, repair, benchmark, tcryptOpen, tcryptDump, bitlkOpen, bitlkDump.

## Options

### General Options

- `-v, --verbose` — print more information on command execution
- `--debug, --debug-json` — run in debug mode with full diagnostic logs. `--debug-json` prints additional LUKS2 JSON data structures
- `--type <device-type>` — specify device type (plain, luks, luks1, luks2, loopaes, tcrypt)
- `-h, --hash <hash-spec>` — passphrase hash for plain/loopaes open; hash for LUKS key setup (must be at least 160 bits for luksFormat)
- `-c, --cipher <cipher-spec>` — cipher specification string (default: aes-cbc-essiv:sha256 for plain, aes-xts-plain64 for LUKS)
- `-y, --verify-passphrase` — prompt for passphrase twice when creating mapping or luksFormat
- `-d, --key-file <name>` — read passphrase from file. `-` reads from stdin (newline not stripped)
- `--keyfile-offset <value>` — skip bytes at start of key file
- `--keyfile-size, -l <value>` — read max bytes from key file (default: whole file up to compiled-in max)
- `--new-keyfile-offset <value>` — skip bytes when adding new passphrase from key file (luksAddKey)
- `--new-keyfile-size <value>` — max bytes to read when adding new passphrase (luksAddKey)
- `--master-key-file <file>` — use master key from file (luksFormat, luksAddKey, open, luksDump)
- `--dump-json-metadata` — print LUKS2 JSON metadata (luksDump)
- `--dump-master-key` — dump master key (luksDump, tcryptDump)
- `--json-file <file>` — read/write token JSON (token action). `-` for stdin/stdout
- `--use-random, --use-urandom` — RNG source for master key creation (luksFormat)
- `-S, --key-slot <0-N>` — specify key slot (LUKS). LUKS1: 0-7, LUKS2: 0-31
- `-s, --key-size <bits>` — key size in bits (multiple of 8). Used for open --type plain and luksFormat
- `-b, --size <sectors>` — device size in 512-byte sectors (open, resize)
- `-o, --offset <sectors>` — start offset in backend device (open --type plain/loopaes, luksFormat). For LUKS, sets data offset (must be multiple of 8)
- `-p, --skip <sectors>` — IV calculation offset in 512-byte sectors (open --type plain/loopaes)
- `--device-size <size>[units]` — override device size. Units: S (512 bytes), K/M/G/T (1024 base), KB/MB/GB/TB (1000 base). WARNING: destructive with reencrypt
- `-r, --readonly` — set up read-only mapping
- `--shared` — create additional mapping for same ciphertext device (open --type plain)
- `--pbkdf <PBKDF>` — PBKDF algorithm for LUKS keyslot: pbkdf2, argon2i, argon2id
- `-i, --iter-time <ms>` — milliseconds to spend on PBKDF processing (luksFormat, luksAddKey, luksChangeKey). 0 = compiled-in default
- `--pbkdf-memory <number>` — memory cost for Argon2 (KB). Not for PBKDF2
- `--pbkdf-parallel <number>` — parallel cost for Argon2 (threads, max 4)
- `--pbkdf-force-iterations <num>` — set iterations directly, bypass benchmark
- `-q, --batch-mode` — suppress confirmation questions. Also disables passphrase verification for luksFormat if `-y` not given
- `--progress-frequency <seconds>` — print wipe progress every <seconds>
- `-t, --timeout <seconds>` — timeout for passphrase input (0 = wait forever)
- `-T, --tries <N>` — number of passphrase retries (default 3)
- `--align-payload <sectors>` — align payload on 512-byte sector boundary (luksFormat). DEPRECATED; use `--offset` instead
- `--uuid=UUID` — set UUID for luksFormat or change with luksUUID
- `--allow-discards` — enable discard (TRIM) requests. WARNING: security impact. Requires kernel 3.1+
- `--perf-same_cpu_crypt` — encryption on same CPU as IO submission. Kernel 4.0+
- `--perf-submit_from_crypt_cpus` — disable offloading writes after encryption. Kernel 4.0+
- `--perf-no_read_workqueue, --perf-no_write_workqueue` — bypass dm-crypt workqueue for synchronous processing. Kernel 5.9+
- `--test-passphrase` — verify passphrase without activating device (open)
- `--header <device>` — use detached LUKS header device/file
- `--header-backup-file <file>` — file for header backup/restore
- `--force-password` — skip password quality checking (luksFormat, luksAddKey, luksChangeKey)
- `--deferred` — defer device removal in close until last user closes
- `--cancel-deferred` — cancel deferred device removal
- `--disable-external-tokens` — disable loading of external LUKS2 token plugins
- `--disable-locks` — disable lock protection for metadata (LUKS2 only). WARNING: only in restricted environments
- `--disable-keyring` — store volume key directly in dm-crypt target instead of kernel keyring (LUKS2)
- `--key-description <text>` — key description in keyring for token command
- `--priority <normal|prefer|ignore>` — set priority for LUKS2 keyslot
- `--token-id` — specify token ID for token, open, resize actions
- `--token-only` — fail if token activation fails; do not fall back to passphrase prompt
- `--token-type` — restrict to specific token type
- `--sector-size <bytes>` — sector size for encryption (512-4096, power of 2). LUKS2 or plain mode
- `--iv-large-sectors` — count IV in larger sector size instead of 512 bytes (open --type plain)
- `--persistent` — write activation flags persistently into LUKS2 metadata (open, refresh)
- `--refresh` — refresh active device parameters
- `--label <LABEL>` — set label for LUKS2 device (config, format)
- `--subsystem <SUBSYSTEM>` — set subsystem description for LUKS2 device
- `--integrity <algorithm>` — integrity algorithm for authenticated encryption (LUKS2, EXPERIMENTAL). Requires dm-integrity kernel 4.12+
- `--luks2-metadata-size <size>` — enlarge LUKS2 metadata area (valid: 16,32,64,128,256,512,1024,2048,4096 kB)
- `--luks2-keyslots-size <size>` — set size of keyslot area (aligned to 4096 bytes, max 128 MB)
- `--keyslot-cipher <cipher>` — cipher for LUKS2 keyslot area
- `--keyslot-key-size <bits>` — key size for LUKS2 keyslot area
- `--integrity-no-journal` — activate integrity device without data journal (risk of non-atomic write)
- `--integrity-no-wipe` — skip wiping integrity tags (sectors report invalid until written)
- `--unbound` — create/dump LUKS2 unbound keyslot (luksAddKey, luksDump)
- `--tcrypt-hidden` — use TrueCrypt hidden header
- `--tcrypt-system` — use TrueCrypt system encryption header
- `--tcrypt-backup` — use TrueCrypt backup header
- `--disable-veracrypt` — disable VeraCrypt compatibility (only TrueCrypt)
- `--veracrypt-pim <PIM>` — set Personal Iteration Multiplier for VeraCrypt
- `--veracrypt-query-pim` — prompt for PIM
- `--serialize-memory-hard-pbkdf` — use global lock to serialize memory-hard PBKDF unlocking (for parallel activation)
- `--encrypt` — initialize device encryption (reencrypt action)
- `--decrypt` — initialize device decryption (reencrypt action)
- `--init-only` — only initialize reencryption metadata, exit
- `--resume-only` — resume reencryption operation already in metadata
- `--resilience <mode>` — reencryption resilience mode: checksum (default), journal, none
- `--resilience-hash <hash>` — hash for checksum resilience (default sha256)
- `--hotzone-size <size>` — upper limit on reencryption hotzone size
- `--reduce-device-size <size>` — reduce data device size for reencryption (--encrypt only). WARNING: destructive
- `--version` — show program version
- `--usage` — show short option help
- `-?, --help` — show help text and default parameters

## Examples

shell
# Example 1: Create LUKS2 container on block device /dev/sdX
sudo cryptsetup --type luks2 luksFormat /dev/sdX

# Example 2: Add an additional passphrase to key slot 5
sudo cryptsetup luksAddKey --key-slot 5 /dev/sdX

# Example 3: Create LUKS header backup and save to file
sudo cryptsetup luksHeaderBackup /dev/sdX --header-backup-file /var/tmp/NameOfBackupFile

# Example 4: Open LUKS container on /dev/sdX and map it to sdX_crypt
sudo cryptsetup open /dev/sdX sdX_crypt

# Example 5: Erase all key slots on /dev/sdX (WARNING: destroys access)
sudo cryptsetup erase /dev/sdX

# Example 6: Restore LUKS header from backup file
sudo cryptsetup luksHeaderRestore /dev/sdX --header-backup-file /var/tmp/NameOfBackupFile
## See Also

- [LUKS website](https://gitlab.com/cryptsetup/cryptsetup/)
- [Cryptsetup FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions)
- [LUKS1 on-disk format specification](https://gitlab.com/cryptsetup/cryptsetup/wikis/Specification)
- [LUKS2 specification](https://gitlab.com/cryptsetup/LUKS2-docs)
- [losetup(8)](http://localhost/phpMan.php/man/losetup/8/markdown)
- [dmsetup(8)](http://localhost/phpMan.php/man/dmsetup/8/markdown)
- [urandom(4)](http://localhost/phpMan.php/man/urandom/4/markdown)
- [pwquality.conf(5)](http://localhost/phpMan.php/man/pwquality.conf/5/markdown)
- [passwdqc.conf(5)](http://localhost/phpMan.php/man/passwdqc.conf/5/markdown)

## Exit Codes

- `0` — success
- `1` — wrong parameters
- `2` — no permission (bad passphrase)
- `3` — out of memory
- `4` — wrong device specified
- `5` — device already exists or device is busy