1CRYPTSETUP-LUKSFORMAT(8) Maintenance Commands CRYPTSETUP-LUKSFORMAT(8)
2
3
4
6 cryptsetup-luksFormat - initialize a LUKS partition and set the initial
7 passphrase
8
10 cryptsetup luksFormat [<options>] <device> [<key file>]
11
13 Initializes a LUKS partition and sets the initial passphrase (for
14 key-slot 0), either via prompting or via <key file>. Note that if the
15 second argument is present, then the passphrase is taken from the file
16 given there, without the need to use the --key-file option. Also note
17 that for both forms of reading the passphrase from a file you can give
18 '-' as file name, which results in the passphrase being read from stdin
19 and the safety-question being skipped.
20
21 You cannot call luksFormat on a device or filesystem that is mapped or
22 in use, e.g., mounted filesystem, used in LVM, active RAID member, etc.
23 The device or filesystem has to be un-mounted in order to call
24 luksFormat.
25
26 To use specific version of LUKS format, use --type luks1 or type luks2.
27
28 <options> can be [--hash, --cipher, --verify-passphrase, --key-size,
29 --key-slot, --key-file (takes precedence over optional second
30 argument), --keyfile-offset, --keyfile-size, --use-random,
31 --use-urandom, --uuid, --volume-key-file, --iter-time, --header,
32 --pbkdf-force-iterations, --force-password, --disable-locks, --timeout,
33 --type, --offset, --align-payload (deprecated)].
34
35 For LUKS2, additional <options> can be [--integrity,
36 --integrity-no-wipe, --sector-size, --label, --subsystem, --pbkdf,
37 --pbkdf-memory, --pbkdf-parallel, --disable-locks, --disable-keyring,
38 --luks2-metadata-size, --luks2-keyslots-size, --keyslot-cipher,
39 --keyslot-key-size, --integrity-legacy-padding].
40
41 WARNING: Doing a luksFormat on an existing LUKS container will make all
42 data in the old container permanently irretrievable unless you have a
43 header backup.
44
46 --type <device-type>
47 Specifies required device type, for more info read BASIC ACTIONS
48 section in cryptsetup(8).
49
50 --hash, -h <hash-spec>
51 Specifies the hash used in the LUKS key setup scheme and volume key
52 digest. The specified hash is used for PBKDF2 and AF splitter.
53
54 The hash algorithm must provide at least 160 bits of output. Do not
55 use a non-crypto hash like xxhash as this breaks security. Use
56 cryptsetup --help to show the defaults.
57
58 --cipher, -c <cipher-spec>
59 Set the cipher specification string.
60
61 cryptsetup --help shows the compiled-in defaults.
62
63 If a hash is part of the cipher specification, then it is used as
64 part of the IV generation. For example, ESSIV needs a hash
65 function, while "plain64" does not and hence none is specified.
66
67 For XTS mode you can optionally set a key size of 512 bits with the
68 -s option. Key size for XTS mode is twice that for other modes for
69 the same security level.
70
71 --verify-passphrase, -y
72 When interactively asking for a passphrase, ask for it twice and
73 complain if both inputs do not match. Ignored on input from file or
74 stdin.
75
76 --key-file, -d name
77 Read the passphrase from file.
78
79 If the name given is "-", then the passphrase will be read from
80 stdin. In this case, reading will not stop at newline characters.
81
82 With LUKS, the passphrase supplied via --key-file is always the
83 existing passphrase requested by a command, except in the case of
84 luksFormat where --key-file is equivalent to the positional key
85 file argument.
86
87 If you want to set a new passphrase via key file, you have to use a
88 positional argument to luksAddKey.
89
90 See section NOTES ON PASSPHRASE PROCESSING in cryptsetup(8) for
91 more information.
92
93 --keyfile-offset value
94 Skip value bytes at the beginning of the key file.
95
96 --keyfile-size, -l value
97 Read a maximum of value bytes from the key file. The default is to
98 read the whole file up to the compiled-in maximum that can be
99 queried with --help. Supplying more data than the compiled-in
100 maximum aborts the operation.
101
102 This option is useful to cut trailing newlines, for example. If
103 --keyfile-offset is also given, the size count starts after the
104 offset.
105
106 --volume-key-file, --master-key-file (OBSOLETE alias)
107 Use a volume key stored in a file. WARNING: If you create your own
108 volume key, you need to make sure to do it right. Otherwise, you
109 can end up with a low-entropy or otherwise partially predictable
110 volume key which will compromise security.
111
112 --use-random, --use-urandom
113 For luksFormat these options define which kernel random number
114 generator will be used to create the volume key (which is a
115 long-term key).
116
117 See NOTES ON RANDOM NUMBER GENERATORS in cryptsetup(8) for more
118 information. Use cryptsetup --help to show the compiled-in default
119 random number generator.
120
121 WARNING: In a low-entropy situation (e.g. in an embedded system)
122 and older kernels, both selections are problematic. Using
123 /dev/urandom can lead to weak keys. Using /dev/random can block a
124 long time, potentially forever, if not enough entropy can be
125 harvested by the kernel.
126
127 --key-slot, -S <0-N>
128 For LUKS operations that add key material, this option allows you
129 to specify which key slot is selected for the new key.
130
131 The maximum number of key slots depends on the LUKS version. LUKS1
132 can have up to 8 key slots. LUKS2 can have up to 32 key slots based
133 on key slot area size and key size, but a valid key slot ID can
134 always be between 0 and 31 for LUKS2.
135
136 --key-size, -s bits
137 Sets key size in bits. The argument has to be a multiple of 8. The
138 possible key-sizes are limited by the cipher and mode used.
139
140 See /proc/crypto for more information. Note that key-size in
141 /proc/crypto is stated in bytes.
142
143 This option can be used for open --type plain or luksFormat. All
144 other LUKS actions will use the key-size specified in the LUKS
145 header. Use cryptsetup --help to show the compiled-in defaults.
146
147 --offset, -o <number of 512 byte sectors>
148 Start offset in the backend device in 512-byte sectors.
149
150 The --offset option sets the data offset (payload) of data device
151 and must be aligned to 4096-byte sectors (must be multiple of 8).
152 This option cannot be combined with --align-payload option.
153
154 --pbkdf <PBKDF spec>
155 Set Password-Based Key Derivation Function (PBKDF) algorithm for
156 LUKS keyslot. The PBKDF can be: pbkdf2 (for PBKDF2 according to
157 RFC2898), argon2i for Argon2i or argon2id for Argon2id (see Argon2
158 <https://www.cryptolux.org/index.php/Argon2> for more info).
159
160 For LUKS1, only PBKDF2 is accepted (no need to use this option).
161 The default PBKDF for LUKS2 is set during compilation time and is
162 available in cryptsetup --help output.
163
164 A PBKDF is used for increasing dictionary and brute-force attack
165 cost for keyslot passwords. The parameters can be time, memory and
166 parallel cost.
167
168 For PBKDF2, only time cost (number of iterations) applies. For
169 Argon2i/id, there is also memory cost (memory required during the
170 process of key derivation) and parallel cost (number of threads
171 that run in parallel during the key derivation.
172
173 Note that increasing memory cost also increases time, so the final
174 parameter values are measured by a benchmark. The benchmark tries
175 to find iteration time (--iter-time) with required memory cost
176 --pbkdf-memory. If it is not possible, the memory cost is decreased
177 as well. The parallel cost --pbkdf-parallel is constant and is
178 checked against available CPU cores.
179
180 You can see all PBKDF parameters for particular LUKS2 keyslot with
181 cryptsetup-luksDump(8) command.
182
183 NOTE: If you do not want to use benchmark and want to specify all
184 parameters directly, use --pbkdf-force-iterations with
185 --pbkdf-memory and --pbkdf-parallel. This will override the values
186 without benchmarking. Note it can cause extremely long unlocking
187 time. Use only in specific cases, for example, if you know that the
188 formatted device will be used on some small embedded system.
189
190 MINIMAL AND MAXIMAL PBKDF COSTS: For PBKDF2, the minimum iteration
191 count is 1000 and maximum is 4294967295 (maximum for 32bit unsigned
192 integer). Memory and parallel costs are unused for PBKDF2. For
193 Argon2i and Argon2id, minimum iteration count (CPU cost) is 4 and
194 maximum is 4294967295 (maximum for 32bit unsigned integer). Minimum
195 memory cost is 32 KiB and maximum is 4 GiB. (Limited by addressable
196 memory on some CPU platforms.) If the memory cost parameter is
197 benchmarked (not specified by a parameter) it is always in range
198 from 64 MiB to 1 GiB. The parallel cost minimum is 1 and maximum 4
199 (if enough CPUs cores are available, otherwise it is decreased).
200
201 --iter-time, -i <number of milliseconds>
202 The number of milliseconds to spend with PBKDF passphrase
203 processing. Specifying 0 as parameter selects the compiled-in
204 default.
205
206 --pbkdf-memory <number>
207 Set the memory cost for PBKDF (for Argon2i/id the number represents
208 kilobytes). Note that it is maximal value, PBKDF benchmark or
209 available physical memory can decrease it. This option is not
210 available for PBKDF2.
211
212 --pbkdf-parallel <number>
213 Set the parallel cost for PBKDF (number of threads, up to 4). Note
214 that it is maximal value, it is decreased automatically if CPU
215 online count is lower. This option is not available for PBKDF2.
216
217 --pbkdf-force-iterations <num>
218 Avoid PBKDF benchmark and set time cost (iterations) directly. It
219 can be used for LUKS/LUKS2 device only. See --pbkdf option for more
220 info.
221
222 --progress-frequency seconds
223 Print separate line every seconds with wipe progress.
224
225 --progress-json
226 Prints progress data in JSON format suitable mostly for machine
227 processing. It prints separate line every half second (or based on
228 --progress-frequency value). The JSON output looks as follows
229 during progress (except it’s compact single line):
230
231 {
232 "device":"/dev/sda" // backing device or file
233 "device_bytes":"8192", // bytes of I/O so far
234 "device_size":"44040192", // total bytes of I/O to go
235 "speed":"126877696", // calculated speed in bytes per second (based on progress so far)
236 "eta_ms":"2520012" // estimated time to finish an operation in milliseconds
237 "time_ms":"5561235" // total time spent in IO operation in milliseconds
238 }
239
240 Note on numbers in JSON output: Due to JSON parsers limitations all
241 numbers are represented in a string format due to need of full
242 64bit unsigned integers.
243
244 --timeout, -t <number of seconds>
245 The number of seconds to wait before timeout on passphrase input
246 via terminal. It is relevant every time a passphrase is asked. It
247 has no effect if used in conjunction with --key-file.
248
249 This option is useful when the system should not stall if the user
250 does not input a passphrase, e.g. during boot. The default is a
251 value of 0 seconds, which means to wait forever.
252
253 --align-payload <number of 512 byte sectors>
254 Align payload at a boundary of value 512-byte sectors.
255
256 If not specified, cryptsetup tries to use the topology info
257 provided by the kernel for the underlying device to get the optimal
258 alignment. If not available (or the calculated value is a multiple
259 of the default) data is by default aligned to a 1MiB boundary (i.e.
260 2048 512-byte sectors).
261
262 For a detached LUKS header, this option specifies the offset on the
263 data device. See also the --header option.
264
265 WARNING: This option is DEPRECATED and has often unexpected impact
266 to the data offset and keyslot area size (for LUKS2) due to the
267 complex rounding. For fixed data device offset use --offset option
268 instead.
269
270 --uuid <UUID>
271 Use the provided UUID for the luksFormat command instead of
272 generating a new one. Changes the existing UUID when used with the
273 luksUUID command.
274
275 The UUID must be provided in the standard UUID format, e.g.
276 12345678-1234-1234-1234-123456789abc.
277
278 --header <device or file storing the LUKS header>
279 Use a detached (separated) metadata device or file where the LUKS
280 header is stored. This option allows one to store ciphertext and
281 LUKS header on different devices.
282
283 With a file name as the argument to --header, the file will be
284 automatically created if it does not exist. See the cryptsetup FAQ
285 for header size calculation.
286
287 The --align-payload option is taken as absolute sector alignment on
288 ciphertext device and can be zero.
289
290 --force-password
291 Do not use password quality checking for new LUKS passwords.
292
293 This option is ignored if cryptsetup is built without password
294 quality checking support.
295
296 For more info about password quality check, see the manual page for
297 pwquality.conf(5) and passwdqc.conf(5).
298
299 --disable-locks
300 Disable lock protection for metadata on disk. This option is valid
301 only for LUKS2 and ignored for other formats.
302
303 WARNING: Do not use this option unless you run cryptsetup in a
304 restricted environment where locking is impossible to perform
305 (where /run directory cannot be used).
306
307 --disable-keyring
308 Do not load volume key in kernel keyring and store it directly in
309 the dm-crypt target instead. This option is supported only for the
310 LUKS2 type.
311
312 --sector-size bytes
313 Set sector size for use with disk encryption. It must be power of
314 two and in range 512 - 4096 bytes. This option is available only
315 with LUKS2 format.
316
317 For LUKS2 devices it’s established based on parameters provided by
318 underlying data device. For native 4K block devices it’s 4096
319 bytes. For 4K/512e (4K physical sector size with 512 bytes
320 emulation) it’s 4096 bytes. For drives reporting only 512 bytes
321 block size it remains 512 bytes. If data device is regular file put
322 in filesystem it’s 4096 bytes.
323
324 Note that if sector size is higher than underlying device hardware
325 sector and there is not integrity protection that uses data
326 journal, using this option can increase risk on incomplete sector
327 writes during a power fail.
328
329 If used together with --integrity option and dm-integrity journal,
330 the atomicity of writes is guaranteed in all cases (but it cost
331 write performance - data has to be written twice).
332
333 Increasing sector size from 512 bytes to 4096 bytes can provide
334 better performance on most of the modern storage devices and also
335 with some hw encryption accelerators.
336
337 --label <LABEL> --subsystem <SUBSYSTEM>
338 Set label and subsystem description for LUKS2 device. The label and
339 subsystem are optional fields and can be later used in udev scripts
340 for triggering user actions once the device marked by these labels
341 is detected.
342
343 --integrity <integrity algorithm>
344 Specify integrity algorithm to be used for authenticated disk
345 encryption in LUKS2.
346
347 WARNING: This extension is EXPERIMENTAL and requires dm-integrity
348 kernel target (available since kernel version 4.12). For native
349 AEAD modes, also enable "User-space interface for AEAD cipher
350 algorithms" in "Cryptographic API" section
351 (CONFIG_CRYPTO_USER_API_AEAD .config option).
352
353 For more info, see AUTHENTICATED DISK ENCRYPTION section in
354 cryptsetup(8).
355
356 --integrity-legacy-padding
357 Use inefficient legacy padding.
358
359 WARNING: Do not use this option until you need compatibility with
360 specific old kernel.
361
362 --luks2-metadata-size <size>
363 This option can be used to enlarge the LUKS2 metadata (JSON) area.
364 The size includes 4096 bytes for binary metadata (usable JSON area
365 is smaller of the binary area). According to LUKS2 specification,
366 only these values are valid: 16, 32, 64, 128, 256, 512, 1024, 2048
367 and 4096 kB The <size> can be specified with unit suffix (for
368 example 128k).
369
370 --luks2-keyslots-size <size>
371 This option can be used to set specific size of the LUKS2 binary
372 keyslot area (key material is encrypted there). The value must be
373 aligned to multiple of 4096 bytes with maximum size 128MB. The
374 <size> can be specified with unit suffix (for example 128k).
375
376 --keyslot-cipher <cipher-spec>
377 This option can be used to set specific cipher encryption for the
378 LUKS2 keyslot area.
379
380 --keyslot-key-size <bits>
381 This option can be used to set specific key size for the LUKS2
382 keyslot area.
383
384 --integrity-no-wipe
385 Skip wiping of device authentication (integrity) tags. If you skip
386 this step, sectors will report invalid integrity tag until an
387 application write to the sector.
388
389 NOTE: Even some writes to the device can fail if the write is not
390 aligned to page size and page-cache initiates read of a sector with
391 invalid integrity tag.
392
393 --batch-mode, -q
394 Suppresses all confirmation questions. Use with care!
395
396 If the --verify-passphrase option is not specified, this option
397 also switches off the passphrase verification.
398
399 --debug or --debug-json
400 Run in debug mode with full diagnostic logs. Debug output lines are
401 always prefixed by #.
402
403 If --debug-json is used, additional LUKS2 JSON data structures are
404 printed.
405
406 --version, -V
407 Show the program version.
408
409 --usage
410 Show short option help.
411
412 --help, -?
413 Show help text and default parameters.
414
416 Report bugs at cryptsetup mailing list <cryptsetup@lists.linux.dev> or
417 in Issues project section
418 <https://gitlab.com/cryptsetup/cryptsetup/-/issues/new>.
419
420 Please attach output of the failed command with --debug option added.
421
423 Cryptsetup FAQ
424 <https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions>
425
426 cryptsetup(8), integritysetup(8) and veritysetup(8)
427
429 Part of cryptsetup project <https://gitlab.com/cryptsetup/cryptsetup/>.
430
431
432
433cryptsetup 2.5.0 2022-07-28 CRYPTSETUP-LUKSFORMAT(8)