CRYPTSETUP-LUKSFORMAT(8)

πŸ’– CRYPTSETUP-LUKSFORMAT πŸ’–

okay bestie, welcome to cryptsetup-luksFormat(8) β€” it's filed under Maintenance Commands and it's literally the moment your plain lil partition gets a glow-up into a LUKS container. let's go 🫢


✨ NAME ✨

cryptsetup-luksFormat β€” initialize a LUKS partition and set the initial passphrase


🌸 SYNOPSIS 🌸

cryptsetup luksFormat [<options>] <device> [<key file>]

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea β˜•: this initializes a LUKS partition and sets the passphrase, either by prompting you for it or by grabbing it from <key file>. Heads up tho β€” if that second argument is actually there, the passphrase comes from the file given there, and it does not go through the --key-file option. And for both ways of reading a passphrase from a file, you can pass '-' as the file name, which means the passphrase gets read from stdin and the safety question gets skipped entirely. no cap ✨

You literally cannot call luksFormat on a device or filesystem that's mapped or in use β€” like a mounted filesystem, something used in LVM, an active RAID member, etc. The device or filesystem has to be unmounted before you call luksFormat. it's giving "please close the app first" energy πŸ’…

Want to force a specific version of LUKS format? Use --type luks1 or type luks2. The default format is LUKS2. πŸ‘‘

Want 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 the --hw-opal-factory-reset option in the 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. 😭 And note that luksFormat does not wipe or overwrite the data area β€” it only creates a new LUKS header with fresh keyslots. See the 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) β€” align the payload at a boundary of that many 512-byte sectors.

If you don't specify it, cryptsetup tries to use the topology info the kernel hands over for the underlying device to get the optimal alignment. If that's 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 a fixed data device offset, use the --offset option instead. bestie, just use --offset fr fr πŸ’€
  • --batch-mode, -q β€” suppresses all confirmation questions. Use with care!

If the --verify-passphrase option is not specified, this option also switches off the passphrase verification. 🫣

  • --cipher, -c <cipher-spec> β€” set the cipher specification string.

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 β€” run in debug mode with full diagnostic logs. Debug output lines are always prefixed by #.

If --debug-json is used, additional LUKS2 JSON data structures are printed. πŸ”

  • --disable-blkid β€” disable use of the blkid library for checking and wiping on-disk signatures.
  • --disable-keyring β€” do not load the volume key in the kernel keyring; store it directly in the dm-crypt target instead. This option is supported only for the LUKS2 type.
  • --disable-locks β€” disable lock protection for metadata on disk. This option is valid only for LUKS2 and is ignored for other formats.
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 β€” do not use password quality checking for new LUKS passwords.

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> β€” specifies the hash used in the LUKS key setup scheme and volume key digest. The specified hash is used for PBKDF2 and the AF splitter.

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> β€” use a detached (separated) metadata device or file where the LUKS header is stored. This option allows one to store the ciphertext and LUKS header on different devices. iconic, honestly 🌈

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, -? β€” show help text and default parameters. πŸ†˜
  • --hw-opal β€” format LUKS2 device with dm-crypt encryption stacked on top of HW-based encryption configured on SED OPAL locking range. This option enables both SW and HW based data encryption. πŸ”₯
  • --hw-opal-only β€” format LUKS2 device with HW based encryption configured on SED OPAL locking range only. LUKS2 format only manages the locking range unlock key. This option enables HW-based data encryption managed by the SED OPAL drive 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> β€” specify the integrity algorithm to be used for authenticated disk encryption in LUKS2.
WARNING: This extension is EXPERIMENTAL and requires the 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 β€” store integrity tags in hardware sector integrity fields. The device must support sectors with additional protection information (PI, also known as DIF - data integrity field) of the requested size. Another storage subsystem must not use the additional field (the device must present a "nop" profile in the kernel). Note that some devices must be reformatted at a low level to support this option; for NVMe devices, see nvme(1) id-ns LBA profiles.

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 bits β€” the size of the data integrity key. The argument has to be a multiple of 8. Configurable only for HMAC integrity. The default integrity key size is set to the same as the hash output length.
  • --integrity-legacy-padding β€” use inefficient legacy padding.
Do not use this option until you need compatibility with a specific old kernel. like, only then πŸ™ˆ
  • --integrity-no-wipe β€” skip wiping of device authentication (integrity) tags. If you skip this step, sectors will report an invalid integrity tag until an application writes to the sector.

Skipping this step could also cause write failures due to IO operation alignments. For example, the 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> β€” the number of milliseconds to spend with PBKDF passphrase processing. Specifying 0 as a parameter selects the compiled-in default. ⏱️
  • --key-description text β€” set the key description in the keyring that will be used for passphrase retrieval.
  • --key-file, -d file β€” read the passphrase from the 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 β€” skip value bytes at the beginning of the key file.
  • --keyfile-size, -l value β€” read a maximum of value bytes from the key file. The default is to read the whole file up to the compiled-in maximum that can be queried with --help. Supplying more data than the compiled-in maximum aborts the operation.

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 β€” sets key size in bits. The argument has to be a multiple of 8. The possible key sizes are limited by the cipher and mode used.

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> β€” for LUKS operations that add key material, this option allows you to specify which keyslot is selected for the new key. πŸ”‘

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> β€” bestie, this one lets you set a specific cipher encryption just for the LUKS2 keyslot area. like, the lil zone where your key material lives gets its own cipher. so specific πŸ’…
  • --keyslot-key-size <bits> β€” and this sets a specific key size for that same LUKS2 keyslot area. key size for the keyslot, yes ma'am ✨
  • --label <label>, --subsystem <subsystem> β€” sets the label and the subsystem description for a LUKS2 device. they're giving filesystem-label energy fr. both of these are optional fields and you can use them later in udev scripts to trigger user actions once the device marked with these labels gets detected πŸ‘‘
  • --luks2-keyslots-size size β€” use this to set a specific size for the LUKS2 binary keyslot area (that's where the key material is encrypted, iykyk). the value must be aligned to a multiple of 4096 bytes, with a maximum size of 128MB. and yeah, the <size> can take a unit suffix (like 128k) πŸŽ€
  • --luks2-metadata-size size β€” this one enlarges the LUKS2 metadata (JSON) area. the size includes 4096 bytes for binary metadata (so the usable JSON area is smaller than the binary area, sneaky). according to the LUKS2 specification, literally only these values are valid: 16, 32, 64, 128, 256, 512, 1024, 2048 and 4096 kB. the <size> can be specified with a unit suffix (for example, 128k) 🌸
  • --offset, -o <number of 512 byte sectors> β€” start offset in the backend device, measured in 512-byte sectors.

the --offset option sets the data offset (payload) of the data device, and it must be aligned to 4096-byte sectors (so it has to be a multiple of 8). this option cannot be combined with the --align-payload option. pick one, bestie 🫢

  • --pbkdf <PBKDF spec> β€” sets the Password-Based Key Derivation Function (PBKDF) algorithm for the LUKS keyslot. the PBKDF can be: pbkdf2 (for PBKDF2 according to RFC2898), argon2i for Argon2i, or argon2id for Argon2id (see Argon2 at https://www.cryptolux.org/index.php/Argon2 for more info).

for LUKS1, only PBKDF2 is accepted (and there's no need to use this option at all). the default PBKDF for LUKS2 is set during compilation time and you can see it in the cryptsetup --help output.

a PBKDF exists to increase the dictionary and brute-force attack cost for keyslot passwords. the parameters can be time cost, memory cost and parallel cost.

for PBKDF2, only the time cost (number of iterations) applies. for Argon2i/id, there's also memory cost (the memory required during the process of key derivation) and parallel cost (the 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 the required memory cost --pbkdf-memory. if it's not possible, the memory cost gets 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 don't want to use the benchmark and want to specify all parameters directly, use --pbkdf-force-iterations with --pbkdf-memory and --pbkdf-parallel. this overrides 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. like, be careful okay 😭

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's always in the range from 64 MiB to 1 GiB. memory cost above 1GiB (up to the 4GiB maximum) can be set up only by the --pbkdf-memory parameter. the parallel cost minimum is 1 and maximum 4 (if enough CPU cores are available, otherwise it's 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 usable within a reasonable time on resource-constrained systems.

cryptsetup deliberately restricts the 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, since PBKDF always uses all allocated memory, it frequently causes out-of-memory failures that abort cryptsetup operations πŸ’€

  • --pbkdf-force-iterations number β€” avoid the PBKDF benchmark and set the time cost (iterations) directly. it can be used only for a LUKS/LUKS2 device. see the --pbkdf option for more info πŸ”₯
  • --pbkdf-memory number β€” set the memory cost for PBKDF (for Argon2i/id, the number represents kilobytes). note that it's the maximal value; the PBKDF benchmark or available physical memory can decrease it. this option is not available for PBKDF2 🌈
  • --pbkdf-parallel number β€” set the parallel cost for PBKDF (number of threads, up to 4). note that it's the maximal value; it gets decreased automatically if the CPU online count is lower. this option is not available for PBKDF2 ⭐
  • --progress-frequency seconds β€” print a separate line every seconds with wipe progress. lil heartbeat updates πŸ’–
  • --progress-json β€” prints progress data in JSON format, which is suitable mostly for machine processing. it prints a separate line every half second (or based on the --progress-frequency value). the JSON output looks as follows during progress (except it's a compact single line):
{
  "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, because they need full 64-bit unsigned integers 🧚

  • --sector-size bytes β€” set the encryption sector size for use with LUKS2 device type. it must be a power of two and in the 512 - 4096 bytes range.

the encryption sector size is set based on the underlying data device if not specified explicitly. for native 4096-byte physical sector devices, it's set to 4096 bytes. for 4096/512e (4096-byte physical sector size with 512-byte sector emulation), it's set to 4096 bytes. for drives reporting only a 512-byte physical sector size, it's set to 512 bytes. if the data device is a regular file (container), it's 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). trade-offs, bestie 😭

increasing sector size from 512 to 4096 bytes can provide better performance on most modern storage devices and with some hardware encryption accelerators. slay πŸ”₯

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. do not play with this πŸ™ˆ
  • --timeout, -t seconds β€” the number of seconds to wait before a timeout on passphrase input via terminal. it's relevant every time a passphrase is asked. it has no effect if used in conjunction with --key-file.

this option is useful when the system should not stall if the user doesn't input a passphrase, e.g. during boot. the default is a value of 0 seconds, which means to wait forever. forever ever πŸ¦‹

  • --type type β€” specifies the required device type. for more info, read the BASIC ACTIONS section in cryptsetup(8) ✨
  • --usage β€” show short option help. the lil cheat sheet πŸŽ€
  • --use-random, --use-urandom β€” for luksFormat, these options define which kernel random number generator will be used to create the volume key (which is a long-term key).
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). genuinely, don't πŸ’€
  • --uuid UUID β€” use the provided UUID for the luksFormat command instead of generating a new one. changes the existing UUID when used with the luksUUID command.

the UUID must be provided in the standard UUID format, e.g. 12345678-1234-1234-1234-123456789abc 🌸

  • --verify-passphrase, -y β€” when interactively asking for a passphrase, ask for it twice and complain if both inputs do not match. ignored on input from file or stdin. double-check era πŸ’…
  • --version, -V β€” show the program version πŸ‘‘
  • --volume-key-file file, --master-key-file file (OBSOLETE alias) β€” use a volume key stored in a file.
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. no cap, this is the whole game πŸ”₯

πŸ› REPORTING BUGS πŸ›

ok so bestie, if you found a bug (and like, valid, software is a whole vibe), here's where you spill the tea:

pro tip bestie: please please PLEASE attach the output of the failed command with the --debug option added πŸ₯Ί it's giving "help me help you" and honestly it makes everything so much easier, no cap.

πŸ‘€ SEE ALSO πŸ‘€

things you're gonna wanna peek at too, fr fr:

like a whole squad of manuals, go read them 🫢


πŸ‘‘ CRYPTSETUP πŸ‘‘

this page is part of the cryptsetup project πŸ’… β€” https://gitlab.com/cryptsetup/cryptsetup/ β€” go check it out, the main character energy is off the charts ⭐


and that's a wrap bestie!! πŸŽ€ this whole thing is cryptsetup 2.8.8 and it's dated 2026-09-07, and it's the manual page for CRYPTSETUP-LUKSFORMAT(8). slay, you read the whole thing, so proud of you πŸ’–βœ¨πŸ¦‹

πŸ“¦ where this page comes from