'\" t
.\"     Title: cryptsetup-luksformat
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.12
.\"      Date: 2025-06-04
.\"    Manual: Maintenance Commands
.\"    Source: cryptsetup 2.7.2
.\"  Language: English
.\"
.TH "CRYPTSETUP\-LUKSFORMAT" "8" "2025-06-04" "cryptsetup 2.7.2" "Maintenance Commands"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
.  mso www.tmac
.  am URL
.    ad l
.  .
.  am MTO
.    ad l
.  .
.  LINKSTYLE blue R < >
.\}
.SH "NAME"
cryptsetup\-luksFormat \- initialize a LUKS partition and set the initial passphrase
.SH "SYNOPSIS"
.sp
\fBcryptsetup \fIluksFormat\fP [<options>] <device> [<key file>]\fP
.SH "DESCRIPTION"
.sp
Initializes a LUKS partition and sets the initial passphrase (for
key\-slot 0), either via prompting or via <key file>. Note that if the
second argument is present, then the passphrase is taken from the file
given there, without the need to use the \-\-key\-file option. Also note
that for both forms of reading the passphrase from a file you can give
\(aq\-\(aq as file name, which results in the passphrase being read from stdin
and the safety\-question being skipped.
.sp
You cannot call luksFormat on a device or filesystem that is mapped or
in use, e.g., mounted filesystem, used in LVM, active RAID member, etc. The
device or filesystem has to be un\-mounted in order to call luksFormat.
.sp
To use specific version of LUKS format, use \fI\-\-type luks1\fP or \fItype luks2\fP.
To use OPAL hardware encryption on a self\-encrypting drive, use
\fI\-\-hw\-opal\fP or \fI\-\-hw\-opal\-only\fP.
.sp
\fB<options>\fP 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)].
.sp
For LUKS2, additional \fB<options>\fP 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].
.sp
\fBWARNING:\fP Doing a luksFormat on an existing LUKS container will make
all data in the old container permanently irretrievable unless you have a
header backup.
.SH "OPTIONS"
.sp
\fB\-\-align\-payload <number of 512 byte sectors>\fP
.RS 4
Align payload at a boundary of \fIvalue\fP 512\-byte sectors.
.sp
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).
.sp
For a detached LUKS header, this option specifies the offset on the data
device. See also the \-\-header option.
.sp
\fBWARNING:\fP This option is DEPRECATED and has often unexpected impact to
the data offset and keyslot area size (for LUKS2) due to the complex
rounding. For fixed data device offset use \fI\-\-offset\fP option instead.
.RE
.sp
\fB\-\-batch\-mode, \-q\fP
.RS 4
Suppresses all confirmation questions. Use with care!
.sp
If the \-\-verify\-passphrase option is not specified, this option also
switches off the passphrase verification.
.RE
.sp
\fB\-\-cipher, \-c\fP \fI<cipher\-spec>\fP
.RS 4
Set the cipher specification string.
.sp
\fIcryptsetup \-\-help\fP shows the compiled\-in defaults.
.sp
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.
.sp
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.
.RE
.sp
\fB\-\-debug or \-\-debug\-json\fP
.RS 4
Run in debug mode with full diagnostic logs. Debug output lines are
always prefixed by \fB#\fP.
.sp
If \-\-debug\-json is used, additional LUKS2 JSON data structures are printed.
.RE
.sp
\fB\-\-disable\-blkid\fP
.RS 4
Disable use of blkid library for checking and wiping on\-disk signatures.
.RE
.sp
\fB\-\-disable\-keyring\fP
.RS 4
Do not load volume key in kernel keyring and store it directly in the
dm\-crypt target instead. This option is supported only for the LUKS2 type.
.RE
.sp
\fB\-\-disable\-locks\fP
.RS 4
Disable lock protection for metadata on disk. This option is valid
only for LUKS2 and ignored for other formats.
.sp
\fBWARNING:\fP 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).
.RE
.sp
\fB\-\-force\-password\fP
.RS 4
Do not use password quality checking for new LUKS passwords.
.sp
This option is ignored if cryptsetup is built without password
quality checking support.
.sp
For more info about password quality check, see the manual page for
\fBpwquality.conf(5)\fP and \fBpasswdqc.conf(5)\fP.
.RE
.sp
\fB\-\-hash, \-h\fP \fI<hash\-spec>\fP
.RS 4
Specifies the hash used in the LUKS key setup scheme and volume key
digest.
The specified hash is used for PBKDF2 and AF splitter.
.sp
The hash algorithm must provide at least 160 bits of output.
Do not use a non\-crypto hash like \fBxxhash\fP as this breaks security.
Use \fIcryptsetup \-\-help\fP to show the defaults.
.RE
.sp
\fB\-\-header <device or file storing the LUKS header>\fP
.RS 4
Use a detached (separated) metadata device or file where the LUKS
header is stored. This option allows one to store ciphertext and LUKS
header on different devices.
.sp
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.
.sp
The \-\-align\-payload option is taken as absolute sector alignment on ciphertext
device and can be zero.
.RE
.sp
\fB\-\-help, \-?\fP
.RS 4
Show help text and default parameters.
.RE
.sp
\fB\-\-hw\-opal\fP
.RS 4
Format LUKS2 device with dm\-crypt encryption stacked on top HW based encryption configured
on SED OPAL locking range. This option enables both SW and HW based data encryption.
.RE
.sp
\fB\-\-hw\-opal\-only\fP
.RS 4
Format LUKS2 device with HW based encryption configured on SED OPAL locking range only. LUKS2
format only manages locking range unlock key. This option enables HW based data encryption managed
by SED OPAL drive only.
.sp
\fBNOTE\fP: 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.
.RE
.sp
\fB\-\-integrity <integrity algorithm>\fP
.RS 4
Specify integrity algorithm to be used for authenticated disk
encryption in LUKS2.
.sp
\fBWARNING: This extension is EXPERIMENTAL\fP and requires dm\-integrity
kernel target (available since kernel version 4.12). For native AEAD
modes, also enable "User\-space interface for AEAD cipher algorithms" in
"Cryptographic API" section (CONFIG_CRYPTO_USER_API_AEAD .config
option).
.sp
For more info, see \fIAUTHENTICATED DISK ENCRYPTION\fP section in \fBcryptsetup\fP(8).
.RE
.sp
\fB\-\-integrity\-legacy\-padding\fP
.RS 4
Use inefficient legacy padding.
.sp
\fBWARNING\fP: Do not use this option until you need compatibility with specific
old kernel.
.RE
.sp
\fB\-\-integrity\-no\-wipe\fP
.RS 4
Skip wiping of device authentication (integrity) tags. If you skip
this step, sectors will report invalid integrity tag until an
application write to the sector.
.sp
\fBNOTE:\fP Even some writes to the device can fail if the write is not
aligned to page size and page\-cache initiates read of a sector with
invalid integrity tag.
.RE
.sp
\fB\-\-iter\-time, \-i <number of milliseconds>\fP
.RS 4
The number of milliseconds to spend with PBKDF passphrase processing.
Specifying 0 as parameter selects the compiled\-in default.
.RE
.sp
\fB\-\-key\-file, \-d\fP \fIname\fP
.RS 4
Read the passphrase from file.
.sp
If the name given is "\-", then the passphrase will be read from stdin.
In this case, reading will not stop at newline characters.
.sp
See section \fINOTES ON PASSPHRASE PROCESSING\fP in \fBcryptsetup\fP(8) for more information.
.RE
.sp
\fB\-\-keyfile\-offset\fP \fIvalue\fP
.RS 4
Skip \fIvalue\fP bytes at the beginning of the key file.
.RE
.sp
\fB\-\-keyfile\-size, \-l\fP \fIvalue\fP
.RS 4
Read a maximum of \fIvalue\fP 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.
.sp
This option is useful to cut trailing newlines, for example. If
\-\-keyfile\-offset is also given, the size count starts after the offset.
.RE
.sp
\fB\-\-key\-size, \-s\fP \fIbits\fP
.RS 4
Sets key size in \fIbits\fP. The argument has to be a multiple of 8. The
possible key\-sizes are limited by the cipher and mode used.
.sp
See /proc/crypto for more information. Note that key\-size in
/proc/crypto is stated in bytes.
.sp
This option can be used for \fIopen \-\-type plain\fP or \fIluksFormat\fP. All
other LUKS actions will use the key\-size specified in the LUKS header.
Use \fIcryptsetup \-\-help\fP to show the compiled\-in defaults.
.RE
.sp
\fB\-\-key\-slot, \-S <0\-N>\fP
.RS 4
For LUKS operations that add key material, this option allows you to
specify which key slot is selected for the new key.
.sp
The maximum number of key slots depends on the LUKS version. LUKS1 can have up
to 8 key slots. LUKS2 can have up to 32 key slots based on key slot area
size and key size, but a valid key slot ID can always be between 0 and
31 for LUKS2.
.RE
.sp
\fB\-\-keyslot\-cipher <cipher\-spec>\fP
.RS 4
This option can be used to set specific cipher encryption for the
LUKS2 keyslot area.
.RE
.sp
\fB\-\-keyslot\-key\-size <bits>\fP
.RS 4
This option can be used to set specific key size for the LUKS2 keyslot
area.
.RE
.sp
\fB\-\-label <LABEL> \-\-subsystem <SUBSYSTEM>\fP
.RS 4
Set label and subsystem description for LUKS2 device.
The label and subsystem are optional fields and can be later used
in udev scripts for triggering user actions once the device marked
by these labels is detected.
.RE
.sp
\fB\-\-luks2\-keyslots\-size <size>\fP
.RS 4
This option can be used to set specific size of the LUKS2 binary
keyslot area (key material is encrypted there). The value must be
aligned to multiple of 4096 bytes with maximum size 128MB. The <size>
can be specified with unit suffix (for example 128k).
.RE
.sp
\fB\-\-luks2\-metadata\-size <size>\fP
.RS 4
This option can be used to enlarge the LUKS2 metadata (JSON) area. The
size includes 4096 bytes for binary metadata (usable JSON area is
smaller of the binary area). According to LUKS2 specification, only
these values are valid: 16, 32, 64, 128, 256, 512, 1024, 2048 and 4096
kB The <size> can be specified with unit suffix (for example 128k).
.RE
.sp
\fB\-\-offset, \-o <number of 512 byte sectors>\fP
.RS 4
Start offset in the backend device in 512\-byte sectors.
.sp
The \-\-offset option sets the data offset (payload) of data
device and must be aligned to 4096\-byte sectors (must be multiple of
8). This option cannot be combined with \-\-align\-payload option.
.RE
.sp
\fB\-\-pbkdf <PBKDF spec>\fP
.RS 4
Set Password\-Based Key Derivation Function (PBKDF) algorithm for LUKS
keyslot. The PBKDF can be: \fIpbkdf2\fP (for PBKDF2 according to RFC2898),
\fIargon2i\fP for Argon2i or \fIargon2id\fP for Argon2id (see
.URL "https://www.cryptolux.org/index.php/Argon2" "Argon2" " "
for more info).
.sp
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 \fIcryptsetup \-\-help\fP output.
.sp
A PBKDF is used for increasing dictionary and brute\-force attack cost
for keyslot passwords. The parameters can be time, memory and parallel
cost.
.sp
For PBKDF2, only 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.
.sp
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 (\fI\-\-iter\-time\fP) with required memory cost
\fI\-\-pbkdf\-memory\fP. If it is not possible, the memory cost is decreased as
well. The parallel cost \fI\-\-pbkdf\-parallel\fP is constant and is checked
against available CPU cores.
.sp
You can see all PBKDF parameters for particular LUKS2 keyslot with
\fBcryptsetup\-luksDump\fP(8) command.
.sp
\fBNOTE:\fP If you do not want to use benchmark and want to specify all
parameters directly, use \fI\-\-pbkdf\-force\-iterations\fP with
\fI\-\-pbkdf\-memory\fP and \fI\-\-pbkdf\-parallel\fP. 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.
.sp
\fBMINIMAL AND MAXIMAL PBKDF COSTS:\fP For \fBPBKDF2\fP, the minimum iteration
count is 1000 and maximum is 4294967295 (maximum for 32bit unsigned
integer). Memory and parallel costs are unused for PBKDF2. For \fBArgon2i\fP
and \fBArgon2id\fP, minimum iteration count (CPU cost) is 4 and maximum is
4294967295 (maximum for 32bit unsigned integer). Minimum memory cost is
32 KiB and maximum is 4 GiB. (Limited by addressable memory on some CPU
platforms.) If the memory cost parameter is benchmarked (not specified
by a parameter) it is always in range from 64 MiB to 1 GiB. The parallel
cost minimum is 1 and maximum 4 (if enough CPUs cores are available,
otherwise it is decreased).
.RE
.sp
\fB\-\-pbkdf\-force\-iterations <num>\fP
.RS 4
Avoid PBKDF benchmark and set time cost (iterations) directly. It can
be used for LUKS/LUKS2 device only. See \fI\-\-pbkdf\fP option for more
info.
.RE
.sp
\fB\-\-pbkdf\-memory <number>\fP
.RS 4
Set the memory cost for PBKDF (for Argon2i/id the number represents
kilobytes). Note that it is maximal value, PBKDF benchmark or
available physical memory can decrease it. This option is not
available for PBKDF2.
.RE
.sp
\fB\-\-pbkdf\-parallel <number>\fP
.RS 4
Set the parallel cost for PBKDF (number of threads, up to 4). Note
that it is maximal value, it is decreased automatically if CPU online
count is lower. This option is not available for PBKDF2.
.RE
.sp
\fB\-\-progress\-frequency\fP \fIseconds\fP
.RS 4
Print separate line every \fIseconds\fP with wipe progress.
.RE
.sp
\fB\-\-progress\-json\fP
.RS 4
Prints progress data in JSON format suitable mostly for machine
processing. It prints separate line every half second (or based on
\fI\-\-progress\-frequency\fP value). The JSON output looks as follows during
progress (except it\(cqs compact single line):
.sp
.if n .RS 4
.nf
.fam C
{
  "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
}
.fam
.fi
.if n .RE
.sp
Note on numbers in JSON output: Due to JSON parsers limitations all
numbers are represented in a string format due to need of full 64bit
unsigned integers.
.RE
.sp
\fB\-\-sector\-size\fP \fIbytes\fP
.RS 4
Set sector size for use with disk encryption. It must be power of two
and in range 512 \- 4096 bytes. This option is available only with LUKS2
format.
.sp
For LUKS2 devices it\(cqs established based on parameters provided by
underlying data device. For native 4K block devices it\(cqs 4096 bytes.
For 4K/512e (4K physical sector size with 512 bytes emulation) it\(cqs
4096 bytes. For drives reporting only 512 bytes block size it remains
512 bytes. If data device is regular file put in filesystem it\(cqs 4096
bytes.
.sp
Note that if sector size is higher than underlying device hardware
sector and there is not integrity protection that uses data journal,
using this option can increase risk on incomplete sector writes during a
power fail.
.sp
If used together with \fI\-\-integrity\fP option and dm\-integrity journal, the
atomicity of writes is guaranteed in all cases (but it cost write
performance \- data has to be written twice).
.sp
Increasing sector size from 512 bytes to 4096 bytes can provide better
performance on most of the modern storage devices and also with some hw
encryption accelerators.
.RE
.sp
\fB\-\-timeout, \-t <number of seconds>\fP
.RS 4
The number of seconds to wait before timeout on passphrase input via
terminal. It is relevant every time a passphrase is asked.
It has no effect if used in conjunction with \-\-key\-file.
.sp
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.
.RE
.sp
\fB\-\-type <device\-type>\fP
.RS 4
Specifies required device type, for more info read \fIBASIC ACTIONS\fP section in \fBcryptsetup\fP(8).
.RE
.sp
\fB\-\-usage\fP
.RS 4
Show short option help.
.RE
.sp
\fB\-\-use\-random\fP, \fB\-\-use\-urandom\fP
.RS 4
For \fIluksFormat\fP these options define which kernel random number
generator will be used to create the volume key (which is a long\-term
key).
.sp
See \fBNOTES ON RANDOM NUMBER GENERATORS\fP in \fBcryptsetup\fP(8) for more
information. Use \fIcryptsetup \-\-help\fP to show the compiled\-in default random
number generator.
.sp
\fBWARNING:\fP In a low\-entropy situation (e.g. in an embedded system) and older
kernels, both selections are problematic. Using /dev/urandom can lead to weak keys.
Using /dev/random can block a long time, potentially forever, if not
enough entropy can be harvested by the kernel.
.RE
.sp
\fB\-\-uuid <UUID>\fP
.RS 4
Use the provided \fIUUID\fP for the \fIluksFormat\fP command instead of
generating a new one. Changes the existing \fIUUID\fP when used with the
\fIluksUUID\fP command.
.sp
The \fIUUID\fP must be provided in the standard UUID format, e.g.
12345678\-1234\-1234\-1234\-123456789abc.
.RE
.sp
\fB\-\-verify\-passphrase, \-y\fP
.RS 4
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.
.RE
.sp
\fB\-\-version, \-V\fP
.RS 4
Show the program version.
.RE
.sp
\fB\-\-volume\-key\-file, \-\-master\-key\-file (OBSOLETE alias)\fP
.RS 4
Use a volume key stored in a file.
\fBWARNING:\fP 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.
.RE
.SH "REPORTING BUGS"
.sp
Report bugs at \c
.MTO "cryptsetup\(atlists.linux.dev" "\fBcryptsetup mailing list\fP"
or in \c
.URL "https://gitlab.com/cryptsetup/cryptsetup/\-/issues/new" "\fBIssues project section\fP" "."
.sp
Please attach output of the failed command with \-\-debug option added.
.SH "SEE ALSO"
.sp
.URL "https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions" "\fBCryptsetup FAQ\fP" ""
.sp
\fBcryptsetup\fP(8), \fBintegritysetup\fP(8) and \fBveritysetup\fP(8)
.SH "CRYPTSETUP"
.sp
Part of \c
.URL "https://gitlab.com/cryptsetup/cryptsetup/" "\fBcryptsetup project\fP" "."