]> git.pld-linux.org Git - packages/cryptsetup-luks.git/blame - cryptsetup-luks-initramfs-README
- package python binding (as python-pycryptsetup)
[packages/cryptsetup-luks.git] / cryptsetup-luks-initramfs-README
CommitLineData
b32f9594
JR
11. Introduction
2---------------
3Kernels more recent than 2.6.12 have dropped support for devfs, which
4means that initrd-tools can no longer be used to boot into an encrypted
5root partition. Instead, a similar functionality has been developed for
6use with an initramfs-image.
7
8
92. A fresh installation
10-----------------------
11If you plan to perform a completely new installation of Debian onto a
12machine and to do so using an encrypted root partition, you might want
13to consider using a version of Debian Installer with partman-crypto
14(see http://wiki.debian.org/DebianInstaller/PartmanCrypto).
15
16The installation will then take care of all the details and perform the
17necessary configuration for you, meaning that you should not have to
18read the rest of this document to get a machine with an encrypted
19root fs up and running.
20
21However, if you are not planning to perform a new installation from scratch,
22the following information might be useful to you.
23
24
253. Requirements
26---------------
27In order to boot from an encrypted root fs, you need an initramfs-image
28which includes the necessary kernel modules and scripts to setup
29the root device after the kernel has been initialized, but before the rest
30of the operating system is booted.
31
32To do so, you need two partitions:
33- an unencrypted /boot partition
34- an encrypted / partition
35
36In addition, you need to have initramfs-tools installed.
37
38NOTE: You should make sure that your swap partition is either encrypted, or
39that you are using a swap file on an encrypted partition, as crypto keys and
40other sensitive information might otherwise be written out to the swap
41partition in unencrypted form.
42
43
444. Setup (regular dm-crypt)
45---------------------------
46First of all, you must edit /etc/crypttab and add a line describing your
47root device, for example:
48
49 cryptroot /dev/hda2 none cipher=aes-cbc-essiv:sha256,size=256,hash=sha256
50
51This will allow cryptsetup to create /dev/mapper/cryptroot from the
52encrypted partition /dev/hda2 during boot.
53
54In addition, you must also make sure that the root device is listed in
55/etc/fstab, for example:
56
57 /dev/mapper/cryptroot / ext3 defaults 0 1
58
59This will allow the initramfs support scripts to know which of the devices
60in the crypttab that is the root device.
61
62After doing these changes, you should regenerate the initramfs by running
63"initramfs-update -u", then make sure that your boot loader is configured
64to feed the initramfs to the kernel when booting. The kernel root argument
65should also be changed to /dev/mapper/cryptroot.
66
67Now, reboot the machine, and if everything is correctly configured, you
68should be given a prompt to type in the passphrase for the encrypted
69root partition before the boot can continue.
70
71NOTE: the initramfs scripts default to using the sha256 hash function while
72the plain cryptsetup binary defaults to using the ripemd160 hash function.
73In order to ensure that the crypto setup works in a consistant manner, you
74should make sure that the hash function is specified in the /etc/crypttab file
75if you are using regular dm-crypt (with LUKS the hash function to use is stored
76in the LUKS header).
77
78
795. Setup (using LUKS)
80---------------------
81If you are using the LUKS feature of cryptsetup, the above setup recipe should
82still apply, but since most options can be derived from the information stored
83in the LUKS header on-disk, the line to add to /etc/crypttab should look
84something like this:
85
86 cryptroot /dev/sda2 none luks
87
88
896. Exotic key types
90-------------------
91The above examples assume that you use a regular passphrase as the key to the
92encrypted filesystem. However, if you wish to make use of more complex setups
93(such as root-key-on-usb-memory), you can create a script which does all the
94steps necessary to retrieve the key and then prints it to stdout.
95
96Then add a keyscript=/path/to/your/script.sh to the options (fourth column) in
97the above mentioned /etc/crypttab line, so that it looks something like this:
98
99 cryptroot /dev/sda2 none luks,keyscript=/usr/local/sbin/cryptkey
100
101Next, regenerate your initramfs image. This will copy the script into the
102initramfs image under the /keyscripts/ directory.
103
104NOTE: there is a limited set of tools available when the script is executing
105as part of the initramfs bootup, you have to make sure that you do not use
106any tools which are not available or your script, and therefore boot, will
107fail.
108
109
1107. "cryptopts" boot argument
111----------------------------
112In general, you should use the above approach with a line describing your
113root partition in /etc/crypttab and /etc/fstab. However, if for some reason
114you wish to override the settings that are derived from these files and
115stored in the initramfs image, you can use the "cryptopts" boot argument
116(this *only* works for the root partition).
117
118The format of cryptopts is:
119cryptopts=<opt1>=<value1>,<opt2>=<value2>...
120
121Beside the "hash", "size", "cipher" and "lvm" options that correspond to the
122same options in the fourth field of /etc/crypttab, the options "target",
123"source" and "key" are also supported. They correspond to the first, second
124and third field of /etc/crypttab, respectively. See the crypttab man page
125for further details.
126
127Several "cryptopts" boot arguments can also be specified in case more than
128one mapping needs to be setup in the initramfs stage of the boot.
129
130Example boot arguments:
131root=/dev/mapper/crypt0 cryptopts=target=crypt0,source=/dev/hda1,cipher=twofish
132
1338. Resume device support
134------------------------
135The initramfs scripts will also try to automatically determine the devices,
136if any, that are used for software suspend (swsusp, suspend2 or uswsusp) and
137to set them up during the initramfs stage in order to allow suspend and resume
138in combination with encryption to keep the resume image safe from potential
139attackers.
140
141If your resume device and your root partition use two different cryptsetup
142mappings, you might want to use the "decrypt_derived" keyscript as described
143below.
144
1459. The "decrypt_derived" keyscript
146----------------------------------
147Assume that you have two entries in /etc/crypttab:
148
149cryptroot /dev/hda1 none luks
150cryptswap /dev/hda2 none luks
151
152If cryptswap is used as your suspend/resume device, you'd normally need to
153enter two different passphrases during the boot, but the "decrypt_derived"
154script can generate the key for the second mapping using a hash of the key
155for the first mapping.
156
157In short, you'll need to do something like the following to take advantage
158of the decrypt_derived script:
159
1601) swapoff -a
1612) cryptsetup luksClose cryptswap
1623) edit /etc/crypttab and change the cryptswap line to e.g.:
163cryptswap /dev/hda2 cryptroot cipher=aes-cbc-essiv:sha256,size=256,hash=sha256,keyscript=/lib/cryptsetup/scripts/decrypt_derived,swap
1644) /etc/init.d/cryptdisks start
1655) Make sure that /dev/mapper/cryptswap has been created
1666) swapon -a
1677) (optional) update-initramfs -u
168
169After you've followed the above steps, your swap device should be setup
170automatically after the root device has been setup during the boot stage.
171
172Note: If you don't use suspend device support, it's better to use completely
173random keys for your encrypted swap device. See the section '2. Encrypted
174swap partition(s)' in /usr/share/doc/cryptsetup/README.Debian for information
175on how to setup this.
176
17710. The "passdev" keyscript
178----------------------------
179If you have a keyfile on a removable device (e.g. a USB-key), you can use the
180passdev keyscript. It will wait for the device to appear, mount it read-only,
181read the key and then unmount the device.
182
183The "key" part of /etc/crypttab will be interpreted as <device>:<path>, it is
184strongly recommended that you use one of the persistent device names from
185/dev/disk/*, e.g. /dev/disk/by-label/myusbkey.
186
187This is an example of a suitable line in cryptsetup:
188cryptroot /dev/hda2 /dev/disk/by-label/myusbkey:/keys/root.key cipher=aes-cbc-essiv:sha256,size=256,hash=plain,keyscript=/lib/cryptsetup/scripts/passdev
189
190The above line would cause the boot to pause until /dev/disk/by-label/myusbkey
191appears in the fs, then mount that device and use the file /keys/root.key
192on the device as the key (without any hashing) as the key for the fs.
193
194-- David Härdeman <david@hardeman.nu>
This page took 0.091457 seconds and 4 git commands to generate.