table of contents
CRYPTSETUP-LUKSFORMAT(8) | Maintenance Commands | CRYPTSETUP-LUKSFORMAT(8) |
NAME¶
cryptsetup-luksFormat - initialize a LUKS partition and set the initial passphrase
SYNOPSIS¶
cryptsetup luksFormat [<options>] <device> [<key file>]
DESCRIPTION¶
Initializes a LUKS partition and sets the passphrase via prompting or <key file>. Note that if the second argument is present, the passphrase is taken from the file given there, without using the --key-file option. Also note that for both forms of reading the passphrase from a file, you can give '-' as a file name, which results in the passphrase being read from stdin and the safety question being skipped.
You cannot call luksFormat on a device or filesystem that is mapped or in use, e.g., a mounted filesystem, used in LVM, active RAID member, etc. The device or filesystem has to be unmounted in order to call luksFormat.
To enforce a specific version of LUKS format, use --type luks1 or type luks2. The default format is LUKS2.
To use hardware encryption on an OPAL self-encrypting drive, use --hw-opal or --hw-opal-only. Note that some OPAL drives can require a PSID reset (with deletion of data) before using the LUKS format with OPAL options. See --hw-opal-factory-reset option in cryptsetup erase command.
Doing a luksFormat on an existing LUKS container will regenerate the volume key. Unless you have a header backup, all old encrypted data in the container will be permanently irretrievable. Note that luksFormat does not wipe or overwrite the data area. It only creates a new LUKS header with fresh keyslots. See cryptsetup FAQ for more info on how to wipe the whole device, including encrypted data.
<options> can be [--hash, --cipher, --verify-passphrase, --key-size, --key-slot, --key-file (takes precedence over optional second argument), --keyfile-offset, --keyfile-size, --use-random, --use-urandom, --uuid, --volume-key-file, --iter-time, --header, --pbkdf-force-iterations, --force-password, --disable-locks, --timeout, --type, --offset, --align-payload (DEPRECATED)].
For LUKS2, additional <options> can be [--integrity, --integrity-no-wipe, --sector-size, --label, --subsystem, --pbkdf, --pbkdf-memory, --pbkdf-parallel, --disable-locks, --disable-keyring, --luks2-metadata-size, --luks2-keyslots-size, --keyslot-cipher, --keyslot-key-size, --integrity-legacy-padding, --hw-opal, --hw-opal-only].
OPTIONS¶
--align-payload <number of 512 byte sectors> (DEPRECATED, use --offset)
If not specified, cryptsetup tries to use the topology info provided by the kernel for the underlying device to get the optimal alignment. If not available (or the calculated value is a multiple of the default), data is by default aligned to a 1MiB boundary (i.e., 2048 512-byte sectors).
For a detached LUKS header, this option specifies the offset on the data device. See also the --header option.
This option is DEPRECATED and has an unexpected impact on the data offset and keyslot area size (for LUKS2) due to the complex rounding. For fixed data device offset, use --offset option instead.
--batch-mode, -q
If the --verify-passphrase option is not specified, this option also switches off the passphrase verification.
--cipher, -c <cipher-spec>
cryptsetup --help shows the compiled-in defaults.
If a hash is part of the cipher specification, then it is used as part of the IV generation. For example, ESSIV needs a hash function, while "plain64" does not and hence none is specified.
For XTS mode, you can optionally set a key size of 512 bits with the -s option. Key size for XTS mode is twice that for other modes for the same security level.
--debug or --debug-json
If --debug-json is used, additional LUKS2 JSON data structures are printed.
--disable-blkid
--disable-keyring
--disable-locks
WARNING: Do not use this option unless you run cryptsetup in a restricted environment where locking is impossible to perform (where /run directory cannot be used).
--force-password
This option is ignored if cryptsetup is built without password quality checking support.
For more info about password quality check, see the manual page for pwquality.conf(5) and passwdqc.conf(5).
--hash, -h <hash-spec>
The hash algorithm must provide at least 160 bits of output. Do not use a non-crypto hash like xxhash as this breaks security. Use cryptsetup --help to show the defaults.
--header <device or file storing the LUKS header>
With a file name as the argument to --header, the file will be automatically created if it does not exist. See the cryptsetup FAQ for header size calculation.
The --align-payload option is taken as absolute sector alignment on the ciphertext device and can be zero.
--help, -?
--hw-opal
--hw-opal-only
Please note that with OPAL-only (--hw-opal-only) encryption, the configured OPAL administrator PIN (passphrase) allows unlocking all configured locking ranges without LUKS keyslot decryption (without knowledge of LUKS passphrase). Because of many observed problems with compatibility, cryptsetup currently DOES NOT use OPAL single-user mode, which would allow such decoupling of OPAL admin PIN access.
--integrity <integrity algorithm>
WARNING: This extension is EXPERIMENTAL and requires dm-integrity kernel target. For native AEAD modes, also enable "User-space interface for AEAD cipher algorithms" in the "Cryptographic API" section (CONFIG_CRYPTO_USER_API_AEAD .config option).
For more info, see the AUTHENTICATED DISK ENCRYPTION section in cryptsetup(8).
--integrity-inline
No journal or bitmap is used in this mode. The device should operate with native speed (without any overhead). This option is available since the Linux kernel version 6.11.
--integrity-key-size bytes
--integrity-legacy-padding
Do not use this option until you need compatibility with a specific old kernel.
--integrity-no-wipe
Skipping this step could also cause write failures due to IO operation alignments. For example, kernel page cache can request a read of a full page that fails due to an uninitialized integrity tag. It is usually a bug in the application that tries to read data that was not written before.
--iter-time, -i <number of milliseconds>
--key-description text
--key-file, -d file
If the name given is "-", then the passphrase will be read from stdin. In this case, reading will not stop at newline characters.
See section NOTES ON PASSPHRASE PROCESSING in cryptsetup(8) for more information.
--keyfile-offset value
--keyfile-size, -l value
This option is useful to cut trailing newlines, for example. If --keyfile-offset is also given, the size count starts after the offset.
--key-size, -s bits
See /proc/crypto for more information. Note that the key size in /proc/crypto is stated in bytes.
This option can be used for open --type plain or luksFormat. All other LUKS actions will use the key size specified in the LUKS header. Use cryptsetup --help to show the compiled-in defaults.
--key-slot, -S <0-N>
The maximum number of keyslots depends on the LUKS version. LUKS1 can have up to 8 keyslots. LUKS2 can have up to 32 keyslots based on keyslot area size and key size, but a valid keyslot ID can always be between 0 and 31 for LUKS2.
--keyslot-cipher <cipher-spec>
--keyslot-key-size <bits>
--label <label>, --subsystem <subsystem>
--luks2-keyslots-size size
--luks2-metadata-size size
--offset, -o <number of 512 byte sectors>
The --offset option sets the data offset (payload) of the data device and must be aligned to 4096-byte sectors (must be a multiple of 8). This option cannot be combined with --align-payload option.
--pbkdf <PBKDF spec>
For LUKS1, only PBKDF2 is accepted (no need to use this option). The default PBKDF for LUKS2 is set during compilation time and is available in the cryptsetup --help output.
A PBKDF is used for increasing the dictionary and brute-force attack cost for keyslot passwords. The parameters can be time, memory and parallel cost.
For PBKDF2, only the time cost (number of iterations) applies. For Argon2i/id, there is also memory cost (memory required during the process of key derivation) and parallel cost (number of threads that run in parallel during the key derivation.
Note that increasing memory cost also increases time, so the final parameter values are measured by a benchmark. The benchmark tries to find iteration time (--iter-time) with required memory cost --pbkdf-memory. If it is not possible, the memory cost is decreased as well. The parallel cost --pbkdf-parallel is constant and is checked against available CPU cores.
You can see all PBKDF parameters for a particular LUKS2 keyslot with the cryptsetup-luksDump(8) command.
If you do not want to use benchmark and want to specify all parameters directly, use --pbkdf-force-iterations with --pbkdf-memory and --pbkdf-parallel. This will override the values without benchmarking. Note it can cause extremely long unlocking time or cause out-of-memory conditions with unconditional process termination. Use only in specific cases, for example, if you know that the formatted device will be used on some small embedded system.
MINIMAL AND MAXIMAL PBKDF COSTS: For PBKDF2, the minimum iteration count is 1000 and the maximum is 4294967295 (maximum for 32-bit unsigned integer). Memory and parallel costs are not supported for PBKDF2. For Argon2i and Argon2id, the minimum iteration count (CPU cost) is 4, and the maximum is 4294967295 (maximum for a 32-bit unsigned integer). Minimum memory cost is 32 KiB and maximum is 4 GiB. If the memory cost parameter is benchmarked (not specified by a parameter), it is always in the range from 64 MiB to 1 GiB. Memory cost above 1GiB (up to the 4GiB maximum) can be setup only by the --pbkdf-memory parameter. The parallel cost minimum is 1 and maximum 4 (if enough CPU cores are available, otherwise it is decreased by the available CPU cores).
WARNING: Increasing PBKDF computational costs above the mentioned limits provides negligible additional security improvement. While elevated costs significantly increase brute-force overhead, they offer negligible protection against dictionary attacks. The marginal cost increase for processing an entire dictionary remains fundamentally insufficient.
The hardcoded PBKDF limits represent engineered trade-offs between cryptographic security and operational usability. LUKS maintains portability and must be used within a reasonable time on resource-constrained systems.
Cryptsetup deliberately restricts maximum memory cost (4 GiB) and parallel cost (4) parameters due to architectural limitations (like embedded and legacy systems).
PBKDF memory cost mandates actual physical RAM allocation with intensive write operations that must remain in physical RAM. Any swap usage results in unacceptable performance degradation. Memory management often overcommits allocations beyond available physical memory, expecting most allocated memory to remain unused. In such situations, as PBKDF always uses all allocated memory, it frequently causes out-of-memory failures that abort cryptsetup operations.
--pbkdf-force-iterations number
--pbkdf-memory number
--pbkdf-parallel number
--progress-frequency seconds
--progress-json
{
"device":"/dev/sda", // backing device or file
"device_bytes":"8192", // bytes of I/O so far
"device_size":"44040192", // total bytes of I/O to go
"speed":"126877696", // calculated speed in bytes per second (based on progress so far)
"eta_ms":"2520012", // estimated time to finish an operation in milliseconds
"time_ms":"5561235" // total time spent in IO operation in milliseconds }
Note on numbers in JSON output: Due to JSON parser limitations, all numbers are represented in a string format due to the need for full 64-bit unsigned integers.
--sector-size bytes
The encryption sector size is set based on the underlying data device if not specified explicitly. For native 4096-byte physical sector devices, it is set to 4096 bytes. For 4096/512e (4096-byte physical sector size with 512-byte sector emulation), it is set to 4096 bytes. For drives reporting only a 512-byte physical sector size, it is set to 512 bytes. If the data device is a regular file (container), it is set to 4096 bytes.
If used together with the --integrity option and dm-integrity journal, the atomicity of writes is guaranteed in all cases (but it costs write performance - data has to be written twice).
Increasing sector size from 512 to 4096 bytes can provide better performance on most modern storage devices and with some hardware encryption accelerators.
Note that using a sector size larger than the underlying storage device’s physical sector size may result in data corruption during unexpected power failures. A power failure during write operations may result in only partial completion of the encryption sector write, leaving encrypted data in an inconsistent state that cannot be properly decrypted.
--timeout, -t seconds
This option is useful when the system should not stall if the user does not input a passphrase, e.g., during boot. The default is a value of 0 seconds, which means to wait forever.
--type type
--usage
--use-random, --use-urandom
Do not use these options with recent kernels (later than version 5.6). For more details, see NOTES ON RANDOM NUMBER GENERATORS in cryptsetup(8) and urandom(4).
--uuid UUID
The UUID must be provided in the standard UUID format, e.g., 12345678-1234-1234-1234-123456789abc.
--verify-passphrase, -y
--version, -V
--volume-key-file file, --master-key-file file (OBSOLETE alias)
WARNING: If you create your own volume key, you need to make sure to do it right. Otherwise, you can end up with a low-entropy or otherwise partially predictable volume key, which will compromise security.
REPORTING BUGS¶
Report bugs at cryptsetup mailing list <cryptsetup@lists.linux.dev> or in Issues project section <https://gitlab.com/cryptsetup/cryptsetup/-/issues/new>.
Please attach the output of the failed command with --debug option added.
SEE ALSO¶
Cryptsetup FAQ <https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions>
CRYPTSETUP¶
Part of cryptsetup project <https://gitlab.com/cryptsetup/cryptsetup/>.
2025-08-19 | cryptsetup 2.8.1 |