title
stringlengths 1
61
| section
stringlengths 2
92
| content
stringlengths 6
236k
|
---|---|---|
Category:Sandbox/AB | Intro |
# Category:Sandbox/AB
[Help](https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Categories)
From ArchWiki
|
Category:Sandbox/AB | Subcategories |
## Subcategories
This category has only the following subcategory.
### S
* [Sandbox/AB](../../en/Category:Sandbox/AB.html "Category:Sandbox/AB")
[Categories](../../Special:Categories.html "Special:Categories"):
* [Sandbox/A](../../en/Category:Sandbox/A.html "Category:Sandbox/A")
* [Sandbox/AB](../../en/Category:Sandbox/AB.html "Category:Sandbox/AB")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Category:Sandbox/AB&oldid=186804>"
- This page was last edited on 28 February 2012, at 11:14.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
Chrome OS devices/Chromebook | Intro |
# Chrome OS devices/Chromebook
\[ ] 1 language
* [日本語](https://wiki.archlinux.jp/index.php/Chromebook "Chromebook – 日本語")
From ArchWiki
< [Chrome OS devices](../../en/Chrome_OS_devices.html "Chrome OS devices")
Main article: [Chrome OS devices](../../en/Chrome_OS_devices.html "Chrome OS devices").
|
Chrome OS devices/Chromebook | Introduction |
## Introduction
### First generation of Chromebooks
The first generation of Chromebooks: Google Cr-48, Samsung Series 5 500 and Acer AC700 use [Insyde H2O firmware](https://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices/custom-firmware#TOC-H2C) and not Coreboot firmware. There are three approaches how to install Arch Linux on these devices:
* Flash a custom H2C firmware (only available for Google Cr-48) and install Arch as on any other UEFI laptop.
* Take the ChrUbuntu approach which uses the Chrome OS kernel and modules.
* Build and sign your own kernel, see [\[1\]](https://plus.google.com/+OlofJohansson/posts/34PYU79eUqP).
|
Chrome OS devices/Chromebook | Hardware comparisons |
## Hardware comparisons
**Warning:** The availability of SeaBIOS does not promise device compatibility for Linux or that the pre-installed SeaBIOS works properly. Before purchasing a device visit its page on the ArchWiki and look for Linux users' posts about that model.
| Chromebook Models | | | | | | | | | | |
| ----------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | ------------------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | ----------------------------------- | -------------------------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| Available | Brand | Model | Processor | RAM | Storage | Upgradable | Screen | Resolution | SeaBIOS | Remarks |
| Dec 2010 | Google | Cr-48 | Intel Atom N455 | 2GB DDR3 | 16GB SSD | mSATA | 12.1 in (30.7 cm) | 1280x800 (16:10) | Unavailable for 1st generation | [Custom H2C firmware available](https://web.archive.org/web/20180720194838/http://cr-48.wikispaces.com/Flash+BIOS) |
| Jun 2011 | Samsung | Series 5 XE500C21 | Intel Atom N570 | | | mSATA | | | Unavailable for 1st generation | |
| Jul 2011 | Acer | AC700 | | mSATA Mini | | | 11.6 in (29.5 cm) | 1366x768 (16:9) | Unavailable for 1st generation | |
| May 2012 | Samsung | Series 5 XE550C22 | Intel Celeron 867 Intel Core i5 2467M | 4GB DDR3 | | mSATA | 12.1 in (30.7 cm) | 1280x800 (16:10) | In custom firmware only | Custom firmware available |
| Nov 2012 | Acer | [C710](../../en/Chrome_OS_devices.html "Acer C710 Chromebook") | Intel Celeron 847 Intel Celeron 1007U | 2-4GB DDR3 | 320GB HDD 16GB SSD | SATA 2.5" 7,9.5mm | 11.6 in (29.5 cm) | 1366x768 (16:9) | In custom firmware only | Custom firmware available |
| Feb 2013 | HP | Pavilion 14 Chromebook | Intel Celeron 847 | | | SATA 2.5" 7,9.5mm | 14 in (35.6 cm) | | In custom firmware only | Custom firmware available |
| | Lenovo | ThinkPad X131e Chromebook | Intel Celeron 1007U | 4GB DDR3 | 16GB SSD | mSATA | 11.6 in (29.5 cm) | In custom firmware only | | Custom firmware available |
| | Google | Chromebook Pixel | Intel Core i5 3427U | 4GB DDR3 | 32GB iSSD 64GB iSSD | No | 12.85 in (32.6 cm) | 2560x1700 (3:2) | Yes | Custom firmware available |
| Nov 2013 | HP | [Chromebook 14](../../en/HP_Chromebook_14.html "HP Chromebook 14") | Intel Celeron 2955U | 2GB DDR3 4GB DDR3 | 16GB SSD 32GB SSD | 42mm M.2 NGFF | 14 in ( 35.6 cm) | 1366x768 (16:9) | Yes | Custom firmware available |
| | Acer | [C720/C720P Chromebook](../../en/Acer_C720_Chromebook.html "Acer C720 Chromebook") | Intel Celeron 2955U Intel Core i3-4005U | | | 42mm M.2 NGFF | 11.6 in (29.5 cm) | | Yes | Custom firmware available |
| Jan 2014 | Toshiba | CB30/CB35 Chromebook | Intel Celeron 2955U | 2GB DDR3 | 16GB eMMC | No | 13.3 in (33.8 cm) | | Yes | Custom firmware available |
| Apr 2014 | Dell | [Chromebook 11](../../en/Dell_Chromebook_11.html "Dell Chromebook 11") | Intel Celeron 2955U Intel Core i3-4005U | 2GB DDR3 4GB DDR3 | 16GB eMMC | No | 11.6 in (29.5 cm) | | Requires stock SeaBIOS patching | Custom firmware available |
| Jun 2014 | Lenovo | N20/N20P Chromebook | Intel BayTrail-M N2830 | 2GB DDR3 | | No | | Requires writing SeaBIOS | Custom firmware available | |
| | Asus | Chromebook C200/C300 | | 2GB DDR3 4GB DDR3 | 16GB eMMC 32GB eMMC | No | 11.6 in (29.5 cm) 13.3 in (33.8 cm) | Requires writing SeaBIOS | Custom firmware available | |
| | Lenovo | ThinkPad 11e Chromebook | Intel BayTrail-M N2930 | 4GB DDR3 | 16GB eMMC | No | 11.6 in (29.5 cm) | Requires writing SeaBIOS | | Custom firmware available |
| | | ThinkPad Yoga 11e Chromebook | | | | No | | Requires writing SeaBIOS | Custom firmware available | |
| Jul 2014 | HEXA | Chromebook Pi | Intel BayTrail-M N2830 | | 32GB eMMC | No | | No | Custom firmware available | |
| Sep 2014 | Toshiba | CB30/CB35 Chromebook 2 | Intel BayTrail-M N2840 | 2GB DDR3 4GB DDR3 | 16GB eMMC | No | 13.3 in (33.8 cm) | 1366x768 (16:9) 1920x1080 (16:9) | Requires writing SeaBIOS | Custom firmware available |
| | Acer | CB3-111 Chromebook 11 | Intel BayTrail-M N2830 | 2GB DDR3 | | No | 11.6 in (29.5 cm) | 1366x768 (16:9) | Requires writing SeaBIOS | Custom firmware available |
| Oct 2014 | | C730 Chromebook 11 | Intel BayTrail-M N2840 | 2GB DDR3 4GB DDR3 | 16GB eMMC 32GB eMMC | No | | | Requires writing SeaBIOS | Custom firmware available |
| | HP | Chromebook 11 G3 | | | 16GB eMMC | No | Requires writing SeaBIOS | Custom firmware available | | |
| | Samsung | Chromebook 2 XE500C12 | | 2GB DDR3 | | No | Requires writing SeaBIOS | Custom firmware available | | |
| Feb 2015 | Dell | Chromebook 11 3120 | | 2GB DDR3 4GB DDR3 | | No | Requires writing SeaBIOS | Custom firmware available | | |
| | Acer | C740 (EDU) Chromebook 11 | Intel Celeron 3205U Intel Core i3-5005U | | 16GB SSD 32GB SSD | 42mm M.2 NGFF | Requires writing SeaBIOS | Custom firmware available | | |
| | | CB5-571 Chromebook 15 | | 16GB 32GB | 42mm M.2 NGFF | | 15.6 in (39.6 cm) | 1366x768 (16:9) 1920x1080 (16:9) | Requires writing SeaBIOS | Custom firmware available |
| Mar 2015 | | C910 (EDU) Chromebook 15 | Intel Celeron 3205U Intel Core i3-5005U Intel Core i5-5200U | 4GB DDR3 | 16GB SSD 32GB SSD | [42mm M.2 NGFF](https://www.reddit.com/r/chromeos/comments/3asc4f/no_physical_differences_beteen_acer_chromebook/) | | | Requires writing SeaBIOS | Custom firmware available |
| | Google | [Chromebook Pixel 2](../../en/Chromebook_Pixel_2.html "Chromebook Pixel 2") | Intel Core i5-5200U Intel Core i7-5500U | 8GB DDR3 16GB DDR3 | 32GB 64GB | No | 12.85 in (32.6 cm) | 2560x1700 (3:2) | Yes | Custom firmware available |
| | Lenovo | N21 Chromebook | Intel BayTrail-M N2840 | 2GB DDR3 4GB DDR3 | 16GB eMMC | No | 11.6 in (29.5 cm) | 1366x768 (16:9) | Requires writing SeaBIOS | Custom firmware available |
| Jan 2016 | Acer | CB3-131-C8GZ (Chromebook 11) | | 4GB DDR3 | | No | | | Requires writing SeaBIOS | Custom firmware available |
| Jun 2016 | Lenovo | ThinkPad 13 Chromebook (sentry) | Intel Core i5-6300U (Skylake) | 8GB LPDDR3 | 32GB eMMC | No | 13.3 in (33.8 cm) | 1366x768 (16:9) | Requires writing SeaBIOS | Custom firmware available |
| Oct 2017 | Google | Pixelbook | Intel Core i5-7Y57 Intel Core i5-7Y57 Intel Core i7-7Y75 | 8GB DDR3 8GB DDR3 16GB DDR3 | 128GB 256GB 512GB | No | 12.3 in (31.2 cm) | 2400x1600 (3:2) | Yes | Custom firmware available |
| March 2018 | Acer | [Chromebook 11 (C732)](../../en/Acer_Chromebook_11_\(C732\).html "Acer Chromebook 11 (C732)") Astronaut | Intel Celeron N3450 | 4GB LPDDR4 8GB LPDDR4 | 32GB 64GB | No | 11.6 in (29.5 cm) | 1366 x 768 (16:9) | Yes | Custom firmware available |
| March 2020 | Lenovo | [IdeaPad Flex 5 13IML05 Chromebook](../../en/Lenovo_IdeaPad_Flex_5_13IML05_Chromebook.html "Lenovo IdeaPad Flex 5 13IML05 Chromebook") | Intel Celeron 5205U Intel Core i3-10110U Intel Core i5-10210U | 4GB DDR4 8GB DDR4 | 32GB eMMC 64GB eMMC 128GB SSD 256GB SSD | ? | 13.3 in (33.8 cm) | 1920 x 1080 (16:9) | ? | Custom firmware available |
| September 2020 | Lenovo | [IdeaPad Flex 3 CB 11IGL05](../../en/Lenovo_IdeaPad_Flex_3_CB_11IGL05_Chromebook.html "Lenovo IdeaPad Flex 3 CB 11IGL05 Chromebook") | Intel Celeron N4020 | 4GB LPDDR4-2400 8GB LPDDR4-2400 | 32GB eMMC 64GB eMMC 128GB SSD | ? | 11.6 in (29.5 cm) | 1366 x 768 (16:9) | ? | Custom firmware available |
| August 2021 | Acer | Chromebook CX5500 | Intel Core i3-1115G4 Intel Core i5-1135G7 Intel Core i7-1165G7 | 8G LPDDR4 16G LPDDR4X | 128GB SSD 256GB SSD 512GB SSD | ? | 15.6 in (39.6 cm) | 1920 x 1080 (16:9) | ? | |
|
Chrome OS devices/Chromebook | See also |
## See also
* [Gallium OS hardware compatibility](https://wiki.galliumos.org/Hardware_Compatibility) for Chromebooks
[Category](../../Special:Categories.html "Special:Categories"):
* [Chrome OS devices](../../en/Category:Chrome_OS_devices.html "Category:Chrome OS devices")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Chrome_OS_devices/Chromebook&oldid=781242>"
- This page was last edited on 16 June 2023, at 22:18.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
Chrome OS devices/Crostini | Intro |
# Chrome OS devices/Crostini
\[ ] 2 languages
* [日本語](https://wiki.archlinux.jp/index.php/Crostini "Crostini – 日本語")
* [中文(简体)](https://wiki.archlinuxcn.org/wiki/Chrome_OS_devices/Crostini "Chrome OS devices/Crostini – 中文(简体)")
From ArchWiki
< [Chrome OS devices](../../en/Chrome_OS_devices.html "Chrome OS devices")
[Crostini](https://chromium.googlesource.com/chromiumos/docs/+/HEAD/containers_and_vms.md) is Google's umbrella term for making Linux application support easy to use and integrating well with Chrome OS.
This article describes how to install Arch Linux on a Chromebook in a container (via Crostini), without needing to enable developer mode, allowing apps to run alongside other Chrome/Android apps.
Highlights:
* Officially supported, do not need to enable developer mode - leaves Chrome OS secure, no need to flash a BIOS etc.
* Better battery life - battery life of Chrome with the functionality of Linux.
* Audio (in/out) & OpenGL are supported, but USB devices are only partially supported and development is still in progress.
|
Chrome OS devices/Crostini | Introduction |
## Introduction
### Enabling Linux support
Look for Linux under Settings and enable it. This installs a Debian Linux container that we will then replace with an Arch Linux container.
* *Settings > Linux > Enable*
Crostini is still rolling out to Chromebooks. If you do not see an option to enable Linux, you may need to switch to the beta or developer channel, if it has not rolled out to the stable channel for your laptop yet. This can be done via *Settings > About Chrome OS > Channel > Dev/Beta*.
### Replacing the default Debian Linux container with Arch Linux
The below instructions were initially based on <https://www.reddit.com/r/Crostini/wiki/howto/run-arch-linux?v=2d4c6b4c-bbb0-11e8-8f2f-0e740b2a8a8c>.
#### Optional: Delete the Debian container
**Warning:** For the time being of Chrome 87, starting a vmc with a custom lxc image makes Termina think it is invalid and delete it. `lxc delete penguin` should not leave the space unusable. See [\[1\]](https://bugs.chromium.org/p/chromium/issues/detail?id=1146390#c6)
If you have no use for Debian anymore, you can save some storage space by destroying and recreating the Termina VM (this will let you skip renaming / deleting existing container later). Beware this will also delete any other containers you may have under Termina.
**Warning:** Destroying the existing termina may also disable android apps and the play store.
Open the crosh terminal in Chrome (`Ctrl+Alt+t`).
```
vmc destroy termina
vmc start termina
```
#### Create the container
Open a new crosh terminal in Chrome (`Ctrl+Alt+t`). Create an Arch Linux container in Termina using VMC:
```
vmc container termina arch https://us.lxd.images.canonical.com/[dead link 2024-03-03 ⓘ] archlinux/current
```
The following error will be shown after completion:
```
Error: operation `container_create` failed: failed to create container: `UNKNOWN`: requested VM does not exist: termina
ERROR - ERROR: command failed
```
This is expected behaviour, proceed with following steps.
(If this doesn't work, you might be able to succeed with 'lxc launch images:archlinux' instead. It will create the image with a random name to be changed instead of arch later on. substitute arch in the following steps for this generated name.)
Open a shell in Termina and check if the Arch Linux container is present (it may a few minutes to show on the list):
```
vsh termina
lxc list
```
If the container is not started, start it:
```
lxc start arch
```
Launch a bash shell in the container:
```
lxc exec arch -- bash
```
#### Set up the user
The container creates a default user on install based on the email used to sign in to Chrome OS. The username can be seen with the following command:
```
grep 1000:1000 /etc/passwd|cut -d':' -f1
```
Optionally you can rename user/group, by default named by your GMail id:
```
# pkill -9 -u old-username
# groupmod -n new-username old-username
# usermod -d /home/new-username -l new-username -m -c new-username old-username
```
A password needs setting for the user:
```
# passwd username
```
You may additionally want to install [sudo](../../en/Sudo.html "Sudo") and add the user to the wheel group. Use after installation:
```
# visudo
```
Uncomment the following line to allow the wheel group to use sudo:
```
# %wheel ALL=(ALL) ALL
```
Add your user to the wheel group:
```
# usermod -aG wheel username
```
Leave the container:
```
# exit
```
#### Set up the container for use in Chrome OS
Login to the container using regular user account you just configured:
```
lxc console arch
```
Verify networking in the container. The command
```
$ ip -4 a show dev eth0
```
should return a non-empty output with the container's assigned IP address. If it is not empty, you can proceed, otherwise you are facing the issue described in [#No network in container](#No_network_in_container) - follow the instructions listed there to address the issue.
Install the Crostini container tools, Wayland for GUI application support and Xwayland for X11 application support:
[Install](../../en/Help:Reading.html#Installation_of_packages "Install") the [cros-container-guest-tools-git](https://aur.archlinux.org/packages/cros-container-guest-tools-git/)AUR package. Additionally install [wayland](https://archlinux.org/packages/?name=wayland) and [xorg-xwayland](https://archlinux.org/packages/?name=xorg-xwayland) to be able to use GUI tools.
[Start/enable](../../en/Help:Reading.html#Control_of_systemd_units "Start/enable") the following user units:
| Template instance | Purpose |
| ----------------------- | --------------------- |
| `sommelier@0.service` | Wayland |
| `sommelier-x@0.service` | X11 |
| `sommelier@1.service` | Wayland (low density) |
| `sommelier-x@1.service` | X11 (low density) |
Make sure these user services are running successfully by checking their [unit statuses](../../en/Help:Reading.html#Control_of_systemd_units "Unit status"). Now, when apps are installed in Arch Linux, they will automatically appear in the Chrome OS launcher. Exit from the container shell back to the Termina shell by pressing `Ctrl+a` `q`.
#### Replace the default Debian container with Arch Linux
The default Debian container is named penguin. Renaming the "arch" container created above to it will cause Chrome OS to launch Linux apps from the arch container. Stop the Arch Linux container:
```
lxc stop --force arch
```
Stop the Debian container and rename it to "debian" (this step can be skipped if you have already removed the Debian container):
```
lxc stop --force penguin
lxc rename penguin debian
```
Rename the Arch container to "penguin" and start it:
```
lxc rename arch penguin
lxc start penguin
```
Restart the Linux subsystem to apply the changes. After restart, verify that no [failed system or user units](../../en/Systemd.html#Using_units "Systemd") are listed.
The following command should report the IP address assigned for container:
```
ip -4 a show dev eth0
```
|
Chrome OS devices/Crostini | Troubleshooting |
## Troubleshooting
**Tip:** Check the Chromium OS Garcon Bridge (`journalctl --user -u cros-garcon`) for host integration issues, like "Linux files is empty in the Files app" or "Applications do not appear on Chrome OS".
### Arch container fails to start after update to Chrome OS 81
Most of custom containers stopped working with Chrome OS 81 update. The root cause is a LXC version update, as a result, the container fails to start with following error:
```
lxc penguin 20200411193357.312 WARN initutils - initutils.c:setproctitle:324 - Invalid argument - Failed to set cmdline
lxc penguin 20200411193357.395 WARN conf - conf.c:lxc_map_ids:2919 - newuidmap is lacking necessary privileges
lxc penguin 20200411193357.395 WARN conf - conf.c:lxc_map_ids:2925 - newgidmap is lacking necessary privileges
lxc penguin 20200411193357.400 WARN conf - conf.c:lxc_map_ids:2919 - newuidmap is lacking necessary privileges
lxc penguin 20200411193357.400 WARN conf - conf.c:lxc_map_ids:2925 - newgidmap is lacking necessary privileges
lxc penguin 20200411193357.477 ERROR conf - conf.c:run_buffer:335 - Script exited with status 32
lxc penguin 20200411193357.477 ERROR conf - conf.c:lxc_setup:3589 - Failed to run mount hooks
lxc penguin 20200411193357.477 ERROR start - start.c:do_start:1263 - Failed to setup container "penguin"
lxc penguin 20200411193357.478 ERROR sync - sync.c:__sync_wait:62 - An error occurred in another process (expected sequence number 5)
lxc penguin 20200411193357.478 WARN network - network.c:lxc_delete_network_priv:2561 - Failed to rename interface with index 17 from "eth0" to its initial name "veth421fa9d1"
lxc penguin 20200411193357.478 ERROR lxccontainer - lxccontainer.c:wait_on_daemonized_start:842 - Received container state "ABORTING" instead of "RUNNING"
lxc penguin 20200411193357.479 ERROR start - start.c:__lxc_start:1939 - Failed to spawn container "penguin"
lxc penguin 20200411193357.701 WARN conf - conf.c:lxc_map_ids:2919 - newuidmap is lacking necessary privileges
lxc penguin 20200411193357.701 WARN conf - conf.c:lxc_map_ids:2925 - newgidmap is lacking necessary privileges
lxc 20200411193357.706 WARN commands - commands.c:lxc_cmd_rsp_recv:132 - Connection reset by peer - Failed to receive response for command "get_state"
lxc 20200411193357.707 WARN commands - commands.c:lxc_cmd_rsp_recv:132 - Connection reset by peer - Failed to receive response for command "get_state"
```
**Solution**
Navigate to crosh and execute the following commands:
```
vmc start termina
vsh termina
lxc file delete penguin/var/lib/lxc
lxc file delete penguin/var/lib/lxcfs
```
Restart Linux subsystem and container started should start normally.
### No network in container
**The factual accuracy of this article or section is disputed.**
**Reason:** In systemd v249, the problem seems to have disappeared, and everything works as it should. However, in systemd v250, the problem seems to appear again. The above claims regarding v249 and v250 need to be confirmed with more user reports. (Discuss in [Talk:Chrome OS devices/Crostini](../../en/Talk:Chrome_OS_devices/Crostini.html))
As was reported by multiple sources, systemd-networkd and systemd-resolved services in systemd-244.1 are not working properly for unprivileged LXC containers, which ends up in missing network connectivity inside the Crostini container. Users may see only IPv6 address but no IPv4 address for the `arch` container (for example, using `ip a` command).
One possible solution is stated here: [LXD#No IPv4 with systemd-networkd](../../en/LXD.html#No_IPv4_with_systemd-networkd "LXD").
Alternatively, another solution is to completely disable systemd-networkd/systemd-resolved and perform network configuration by [dhclient](../../en/Network_configuration.html#Network_managers "Dhclient") service instead. First, install [dhclient](https://archlinux.org/packages/?name=dhclient), then, as the root user, run:
```
dhcpcd eth0
systemctl disable systemd-networkd
systemctl disable systemd-resolved
unlink /etc/resolv.conf
touch /etc/resolv.conf
systemctl enable dhclient@eth0
systemctl start dhclient@eth0
```
[NetworkManager](../../en/NetworkManager.html "NetworkManager") and [dhcpcd](../../en/Dhcpcd.html "Dhcpcd") also can be used to address the issue if you prefer them over the `dhclient` solution.
### Permission denied with ping
If you get
```
ping: socket: permission denied
```
when trying to ping from a user other than `root`, you need to set the [capability](../../en/Capabilities.html "Capabilities") flag on the `/usr/bin/ping` file to fix it.
```
# setcap cap_net_raw+ep /usr/bin/ping
```
This should solve the problem. See [FS#63710](https://bugs.archlinux.org/task/63710).
### App not opening in chrome OS (infinite spinner)
I found that launching a console (lxc console penguin) session prevents apps from launching in Chrome OS. Launching results in an infinite spinner. In that case, I have to stop and start the container to get the Chrome OS launcher working
```
lxc stop penguin
lxc start penguin
```
Instead of using an lxc console session, I use a regular Linux terminal GUI launched from Chrome OS that prevents this issue.
### Audio playback/input
Crostini support audio playback starting Chrome OS 74. With [cros-container-guest-tools-git](https://aur.archlinux.org/packages/cros-container-guest-tools-git/)AUR installed both ALSA and PulseAudio playback should work after PulseAudio configuration. Audio input is supported starting Chrome OS 79.
Enter the following command in the container (in case you did not):
```
$ cp -rT /etc/skel/.config/pulse ~/.config/pulse
```
It is also possible to use [PipeWire](../../en/PipeWire.html "PipeWire") instead of PulseAudio. Put the following file into `/etc/pipewire/pipewire.conf.d`:
```
/etc/pipewire/pipewire.conf.d/crostini-audio.conf
```
```
context.objects = [
{ factory = adapter
args = {
factory.name = api.alsa.pcm.sink
node.name = "Virtio Soundcard Sink"
media.class = "Audio/Sink"
api.alsa.path = "hw:0,0"
audio.channels = 2
audio.position = "FL,FR"
}
}
{ factory = adapter
args = {
factory.name = api.alsa.pcm.source
node.name = "Virtio Soundcard Source"
media.class = "Audio/Source"
api.alsa.path = "hw:0,0"
audio.channels = 2
audio.position = "FL,FR"
}
}
]
```
### Video playback
[mpv](../../en/Mpv.html "Mpv") can play videos using software rendering without any addition configuration, however this is CPU consuming and laggy experience for modern video codecs like H265. For hardware accelerated playback GPU acceleration is required. Take into account, that GPU acceleration for Crostini is based on [VirGL](https://docs.mesa3d.org/drivers/virgl), so no real GPU device pass-though is performed and hardware-specific APIs like VA-API or VPDAU are not available. However OpenGL acceleration can be used, i.e. this is example of `mpv.conf` which enabled accelerated video and audio playback on Google Pixelbook starting Chrome OS 77:
```
vo=gpu
ao=alsa
```
### GPU acceleration
On Google Pixelbook GPU acceleration works with Arch out-of-the-box starting Chrome OS 77. Also no flags need to be enabled on recent released of Chrome OS:
```
$ glxinfo -B
```
```
name of display: :0
display: :0 screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
Vendor: Red Hat (0x1af4)
Device: virgl (0x1010)
Version: 19.1.4
--> Accelerated: yes <--
Video memory: 0MB
Unified memory: no
Preferred profile: core (0x1)
Max core profile version: 4.3
Max compat profile version: 3.1
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.2
OpenGL vendor string: Red Hat
OpenGL renderer string: virgl
OpenGL core profile version string: 4.3 (Core Profile) Mesa 19.1.4
OpenGL core profile shading language version string: 4.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 3.1 Mesa 19.1.4
OpenGL shading language version string: 1.40
OpenGL context flags: (none)
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 19.1.4
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
```
### Unlock the keyring when starting the container
If you have problems with programs that use [gnome-keyring](https://archlinux.org/packages/?name=gnome-keyring)-daemon, you need to write a user systemd daemon (see [Systemd/User#Writing user units](../../en/Systemd/User.html#Writing_user_units "Systemd/User")) that will run the keyring daemon when the container starts.
Create the following two files:
```
/etc/systemd/user/gnome-keyring.service
```
```
[Unit]
Description=Keyring
[Service]
ExecStart=/usr/local/bin/export-keys
KillUserProcesses=no
[Install]
WantedBy=default.target
```
**Warning:** Leaving the password in plain text is potentially dangerous. You can replace `echo random-password` with `cat ~/.password` by creating the appropriate file in your home folder.
```
/usr/local/bin/export-keys
```
```
#!/bin/bash
killall gnome-keyring-daemon
echo random-password | gnome-keyring-daemon --components=secrets,ssh,pkcs11 --unlock --foreground
```
Give the file launch rights:
```
# chmod a+x /usr/local/bin/export-keys
```
Then, [start/enable](../../en/Help:Reading.html#Control_of_systemd_units "Start/enable") the `gnome-keyring.service` user unit and run
```
$ echo -n login > ~/.local/share/keyrings/default
```
### Fullscreen video, games and mouse capture
Currently Crostini has limited support for mouse capture starting with Chrome OS 79. You must enable the flag chrome://flags/#exo-pointer-lock to get mouse capture. The closed issue relating to mouse capture is <https://bugs.chromium.org/p/chromium/issues/detail?id=927521>.
### "Linux Files" is empty on host
If you find the "Linux Files" directory on host is always empty and see the following logs in the guest Arch Linux, then you might be affected.
```
Feb 24 21:18:23 penguin garcon[183]: [183]: sftp: accepted connection from vsock:2:3162708311
Feb 24 21:18:23 penguin garcon[183]: [183]: Failed to execute requested program in child process: No such file or directory
Feb 24 21:18:23 penguin garcon[183]: [183]: sftp: failed to spawn child process: No child processes (10)
```
Since [2022-06](https://crrev.com/c/3702822), garcon launches the sftp server with `/usr/lib/openssh/sftp-server`, while the [openssh](https://archlinux.org/packages/?name=openssh) package installs the binary at `/usr/lib/ssh/sftp-server`. A workaround is linking the path expected by garcon to the installed one:
```
# mkdir /usr/lib/openssh/
# ln -s /usr/lib/ssh/sftp-server /usr/lib/openssh/sftp-server
```
### Firefox laggy clicking, scrolling & videos
If firefox is exhibiting extremely laggy behavior when clicking on the address bar, scrolling, selecting text etc, and or playing lagged or choppy videos, running firefox with MOZ\_ENABLE\_WAYLAND=1 may resolve this. Inside firefox, about:support should show "Window Protocol" as wayland after this.
```
MOZ_ENABLE_WAYLAND=1 firefox
```
|
Chrome OS devices/Crostini | See also |
## See also
* [Running Custom Containers Under Chrome OS](https://chromium.googlesource.com/chromiumos/docs/+/HEAD/containers_and_vms.md)
* [/r/Crostini](https://www.reddit.com/r/Crostini/)
* [Powerline Web Fonts for Chromebook](https://github.com/wernight/powerline-web-fonts)
[Category](../../Special:Categories.html "Special:Categories"):
* [Chrome OS devices](../../en/Category:Chrome_OS_devices.html "Category:Chrome OS devices")
Hidden categories:
* [Pages with dead links](../../en/Category:Pages_with_dead_links.html "Category:Pages with dead links")
* [Pages or sections flagged with Template:Accuracy](../../en/Category:Pages_or_sections_flagged_with_Template:Accuracy.html "Category:Pages or sections flagged with Template:Accuracy")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Chrome_OS_devices/Crostini&oldid=802718>"
- This page was last edited on 9 March 2024, at 14:38.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
Chrome OS devices/Custom firmware | Intro |
# Chrome OS devices/Custom firmware
\[ ] 1 language
* [日本語](https://wiki.archlinux.jp/index.php/Chrome_OS_%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%A0%E3%83%95%E3%82%A1%E3%83%BC%E3%83%A0%E3%82%A6%E3%82%A7%E3%82%A2 "Chrome OS カスタムファームウェア – 日本語")
From ArchWiki
< [Chrome OS devices](../../en/Chrome_OS_devices.html "Chrome OS devices")
Related articles
* [Chromebook](../../en/Chrome_OS_devices.html "Chromebook")
* [Chromebook Pixel 2](../../en/Chromebook_Pixel_2.html "Chromebook Pixel 2")
**Warning:** This article relies on third-party scripts and modifications, and may irreparably damage your hardware or data.
**This article or section needs language, wiki syntax or style improvements. See [Help:Style](../../en/Help:Style.html "Help:Style") for reference.**
**Reason:** This topic on this page were moved out from the Chromebook page as it was too bloated, hard to navigate and follow, the page here is still needs a little more work to stand by it own and we can probably move out a little more details from the Chromebook page to avoid duplicates, anyone who create hot links in other pages to specific topics in this page should be aware that some topics' headers might be change. (Discuss in [Talk:Chrome OS devices/Custom firmware](../../en/Talk:Chrome_OS_devices/Custom_firmware.html))
|
Chrome OS devices/Custom firmware | Why flash a custom firmware? |
## Why flash a custom firmware?
### Pros
* Allows the use of a [UEFI](../../en/Unified_Extensible_Firmware_Interface.html "UEFI") coreboot payload (with MrChromebox's custom firmware).
* May reduce boot time.
* Removes the Developer Mode screen that some users find annoying.
* Enables VMX in models in which it is not active by default.
* Fixes some issues (like suspend).
### Cons
* Dangerous, and has the potential to render a device unusable.
* Cannot boot stock Chrome OS (you can install [Arnold the Bat’s Chromium OS build](https://arnoldthebat.co.uk/wordpress/chromium-os/) and it should be possible to upgrade it to full blown Chrome OS with a script if the user desires).
* Custom-BIOS specific bugs may occur.
|
Chrome OS devices/Custom firmware | Flashing the custom firmware |
## Flashing the custom firmware
There are several approaches for flashing a custom firmware:
* Use MrChromebox's [Firmware Utility Script](https://mrchromebox.tech/#fwscript).
* Use John Lewis' script.
* Manually with `flashrom`, in this case you will need to obtain the firmware by yourself or to compile it from the coreboot sources ([official](https://doc.coreboot.org/distributions.html) or [Chromium OS fork](https://chromium.googlesource.com/chromiumos/third_party/coreboot/)).
**Note:** With Linux kernel versions greater than 4.4, CONFIG\_IO\_STRICT\_DEVMEM a new kernel security measure can make flashrom stop working, in that case you can try adding `iomem=relaxed` to your kernel parameters. [\[1\]](https://wiki.flashrom.org/FAQ#What_can_I_do_about_.2Fdev.2Fmem_errors.3F)
### Disable the hardware write protection
See the [Disabling the hardware write protection](#Disabling_the_hardware_write_protection) at the [Firmware write protection](#Firmware_write_protection).
### Flashing with MrChromebox's Firmware Utility Script
#### Introduction to the firmware
MrChromebox's firmware for Chromebooks and Chromeboxes has some differences compared to other third-party custom firmware, namely:
* A [UEFI](../../en/Unified_Extensible_Firmware_Interface.html "UEFI") implementation via the Tianocore coreboot payload.
- Updates for the Embedded Controller (EC) of some of the devices it supports, solving some bugs associated with other custom firmware.
* Built based on the latest coreboot upstream, rather than on the frozen source snapshot provided by Google.
- Source code and build scripts available on [github](https://github.com/MrChromebox)
#### Understanding the script
##### What MrChromebox's Firmware Utility Script script does ?
* Automatically downloads statically compiled 64-bit versions of chromium `flashrom`, `cbfstool`, and `gbb_utility`.
* Automatically detects your device/board name, current firmware, and hardware write-protect state
* Provides the option to backup your current firmware on USB (when flashing full/custom UEFI firmware).
* Automatically disables, clears, sets, and enables the software write protection as needed.
* Provides choice between RW\_LEGACY, BOOT\_STUB, and UEFI Full ROM firmware (types available vary based on device).
* Provides the ability to set the stock firmware's GBB flags outside of ChromeOS
* Provides the ability to remove the white Developer Mode splash screen (select models only)
* Writes and verifies the custom firmware.
##### What the script does not do ?
* Does not make you a sandwich.
**Warning:** If you are flashing a custom firmware be prepared to the possibility that you might brick your device and make yourself familiar with the [unbricking methods](#Unbricking_your_Chrome_OS_device).
#### Flashing the firmware
Ensure that your device is supported by looking at the [supported device list](https://mrchromebox.tech/#devices). For some devices there is a legacy SeaBIOS (non-UEFI) firmware also available, although those are [deprecated](https://github.com/MrChromebox/firmware/issues/46) and will generally not receive further updates. Legacy firmware images also do not provide Embedded Controller updates.
If a UEFI ROM for your device is available, you can flash the Full ROM firmware using the [Firmware Utility Script](https://mrchromebox.tech/#fwscript) (after ensuring that you have removed your device's firmware write-protection screw). After successfully flashing the firmware, you can follow the [Installation guide](../../en/Installation_guide.html "Installation guide") and install Arch Linux just like on any UEFI computer. [Systemd-boot](../../en/Systemd-boot.html "Systemd-boot") is the recommended bootloader since it installs itself by default in `esp/EFI/Boot/BOOTX64.EFI`, the path that this firmware tries to boot from by default.
#### Using the script from Arch Linux
You will need to install [dmidecode](https://archlinux.org/packages/?name=dmidecode) and [which](https://archlinux.org/packages/?name=which). Furthermore, to ensure that `flashrom` can correctly flash the firmware it is necessary to boot with both the `nopat` and the `iomem=relaxed` [Kernel parameters](../../en/Kernel_parameters.html "Kernel parameters"). This is due to an [issue](https://wiki.flashrom.org/FAQ#What_can_I_do_about_.2Fdev.2Fmem_errors.3F) with the chromium build of `flashrom` used by the script, which is required since upstream `flashrom` cannot be used to set/clear the software write-protect state or range.
### Flashing with John Lewis' script
**Warning:** Do not run the script before disabling the hardware write protection.
#### Understanding the script
##### What John Lewis' `flash_chromebook_rom.sh` script does ?
* Automatically downloads Chromium OS 64bit version of `flashrom`.
* Backup your current firmware.
* Disables software write protection by running `# ./flashrom --wp-disable`.
* Checks the Chromebook product name with [dmidecode](https://archlinux.org/packages/?name=dmidecode) and download the proper custom firmware.
* Writes the custom firmware.
##### What the script does not do ?
* Does not ask for confirmation.
* Does not check if the hardware write protection is disabled.
* Does not confirm the compatibility of a custom firmware to a specific Chromebook sub-model.
##### Conclusions
* Make sure you disabled the hardware write protection.
* Read the [FAQ](https://johnlewis.ie/custom-chromebook-firmware/faq/).
* [Confirm that your Chromebook model is supported](https://johnlewis.ie/custom-chromebook-firmware/rom-download/), if your model is untested then visit the [coreboot on Chromebooks Google+ community](https://plus.google.com/communities/112479827373921524726) and ask for advice.
**Note:** John Lewis shut down his Google+ community in December 2017; his firmware is presumed to now be unsupported.
**Warning:** If you are flashing a custom firmware be prepared to the possibility that you might brick your device and make yourself familiar with the [unbricking methods](#Unbricking_your_Chrome_OS_device).
#### Running the script in Chrome OS
* Access your command prompt via VT-2 (`Ctrl+Alt+→`)
* Enter the command shown on the [Download ROM page at John Lewis site](https://johnlewis.ie/custom-chromebook-firmware/rom-download/).
**Note:** The reason for not posting here is to force you to visit the site and read the page before proceeding.
* After the script exited copy the backed up firmware to an external storage before rebooting the system.
You should now have a custom firmware installed on your device, cross your fingers and reboot.
If you flashed the firmware as part of the installation process then continue by following [Chrome OS devices#Installing Arch Linux](../../en/Chrome_OS_devices.html#Installing_Arch_Linux "Chrome OS devices"), if the custom firmware boots the installation media correctly then you might want to enable back the hardware write protection.
#### Running the script in Arch Linux
* Install [dmidecode](https://archlinux.org/packages/?name=dmidecode).
* Enter the command shown on the [Download ROM page at John Lewis site](https://johnlewis.ie/custom-chromebook-firmware/rom-download/).
**Note:** The reason for not posting here is to force you to visit the site and read the page before proceeding.
* After the script exited copy the backed up firmware to an external storage before rebooting the system.
You should now have a custom firmware installed on your device, cross you fingers and reboot.
If the custom firmware boots Arch Linux correctly then you might want to enable back the hardware write protection, although [John Lewis states](https://web.archive.org/web/20150421011305/https://blogs.fsfe.org/the_unconventional/2014/09/19/c720-coreboot/) that it is not necessary and will only make upgrading more difficult later. However, if you do not re-enable it you want to be careful not to use flashrom.
### Manually with flashrom
The use of the upstream [flashrom](https://archlinux.org/packages/?name=flashrom) package is discouraged as it is missing operations like `--wp-disable`, `--wp-status` and it will not write firmware successfully to the ROM of the Chromebook unless it already been programmed externally (i.e. flashing by another device over SPI with SOIC clip), this is why it is recommended to use Chromium OS's `flashrom`.
#### Get flashrom for Arch Linux
Download a 64-bit statically linked Chromium OS's `flashrom` version from <https://johnlewis.ie/flashrom> and make it [executable](../../en/Help:Reading.html#Make_executable "Executable").
#### Get flashrom for Chrome OS
Chrome OS already includes `flashrom`.
#### Basic use of flashrom
**Note:** Do not forget that `flashrom`'s location is not in `$PATH`, to execute it you will need to precede the command with `./`, i.e. `./flashrom`.
* Disable software write protection before writing to the firmware chip.
```
# flashrom --wp-disable
```
* Backup firmware from the firmware chip.
```
# flashrom -r old_firmware.bin
```
* Write firmware to the firmware chip.
```
# flashrom -w new_firmware.bin
```
**Tip:** Find your firmware chip by running the command `flashrom -V|grep 'Found' |grep 'flash chip'`
|
Chrome OS devices/Custom firmware | Flashing back stock firmware |
## Flashing back stock firmware
**Note:** The following assumes that your device is not bricked, if it does bricked then jump to [Unbricking your Chrome OS device](#Unbricking_your_Chrome_OS_device)
[Disable the hardware write protection](#Disabling_the_hardware_write_protection) and follow the how to [manually flash firmware with `flashrom`](#Manually_with_flashrom) to flash the backup of your stock firmware.
|
Chrome OS devices/Custom firmware | Unbricking your Chrome OS device |
## Unbricking your Chrome OS device
**Note:** This does not intended to be a thorough guide but just give you a basic understanding of the process of flashing a firmware to a bricked Chromebook. The ArchWiki is not the place for detailed hardware hacking guides so there is no sense in expanding this topic.
### Required tools
* Programmer, both the [Raspberry Pi](https://wiki.flashrom.org/RaspberryPi) and the [Bus Pirate](https://wiki.flashrom.org/Bus_Pirate) are mentioned as compatible devices on the [flashrom wiki](https://wiki.flashrom.org/Flashrom). The [Bus Pirate](https://wiki.flashrom.org/Bus_Pirate) preferable as it will allow you to use Chromium OS's version of `flashrom` that supports `--wp-disable` and `--wp-status` flags.
* SOIC clip is recommended, see [\[2\]](https://wiki.flashrom.org/ISP).
* Female jumper wires.
* If you want to use Chromium OS's `flashrom` another Linux machine (32bit or 64bit) is required.
### General idea on the unbricking process
* Connect the jumper wires to the programmer and the SOIC clip.
* Connect the SOIC clip to the ROM chip.
* If your programmer is running Linux (Raspberry Pi) then modprobe the spi modules.
* If your programmer is not running Linux then connect it to your Linux machine.
* Write the firmware with `flashrom`, you might need to disable software write protection by running `flashrom` with the `--wp-disable` flag (this is why Chromium OS's `flashrom` is handy).
### Recommended reading about unbricking
* Flashrom's wiki pages on [ISP](https://wiki.flashrom.org/ISP), [Bus Pirate](https://wiki.flashrom.org/Bus_Pirate), [Raspberry Pi](https://wiki.flashrom.org/RaspberryPi) and [SOIC8](https://wiki.flashrom.org/Technology#SO8.2FSOIC8:_Small-Outline_Integrated_Circuit.2C_8_pins).
* [coreboot's wiki page on Chromebooks](https://web.archive.org/web/20190203184547/https://www.coreboot.org/Chromebooks).
* Examples of unbricking the C720: [guide](https://www.tnhh.net/posts/unbricking-chromebook-with-beaglebone.html), [pictures](https://drive.google.com/folderview?id=0B9f62MH0umbmRTA2Xzd5WHhjWEU\&usp=sharing).
* Example of unbricking HP Chromebox: [guide](https://pomozok.wordpress.com/2015/01/10/chromebook-vivisection-readingwriting-rom-chip-data/)
|
Chrome OS devices/Custom firmware | Firmware write protection |
## Firmware write protection
**Note:** The information on this topic only intended to give you the basic understanding on the write protection feature in your Chromebook. The ArchWiki is not the place for detailed hardware hacking guides so there is no sense in expanding this topic.
The firmware (coreboot and its payloads) is stored on a SPI flash chip (usually SOIC8), portions of which are protected from writing by a combination of hardware and software measures.
As long as the write protection has not been disabled and the protected range not cleared (set to 0,0), any changes made to the unprotected (RW) parts of the firmware (mainly SeaBIOS) can be reverted via either a booted Chrome OS install or Chrome OS recovery media.
There are two parts to the firmware write protection: hardware and software.
### Hardware write protection
The hardware write protection is an electrical circuit which prevents writing to the software protection special registers; it is normally enforced by the grounding of the !WP pin on the SOIC8 chip. Thus the hardware write protection only protects directly these special registers, but indirectly also the data in the firmware chip.
Early Chromebook models (2012-2013) used a jumper or switch to implement hardware write protection. Most models from 2014-2017 used a screw, and Kabylake/Apollolake (and newer) models from 2017 on use the battery sense line (so disconnecting the battery is necessary to disable the hardware write protect).
### Software write protection
The software write protection is implemented via a special register on the firmware chip, which contain an enabled/disabled flag, as well as one or more ranges of addresses to be protected / marked as read-only.
### Understanding the Process of Disabling the Write Protection
To fully disable the write protection one would need to:
* Disable the hardware write protection of the special software register.
* Change the value of the special software register to disable software write protection, and clear the range of the protected addresses so no data will be protected (start and end at 0).
Conclusion: If one disables the software write protection and does not enable it back, then even if the hardware write protection is re-enabled, the firmware chip will remain unprotected.
#### Disabling the hardware write protection
To find the location of the hardware write-protect screw/switch/jumper and how to disable it visit the ArchWiki page for your Chromebook model (see [Chromebook Models](../../en/Chrome_OS_devices/Chromebook.html "Chrome OS devices/Chromebook")). If there is no information about your device on the ArchWiki then turn to [Developer Information for Chrome OS Devices](https://www.chromium.org/chromium-os/developer-information-for-chrome-os-devices) and [coreboot's Chromebooks page](https://web.archive.org/web/20190203184547/https://www.coreboot.org/Chromebooks).
#### Disabling the software write protection
**Note:** If using MrChromebox's Firmware Utility Script to flash the firmware or set the GBB flags on your device, it is not necessary (nor recommended) to manually disable the software write protection. The Firmware Utility Script will automatically disable/clear/set/enable the software write protection as required.
Chromium OS's `flashrom` can manipulate the software write protection special registers.
* Read the status of the software write protection special registers.
```
# flashrom --wp-status
```
* Disable or enable the software write protection.
```
# flashrom --wp-disable
```
* Change software write protection addresses range.
```
# flashrom --wp-range 0 0
```
For more details on Chromium OS's `flashrom` and how to obtain it, see [#Manually with flashrom](#Manually_with_flashrom).
[Category](../../Special:Categories.html "Special:Categories"):
* [Chrome OS devices](../../en/Category:Chrome_OS_devices.html "Category:Chrome OS devices")
Hidden category:
* [Pages or sections flagged with Template:Style](../../en/Category:Pages_or_sections_flagged_with_Template:Style.html "Category:Pages or sections flagged with Template:Style")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Chrome_OS_devices/Custom_firmware&oldid=785737>"
- This page was last edited on 19 August 2023, at 06:10.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
Compiz/Configuration | Intro |
# Compiz/Configuration
\[ ] 1 language
* [日本語](https://wiki.archlinux.jp/index.php/Compiz_%E8%A8%AD%E5%AE%9A "Compiz 設定 – 日本語")
From ArchWiki
< [Compiz](../../en/Compiz.html "Compiz")
Related articles
* [Compiz](../../en/Compiz.html "Compiz")
* [Window manager](../../en/Window_manager.html "Window manager")
This article details more advanced Compiz configuration. It is assumed that you have successfully installed Compiz and have a basic, working configuration. For information on installation, basic configuration and troubleshooting, please consult the [Compiz](../../en/Compiz.html "Compiz") article.
|
Compiz/Configuration | Settings storage options |
## Settings storage options
### Configuration backends
**Note:**
* Depending on what packages you have installed, not all of the Compiz backends may be available.
* The GConf backend was dropped from Compiz 0.9.12 ([revision 3991](https://bazaar.launchpad.net/~compiz-team/compiz/0.9.12/revision/3991)).
By default, Compiz stores its configuration settings in a plain text file `~/.config/compiz-1/compizconfig/Default.ini`. In CCSM this is known as *Flat-file Configuration Backend*.
Compiz can also store its settings in the GSettings or GConf databases. To change how Compiz saves its settings open CCSM and click on the *Preferences* tab in the left hand column. Then choose your desired backend from the list under *Backend*.
You can also change the backend manually by editing the `~/.config/compiz-1/compizconfig/config` file.
Edit the line below:
```
backend = ini
```
* ini = *Flat File Configuration Backend*
* gsettings = *GSettings Configuration Backend*
* gconf = *GConf Configuration Backend*
Once you have edited and saved the file the change will take place immediately. There is no need to log out.
### Profiles
Profiles allow you to switch between different sets of Compiz settings easily. To create a new profile open CCSM and click on the *Preferences* tab. Under *Profile* click the plus sign to add a new profile or the minus sign to delete one. All changes made in CCSM will be written to your current profile.
Profiles are specific to the backend you are using. For instance, if you are using the GSettings backend then any new profile you create will be a GSettings profile. If you switch to a different backend then your current profile will not work and you will automatically switch to a profile available for that backend.
**Note:** If you see more than one profile named *Default* this is probably because you have used more than one backend e.g. you will have a default profile for ini and a default profile for GSettings or GConf.
|
Compiz/Configuration | Window decoration themes |
## Window decoration themes
### Emerald
**Tip:** For installing Emerald, see [Compiz#Extras](../../en/Compiz.html#Extras "Compiz").
**Note:** Some themes may cause Emerald to crash if they are selected. See [Compiz#Emerald crashes when selecting a theme](../../en/Compiz.html#Emerald_crashes_when_selecting_a_theme "Compiz").
Many Emerald themes are available for download on [compiz-themes.org](https://web.archive.org/web/20190207205010/https://www.compiz-themes.org/browse/cat/117/ord/latest/). Emerald themes can be installed, selected, removed and edited using the *emerald-theme-manager* program. For downloaded themes, unzip the tarball and then install it using the *Import* option in the theme manager.
Emerald themes are store in two locations:
* `/usr/share/emerald/themes` -- system
* `~/.emerald/themes` -- user
The currently selected Emerald theme is copied into the `~/.emerald/theme` directory.
Emerald settings such as window button pulse can be configured in `emerald-theme-manager` and are written to the `~/.emerald/settings.ini` file.
### GTK Window Decorator
**Note:** It is not necessary for Compiz to be using the GConf or GSettings backends in order for Compiz to read Metacity settings stored in the GConf or GSettings databases.
The GTK Window Decorator can be compiled with support for the Metacity or Marco window managers (depending on the Compiz version). If it is compiled with this support, the theme used by Metacity or Marco will also be used by GTK Window Decorator. If GTK Window Decorator is not compiled with Metacity or Marco support, a builtin fallback theme will be used.
Many Metacity themes are available for download on [gnome-look.org](https://www.gnome-look.org/browse/cat/125/ord/latest/). Once downloaded, they should be unpacked into a directory such as `/usr/local/share/themes` (for Metacity) or `~/.themes` (for Marco).
* Compiz 0.9
The GTK Window Decorator provided by Compiz 0.9 can be compiled with Metacity (version 3) support. Assuming this support is compiled in, change the Metacity theme using the commands below:
* In a GNOME Flashback session
Firstly, ensure that the theme type is set to metacity:
```
$ gsettings set org.gnome.metacity.theme type metacity
```
Then the theme can be set with the following command:
```
$ gsettings set org.gnome.metacity.theme name theme-name
```
* In a MATE session
Use the following command:
```
$ gsettings set org.mate.Marco.general theme theme-name
```
* In any other session
Use the following command:
```
$ gsettings set org.gnome.desktop.wm.preferences theme theme-name
```
* Compiz 0.8
The GTK Window Decorator included in the Compiz provided by the Compiz-Reloaded upstream (versions 0.8.10 and higher) can be compiled with Marco support. Assuming this support is compiled in, use the command below to change the Marco theme:
```
$ gsettings set org.mate.Marco.general theme theme-name
```
The GTK Window Decorator included in the Compiz provided by the original Compiz upstream (versions 0.8.9 and below) can be compiled with Metacity (version 2) support. This GTK Window Decorator version expects the theme to be defined as a GConf setting. Assuming this support is compiled in, use the command below to change the Metacity theme:
```
$ gconftool-2 -s /apps/metacity/general/theme -t string theme-name
```
### KDE Window Decorator
Kwin themes can be downloaded, installed and managed using the [KDE](../../en/KDE.html "KDE") *systemsettings* panel.
|
Compiz/Configuration | Workspaces and Viewports |
## Workspaces and Viewports
**Note:** There was once a *Number of Desktops* option under CCSM -> *General Options* -> *Desktop Size* which made it possible to use multiple workspaces along with viewports (though this was incompatible with many Compiz plugins such as *Cube*). As of Compiz 0.9.11 ([revision 3857](https://bazaar.launchpad.net/~compiz-team/compiz/0.9.12/revision/3857)) the *Number of Desktops* option has been removed.
Unlike many other window managers, Compiz does not use multiple workspaces. Instead, it uses one workspace but splits it into multiple sections known as viewports. See [\[1\]](http://www.circuitousroot.com/artifice/programming/useful/fvwm/viewports/index.html) for more information.
The number and layout of viewports can be configured in CCSM -> *General Options* -> *Desktop Size*. Changing the *Horizontal Virtual Size* will change the number of viewports in a row. Changing the *Vertical Virtual Size* will add or remove rows of viewports.
If you are using the *Desktop Cube* plugin, you will not be to use the rows of viewports added by increasing the *Vertical Virtual Size*. To take advantage of multiple rows of viewports, use the *Desktop Wall* plugin instead.
|
Compiz/Configuration | Keyboard shortcuts |
## Keyboard shortcuts
Below is a list of the default keyboard shortcuts for Compiz.
* Switch windows = `Alt+Tab`.
* Switch to next desktops = `Ctrl+Alt+←`.
* Switch to previous desktop = `Ctrl+Alt+→`.
* Move window = `Alt+Left click`.
* Resize window = `Alt+Right click`.
A more detailed list can be found under [CommonKeyboardShortcuts](http://wiki.compiz.org/CommonKeyboardShortcuts) in the Compiz wiki or you can always just look at your plugin's configuration.
Extra shortcuts can be added using the commands plugin in CCSM.
### Edge bindings
Besides mouse and key bindings, Compiz can also assign commands to certain actions involving the screen edges, for example: dragging a window to the screen edge. For instance: the *Rotate Cube* plugin has an option to switch to the next [viewport](#Workspaces_and_Viewports) if a window is dragged to the screen edge. Edge bindings can usually be disabled, through CCSM, by unticking *Edge Flip* options in the plugin's settings section or by disabling actions which have the screen icon next to them in the *Bindings* section of the relevant plugin.
|
Compiz/Configuration | Plugins |
## Plugins
Almost all Compiz functionality is implemented using plugins. Some plugins must be enabled for standard window manager functionality - see [Compiz#Enabling important plugins](../../en/Compiz.html#Enabling_important_plugins "Compiz"). Plugins that provide extra functionality, above and beyond standard window management, are discussed here.
### Grid
If you want to compare two windows side by side by dragging them to the edges of the screen, similar to the "Aero Snap" feature introduced in Windows 7, enable the *Grid* plugin in CCSM. If you are using the *Desktop Wall* or *Rotate Cube* plugin then disable the *Edge Flip* options in that plugin's section to ensure that windows do not move to the next desktop when dragged to the screen edge.
**Tip:**
* The plugin in CCSM labelled *Snapping Windows* merely adds resistance to the edges of the screen. It does not resize windows that are dragged to the screen edge.
* The *Grid* plugin in Compiz 0.8 does not support resizing windows by dragging them to the screen edge. Windows can only be compared by using keyboard shortcuts.
### Scale
The *Scale* plugin provides an option to view scaled thumbnails of all windows in the current viewport, similar to the "Present Windows" feature in [KDE](../../en/KDE.html "KDE") or the "Overview Mode" in [GNOME](../../en/GNOME.html "GNOME") Shell. Once the plugin is enabled, the view can be accessed by moving the mouse cursor into the top right corner of the screen. The active corner can be configured in the *Bindings* tab of the plugin's settings section.
### Widget Layer
The *Widget Layer* plugin allows you to define certain windows as widgets. Widget windows are shown on a separate "layer" of the screen. When the widget layer is hidden, all windows defined as widget windows will be iconified. By default, the widget layer is shown and hidden using `F9` key.
To define a window as a widget, open CCSM and navigate to the *Widget Layer* plugin. Click on the *Behaviour* tab and click on the plus sign button next to the *Widget Windows* field. In the dialog box that appears, choose *Window Title* from the *Type* menu. In the *Value* field enter the title for the window you wish to define as a widget, for example: *galculator*.
### Screen Magnification
There are two Compiz plugins that can provide magnification functionality. The first is *Magnifier* which acts much like a magnifying glass (everything within the rectangular box will be zoomed). The magnifier can be used by enabling the plugin in CCSM and pressing `Super+m`.
The other plugin is called *Enhanced Desktop Zoom*. When this plugin is enabled, pressing the `Super` key and scrolling the middle mouse button will magnify the part of the desktop that is under the mouse cursor.
### Crash handler
It is a good idea to enable the *Crash handler* plugin in CCSM. This plugin ensures that if, for whatever reason, Compiz fails to start with the session or crashes at some point during the session, crash logs will be dumped and an alternative window manager will be started. To specify a window manager that can replace Compiz in the event of a crash, click on the *Crash handler* plugin and tick the *Start Other Window Manager* option. Then, in the *Window Manager Command Line* field, enter a command to start the window manager of choice, for instance: `xfwm4 --replace`.
|
Compiz/Configuration | Compiz configuration without CCSM |
## Compiz configuration without CCSM
Compiz does not have to be configured through CCSM. Settings can be changed by editing the profile directly. For Flat File profiles, this will mean making editing changes to the `~/.config/compiz-1/compizconfig/Default.ini` file or similar. For GSettings or GConf profiles, this will mean making changes to the DConf or GConf databases using the *gsettings* or *gconftool-2* tools.
### Flat-file sample configuration
Features of this sample configuration:
* `Ctrl+Alt+[numpad]` arranges the current window.
* Left and right bottom corner shows taskbar.
* Mouse control for everything (but typing).
* Some effects.
```
[core]
as_active_plugins = core;session;glib;grid;notification;workarounds;place;put;wall;regex;blur;dbus;fs;inotify;widget;animation;resize;text;mousepoll;obs;expo;fade;move;staticswitcher;mag;scale;scaleaddon;
s0_hsize = 2
s0_vsize = 2
[wall]
as_show_switcher = false
s0_edgeflip_dnd = true
as_flip_down_edge =
[expo]
as_reflection = false
as_vp_brightness = 100.000000
as_expo_edge =
as_expo_button = Button9
as_mipmaps = true
as_zoom_time = 0.150000
as_vp_distance = 0.000000
[scale]
as_initiate_edge =
as_initiate_all_button = Button8
s0_darken_back = false
s0_opacity = 100
s0_overlay_icon = 0
s0_multioutput_mode = 1
as_show_desktop = false
s0_hover_time = 100
s0_spacing = 4
s0_timestep = 0.100000
s0_speed = 2.615500
[scaleaddon]
s0_window_highlight = true
s0_highlight_color = #ffffff08
s0_window_title = 0
[mag]
as_zoom_in_button = <TopEdge>Button4
as_zoom_out_button = <TopEdge>Button5
s0_mode = 2
s0_radius = 600
[place]
s0_multioutput_mode = 3
s0_mode = 2
[workarounds]
as_notification_daemon_fix = true
as_firefox_menu_fix = true
as_legacy_fullscreen = true
as_qt_fix = true
as_convert_urgency = true
[move]
as_opacity = 85
[blur]
s0_filter = 1
s0_independent_tex = true
s0_mipmap_lod = 1.700000
s0_gaussian_radius = 7
s0_alpha_blur_match = (any) & !(class=Conky)
[put]
as_put_next_output_button = Button10
s0_speed = 10.441400
s0_timestep = 0.100000
[obs]
s0_opacity_matches = type=dock | Tooltip | Menu | PopupMenu | DropdownMenu;(any) & !(class=Whaawmp.py | class=Gimp | class=Inkscape | class=Xfdesktop | class=Ristretto);
s0_opacity_values = 70;90;
[animation]
s0_close_effects = animation:Dream;animation:Fade;animation:Fade;
s0_open_effects = animation:Magic Lamp;animation:Fade;animation:Fade;
s0_focus_effects = animation:Dodge;
s0_open_durations = 150;100;100;
s0_close_durations = 150;100;100;
s0_minimize_durations = 150;
s0_shade_durations = 150;
s0_focus_durations = 150;
[widget]
s0_bg_brightness = 100
s0_fade_time = 0.250000
s0_match = type=Dock
as_toggle_edge = BottomLeft|BottomRight
s0_end_on_click = false
[staticswitcher]
s0_highlight_mode = 2
s0_highlight_rect_hidden = 2
as_next_key = Disabled
as_next_no_popup_key = <Alt>Tab
as_prev_all_key = Disabled
```
### GSettings configuration
**Note:**
* Most Compiz schemas are *relocatable*. This means that a path needs to provided along with the schema name itself - in this case, the path to the Compiz profile, for example: `:/org/compiz/profiles/Default/plugins/`.
* That a Compiz plugin's schema is installed does not guarantee that the plugin itself is installed.
List all of the available Compiz profiles:
```
$ gsettings list-recursively org.compiz | grep existing-profiles
```
Show the active Compiz profile:
```
$ gsettings list-recursively org.compiz | grep current-profile
```
Set the active Compiz profile:
```
$ gsettings set org.compiz current-profile profile-name
```
List all the available Compiz plugins schemas:
```
$ gsettings list-relocatable-schemas | grep org.compiz
```
View all of the available settings for a Compiz plugin and their values (this example will show the settings of *Static Application Switcher*):
```
$ gsettings list-recursively org.compiz.staticswitcher:/org/compiz/profiles/Default/plugins/staticswitcher/
```
View the value for a specific Compiz setting (this example checks the whether the *Icon* option in *Static Application Switcher* is enabled:
```
$ gsettings get org.compiz.staticswitcher:/org/compiz/profiles/Default/plugins/staticswitcher/ icon
```
Change the value for a Compiz plugin setting (this will disable icons in *Static Application Switcher*):
```
$ gsettings set org.compiz.staticswitcher:/org/compiz/profiles/Default/plugins/staticswitcher/ icon false
```
#### Enabling or disabling a Compiz plugin using GSettings
**Tip:**
* Do not forget to place quotation marks around the array when overwriting the *active-plugins* value, e.g. `"['core']"`.
* If you enter an invalid plugin name or the name of a plugin that is not installed, the command will complete without error but the invalid name will automatically be removed from the array.
Two steps are required. Firstly, get the list of active Compiz plugins using the command below:
```
$ gsettings get org.compiz.core:/org/compiz/profiles/Default/plugins/core/ active-plugins
```
This should return an output similar to the one below:
```
['core', 'composite', 'opengl', 'compiztoolbox', 'decor', 'vpswitch', 'snap', 'mousepoll', 'resize', 'place', 'move', 'wall', 'grid', 'regex', 'imgpng', 'session', 'gnomecompat', 'animation', 'fade', 'workarounds']
```
Copy and paste the output and add it to the command to set the active plugins, adding or removing plugins from the array as appropriate. The example below will enable the *Static Application Switcher:*
```
$ gsettings set org.compiz.core:/org/compiz/profiles/Default/plugins/core/ active-plugins "['core', 'composite', 'opengl', 'compiztoolbox', 'decor', 'vpswitch', 'snap', 'mousepoll', 'resize', 'place', 'move', 'wall', 'grid', 'regex', 'imgpng', 'session', 'gnomecompat', 'animation', 'fade', 'workarounds', 'staticswitcher']"
```
|
Compiz/Configuration | See also |
## See also
* [Compiz Wiki](http://wiki.compiz.org/Decorators/Emerald), (wiki is unmaintained)
* [Compiz-Themes.org](https://web.archive.org/web/20190904143225/https://compiz-themes.org/), including Emerald themes, Metacity themes, Kwin themes and more
[Categories](../../Special:Categories.html "Special:Categories"):
* [Eye candy](../../en/Category:Eye_candy.html "Category:Eye candy")
* [Stacking window managers](../../en/Category:Stacking_window_managers.html "Category:Stacking window managers")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Compiz/Configuration&oldid=691908>"
- This page was last edited on 16 August 2021, at 18:46.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
Conky/Tips and tricks | Intro |
# Conky/Tips and tricks
\[ ] 1 language
* [日本語](https://wiki.archlinux.jp/index.php/Conky/%E3%83%92%E3%83%B3%E3%83%88%E3%81%A8%E3%83%86%E3%82%AF%E3%83%8B%E3%83%83%E3%82%AF "Conky/ヒントとテクニック – 日本語")
From ArchWiki
< [Conky](../../en/Conky.html "Conky")
Related articles
* [Conky](../../en/Conky.html "Conky")
|
Conky/Tips and tricks | Transparency |
## Transparency
Conky supports two different types of transparency. Pseudo-transparency and real transparency that requires a [composite manager](../../en/Xorg.html#Composite "Composite manager") to be installed and running. If you enable real transparency and do not have a composite manager running your conky will not be alpha transparent with transparency enabled for fonts and images as well as the background.
### Pseudo-transparency
Pseudo-transparency is enabled by default in conky. Pseudo-transparency works by copying the background image from the root window and using the relevant section as the background for conky. Some window managers set the background wallpaper to a level above the root window which can cause conky to have a grey background. To fix this issue you need to set it manually. An example with [feh](../../en/Feh.html "Feh") is:
In `~/.xinitrc`:
```
sleep 1 && feh --bg-center ~/background.png &
```
### Enable real transparency
To enable real transparency, you must have a [composite manager](../../en/Xorg.html#Composite "Composite manager") running and the following lines added to `.conkyrc` inside the conky.config array:
```
conky.config = {
own_window = true,
own_window_transparent = true,
own_window_argb_visual = true,
own_window_type = 'desktop',
}
```
If window type "desktop" does not work try changing it to `normal`. If that does not work try the other options: `dock`, `panel`, or `override` instead.
**Note:** [Xfce](../../en/Xfce.html "Xfce") requires enabled compositing, see [\[1\]](https://forum.xfce.org/viewtopic.php?pid=25939).
### Semi-transparency
To achieve semi-transparency in real transparency mode, the following setup must be used in the conky configuration file:
```
conky.config = {
own_window = true,
own_window_transparent = false,
own_window_argb_visual = true,
own_window_argb_value = 90,
own_window_type = 'desktop',
}
```
To reduce the transparency of the conky window, one can increase the value of `own_window_argb_value` towards 255.
|
Conky/Tips and tricks | Display package update information |
## Display package update information
[pacman-contrib](https://archlinux.org/packages/?name=pacman-contrib) provides a script called `checkupdates` which displays package updates from the official repos. Use `${execi 3600 checkupdates | wc -l}` to display the total number of packages.
|
Conky/Tips and tricks | tail text files |
## tail text files
*conky* is able to [conky(1) § tail](https://man.archlinux.org/man/conky.1#tail) files to your desktop, which is mostly useful for text files. Such as reading `/var/log/` files to display all kinds of log messages. Most of these files can only be read by `root`, but running *conky* as `root` is not recommended, so you will need to add yourself to the `log` [user group](../../en/Users_and_groups.html#Group_management "User group"). In addition, since [systemd](../../en/Systemd.html "Systemd") log files are binary files, this feature is less useful then it used to be. However, it could be accomplished using [lua](../../en/Lua.html "Lua") scripts.
|
Conky/Tips and tricks | Display weather forecast |
## Display weather forecast
It is achieved by reading external web pages, usually pages dedicated to weather forecast. See [this thread](https://bbs.archlinux.org/viewtopic.php?id=37381). Another weather script in lua: [here](https://bbs.archlinux.org/viewtopic.php?id=222998)
|
Conky/Tips and tricks | Display a countdown timer |
## Display a countdown timer
[ConkyTimer](https://github.com/orschiro/scriptlets/tree/master/ConkyTimer) is a simple countdown timer that displays the remaining time of a defined task.
Start the timer using `conkytimer "<task description>" <min>`.
|
Conky/Tips and tricks | Display RSS feeds |
## Display RSS feeds
*Conky* has the ability to display RSS feeds natively without the need for an outside script to run and output into Conky. For example, to display the titles of the ten most recent Planet Arch updates and refresh the feed every minute, you would put this into your `conky.conf` in the `TEXT` section:
```
${rss https://planet.archlinux.org/rss20.xml 300 item_titles 10 }
```
If you want to display Arch Forum rss feed, add this line:
```
${rss https://bbs.archlinux.org/extern.php?action=feed&type=rss 300 item_titles 4}
```
where 300 is in seconds the refresh interval (15 minutes is default), 4 the number of items you wish to show.
|
Conky/Tips and tricks | Display a calendar for the current month |
## Display a calendar for the current month
You can use the following lua script to display a calendar. It uses `color1` and the default color from your configuration. It looks best with a monospace font.
```
#!/usr/bin/env lua
conky_color = "${color1}%2d${color}"
t = os.date('*t', os.time())
year, month, currentday = t.year, t.month, t.day
daystart = os.date("*t",os.time{year=year,month=month,day=01}).wday
month_name = os.date("%B")
days_in_month = {
31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31
}
-- check for leap year
-- Any year that is evenly divisible by 4 is a leap year
-- Any year that is evenly divisible by 100 is a leap year if
-- it is also evenly divisible by 400.
LeapYear = function (year)
return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)
end
if LeapYear(year) then
days_in_month[2] = 29
end
title_start = (20 - (string.len(month_name) + 5)) / 2
title = string.rep(" ", math.floor(title_start+0.5)) .. -- add padding to center the title
(" %s %s\n Su Mo Tu We Th Fr Sa\n"):format(month_name, year)
io.write(title)
function seq(a,b)
if a > b then
return
else
return a, seq(a+1,b)
end
end
days = days_in_month[month]
io.write(
string.format(
string.rep(" ", daystart-1) ..
string.rep(" %2d", days), seq(1,days)
):gsub(string.rep(".",21),"%0\n")
:gsub(("%2d"):format(currentday),
(conky_color):format(currentday)
) .. "\n"
)
```
Inside your `conky.conf` you can then place the following, making sure the path matches where you saved the script.
```
conky.text = [[
${execpi 3600 ~/.config/conky/cal.lua}
]]
```
|
Conky/Tips and tricks | Display rTorrent stats |
## Display rTorrent stats
See [this thread](https://bbs.archlinux.org/viewtopic.php?id=67304).
|
Conky/Tips and tricks | Display your WordPress blog stats |
## Display your WordPress blog stats
This can be achieved by using the in python written extension named [ConkyPress](https://evilshit.wordpress.com/2013/04/20/conkypress-a-wordpress-stats-visualization-tool-for-your-desktop/).
|
Conky/Tips and tricks | Display number of new emails |
## Display number of new emails
Conky has built in support for IMAP and POP3, but does not have support for access over ssl. Conky's FAQ recommends using [stunnel](https://archlinux.org/packages/?name=stunnel) for this and has an example configuration [here](https://conky.sourceforge.net/faq.html#Conky's-built-in-IMAP-and-POP3-doesn't-support-SSL-or-TLS/).
Modify `/etc/stunnel/stunnel.conf` as follows, and then [start](../../en/Help:Reading.html#Control_of_systemd_units "Start") `stunnel.service`:
1. Service-level configuration for TLS server
```
[imap]
client = yes
accept = 143
connect = imap.gmail.com:143
protocol = imap
sslVersion = TLSv1
# Service-level configuration for SSL server
[imaps]
client = yes
accept = 993
connect = imap.gmail.com:993
```
Then add the following to `conky.conf`:
```
conky.config = {
imap = "localhost username password [-i 120] [-f 'inbox'] [-p 993]",
}
```
```
conky.text {
Inbox: ${imap_unseen}/${imap_messages}
}
```
### Gmail
If you use 2-factor authentication, you need to use an [App Password](https://myaccount.google.com/apppasswords).
For method 1, 2 and 3:
Create one of the following files in a convenient location (for example in `~/.scripts/`).
Then add the following string to your `conky.conf` in order the check your Gmail account for new email every five minutes (300 seconds) and display:
```
${execi 300 python ~/.scripts/gmail.py}
```
#### method 1
This script uses retrieves the number of new email via Gmail's Atom API.
```
gmail.py
```
```
#!/usr/bin/env python3
import urllib.request
email = 'your email'
password = 'your password'
# Set up authentication for gmail
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='mail.google.com',
uri='https://mail.google.com/',
user=email,
passwd=password)
opener = urllib.request.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib.request.install_opener(opener)
gmailurl = 'https://mail.google.com/gmail/feed/atom'
with urllib.request.urlopen(gmailurl) as page:
contents = page.read().decode('utf-8')
ifrom = contents.index('<fullcount>') + 11
ito = contents.index('</fullcount>')
fullcount = contents[ifrom:ito]
print('{} new emails'.format(fullcount))
```
#### method 2
Same as method 1, but does proper XML parsing.
```
gmail.py
```
```
#!/usr/bin/env python3
import urllib.request
from xml.etree import ElementTree as etree
email = 'your email'
password = 'your password'
# Set up authentication for gmail
auth_handler = urllib.request.HTTPBasicAuthHandler()
auth_handler.add_password(realm='mail.google.com',
uri='https://mail.google.com/',
user=email,
passwd=password)
opener = urllib.request.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib.request.install_opener(opener)
gmailurl = 'https://mail.google.com/gmail/feed/atom'
NS = '{http://purl.org/atom/ns#}'
with urllib.request.urlopen(gmailurl) as source:
tree = etree.parse(source)
fullcount = tree.find(NS + 'fullcount').text
print('{} new emails'.format(fullcount))
```
#### method 3
The same way, but with using `curl`, `grep` and `sed`:
```
gmail.sh
```
```
#!/usr/bin/sh
curl -s -u email:password https://mail.google.com/mail/feed/atom | grep fullcount | sed 's/<[^0-9]*>//g'
```
replace *email* and *password* with your data.
#### IMAP + SSL using Perl
*Conky* has built in support for IMAP accounts but does not support SSL. This can be provided using this script from [this forum post](https://www.unix.com/shell-programming-scripting/115322-perl-conky-gmail-imap-unread-message-count.html). This requires the Perl/CPAN Modules Mail::IMAPClient and IO::Socket::SSL which are in the [perl-mail-imapclient](https://archlinux.org/packages/?name=perl-mail-imapclient) and [perl-io-socket-ssl](https://archlinux.org/packages/?name=perl-io-socket-ssl) packages
Create a file named `imap.pl` in a location to be read by *conky* (for example in `~/.scripts/`). In this file, add (with the appropriate changes):
```
imap.pl
```
```
#!/usr/bin/perl
# by gxmsgx
# description: get the count of unread messages on imap
use strict;
use Mail::IMAPClient;
use IO::Socket::SSL;
my $username = 'example.username';
my $password = 'password123';
my $socket = IO::Socket::SSL->new(
PeerAddr => 'imap.server',
PeerPort => 993
)
or die "socket(): $@";
my $client = Mail::IMAPClient->new(
Socket => $socket,
User => $username,
Password => $password,
)
or die "new(): $@";
if ($client->IsAuthenticated()) {
my $msgct;
$client->select("INBOX");
$msgct = $client->unseen_count||'0';
print "$msgct\n";
}
$client->logout();
```
Add to `conky.conf`:
```
${execi 300 ~/.scripts/imap.pl}
```
or wherever you saved the file.
If you use Gmail you might need to [generate](https://www.google.com/accounts/IssuedAuthSubTokens?hide_authsub=1) an application specific password.
Alternatively, you can use stunnel as shown above: [#Gmail](#Gmail)
#### IMAP using PHP
Another alternative using PHP. PHP needs to be installed and `extension=imap` must be uncommented in `/etc/php/php.ini`.
Then create a file named `imap.php` in a location to be read by *conky* (for example in `~/.scripts/`). Make the file [executable](../../en/Help:Reading.html#Make_executable "Executable").
In this file, add (with the appropriate changes):
```
imap.php
```
```
#!/usr/bin/php
<?php
// See http://php.net/manual/function.imap-open.php for more information about
// the mailbox string in the first parameter of imap_open.
// This example is ready to use with Office 365 Exchange Mails,
// just replace your username (=email address) and the password.
$mbox = imap_open("{outlook.office365.com:993/imap/ssl/novalidate-cert}", "username", "password");
// Total number of emails
$nrTotal = imap_num_msg($mbox);
// Number of unseen emails. There are other ways using imap_status to count
// unseen messages, but they don't work with Office 365 Exchange. This one does.
$unseen = imap_search($mbox, 'UNSEEN');
$nrUnseen = $unseen ? count($unseen) : 0;
// Display the result, format as you like.
echo $nrUnseen.'/'.$nrTotal;
// Not needed, because the connection is closed after the script end.
// For the sake of clean public available scripts, we are nice to
// the imap server and close the connection manually.
imap_close($mbox);
```
Add to `conky.conf`:
```
${execi 300 ~/.scripts/imap.php}
```
or wherever you saved the file.
This script displays A/B where A is the number of unseen emails and B is the total number of mails in the mailbox. There are a lot of other information available through a lot of PHP functions like with imap\_Status (<https://php.net/manual/function.imap-status.php>). Just see the PHP docs about IMAP: <https://php.net/manual/ref.imap.php>.
|
Conky/Tips and tricks | Show graphic of active network interface |
## Show graphic of active network interface
To test if a network inferface is currently active, you can use the test conky variable `if_existing` on the `operstate` of the interface. Here is an example for wlo1 :
```
draw_graph_borders yes
${if_existing /sys/class/net/wlo1/operstate up}
${color #0077ff}Net Down:$color ${downspeed wlo1} ${color #0077ff}Net Up:$color ${upspeed wlo1}
${color #0077ff}${downspeedgraph wlo1 32,155 104E8B 0077ff} $alignr${color #0077ff}${upspeedgraph wlo1 32,155 104E8B 0077ff}
${endif}
```
This is the expected result :
<https://i.imgur.com/pQQbsP6.png>
|
Conky/Tips and tricks | User-contributed configuration examples |
## User-contributed configuration examples
* A sample rings script with nvidia support - [gist](https://gist.github.com/anonymous/85d052c0c23e58bc3666)
[Category](../../Special:Categories.html "Special:Categories"):
* [System monitors](../../en/Category:System_monitors.html "Category:System monitors")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Conky/Tips_and_tricks&oldid=808777>"
- This page was last edited on 19 May 2024, at 20:40.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
Debugging/Getting traces | Intro |
# Debugging/Getting traces
\[ ] 4 languages
* [日本語](https://wiki.archlinux.jp/index.php/%E3%83%87%E3%83%90%E3%83%83%E3%82%B0/%E3%83%88%E3%83%AC%E3%83%BC%E3%82%B9%E3%82%92%E5%8F%96%E5%BE%97 "デバッグ/トレースを取得 – 日本語")
* [Português](../../pt/Debug_-_Getting_Traces.html "Debug - Getting Traces – português")
* [Русский](../../ru/Debugging/Getting_traces.html "Debugging (Русский)/Getting traces – русский")
* [中文(简体)](https://wiki.archlinuxcn.org/wiki/Debugging/Getting_traces "Debugging/Getting traces – 中文(简体)")
From ArchWiki
< [Debugging](../../en/Debugging.html "Debugging")
Related articles
* [General troubleshooting](../../en/General_troubleshooting.html "General troubleshooting")
* [Reporting bug guidelines](../../en/Bug_reporting_guidelines.html "Reporting bug guidelines")
* [Debuginfod](../../en/Debuginfod.html "Debuginfod")
* [Core dump](../../en/Core_dump.html "Core dump")
This article aims to help debugging software by providing traces and debug information. This information can then be used for the bug report to the (upstream) software developers or package maintainers.
|
Debugging/Getting traces | Introduction |
## Introduction
Usually, executable files are stripped of human readable context to make them smaller. Obtaining traces without debugging information available drastically reduces their usefulness. For example, a trace from a [gdb](https://archlinux.org/packages/?name=gdb) session where debugging information is not available may look as follows:
```
[...]
Backtrace was generated from '/usr/bin/epiphany'
(no debugging symbols found)
Using host libthread_db library "/lib/libthread_db.so.1".
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
[New Thread -1241265952 (LWP 12630)]
(no debugging symbols found)
0xb7f25410 in __kernel_vsyscall ()
#0 0xb7f25410 in __kernel_vsyscall ()
#1 0xb741b45b in ?? () from /lib/libpthread.so.0
[...]
```
`??` shows where debugging info is missing, as well as the name of library or executable which called the function. Similarly, when `(no debugging symbols found)` appears, you should look for the stated file names.
To obtain a proper trace that is useful to the program developers, follow the next sections. Separate debug files are available for most official Arch packages and can be downloaded with [Debuginfod](../../en/Debuginfod.html "Debuginfod") (see [#Getting the trace](#Getting_the_trace)). When enhanced debugging information was not added to the executable in the first place, one has to [rebuild the package](#Rebuilding_packages) with debugging symbols enabled.
Use the complete stack trace to inform developers of a bug you have discovered before. This will be highly appreciated by them and will help to improve your favorite program.
|
Debugging/Getting traces | Getting the trace |
## Getting the trace
The actual backtrace (or stack trace) can be obtained via [gdb](https://archlinux.org/packages/?name=gdb), the GNU Debugger. It can be used in several ways, depending on whether it should start a new instance of a program, attach to an existing process, or examine a previous crash.
### Starting a new instance of a program
Start *gdb* with an executable program that can be found in `$PATH` (or a full path):
```
$ gdb application
```
*gdb* automatically tries to download debug information and symbols for packages in the [official repositories](../../en/Official_repositories.html "Official repositories"). When *gdb* asks whether [Debuginfod](../../en/Debuginfod.html "Debuginfod") should be enabled in the debugging session, answer `y`:
```
This GDB supports auto-downloading debuginfo from the following URLs:
<https://debuginfod.archlinux.org>
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Downloading separate debug info for /usr/bin/application
Reading symbols from /home/user/.cache/debuginfod_client/fbaee841e2ed2c11ecbbda26f39eeec1da23d6c3/debuginfo...
```
Then, within *gdb*, type `run` followed by any arguments you wish the program to start with:
```
(gdb) run arguments
```
**Tip:** Alternatively, you can pass arguments when starting *gdb* using `gdb --args application arguments...` and then use only `run` without arguments within *gdb*. For example, to debug an application written in Python, run `gdb --args /usr/bin/python /path/to/application`.
Now do whatever is necessary to evoke the bug. *gdb* will automatically halt the application when it crashes and prompt for commands. In case of freezes or similar issues, press `Ctrl+c` and you will be returned to the command prompt, too.
Then enable logging to a file:
```
(gdb) set logging enabled on
```
**Tip:** The default file name is `gdb.txt`. An alternate file name can be specified with `set logging file trace.log` within *gdb*.
And finally have the backtrace written to the specified file in the current working directory:
```
(gdb) thread apply all backtrace full
```
### Attaching to an existing process
If the program you want to debug is already running, you need to first find its process ID. Tools such as [pidof(1)](https://man.archlinux.org/man/pidof.1) or [pgrep(1)](https://man.archlinux.org/man/pgrep.1) are available. For example:
```
pidof python3
```
```
907171 491909
```
When the output does not give a unique ID, you can try more filtering or look at the output of `ps aux` or `pstree --show-pids`.
Attaching as regular user does not work by default due to restricted [ptrace scope](../../en/Security.html#ptrace_scope "Security"). The restriction can be lowered temporarily with `echo 0 > /proc/sys/kernel/yama/ptrace_scope` or you can run *gdb* as a privileged user, e.g. using [sudo](../../en/Sudo.html "Sudo").
Start *gdb* attaching it to the process:
```
$ gdb --pid=PID
```
*gdb* will ask if [Debuginfod](../../en/Debuginfod.html "Debuginfod") should be enabled in this debugging session, to which you should answer `y`.
Note that attaching to a process has stopped it and it needs to be explicitly continued. This replaces the `run` command from the workflow in the [#Starting a new instance of a program](#Starting_a_new_instance_of_a_program) section:
```
(gdb) continue
```
Now do whatever is necessary to evoke the bug in the attached process. Then proceed with enabling logging and obtaining the trace same as in [#Starting a new instance of a program](#Starting_a_new_instance_of_a_program).
### Examining a previous crash
To debug an application that has already crashed, you will want to invoke *gdb* on its *core dump*. See [Core dump#Analyzing a core dump](../../en/Core_dump.html#Analyzing_a_core_dump "Core dump") for details.
If debugging information for the crashed program is not available and a proper backtrace was not obtained, you may need to [rebuild the package](#Rebuilding_packages) and reproduce the crash again.
|
Debugging/Getting traces | Manually getting debug info |
## Manually getting debug info
**This article or section is out of date.**
**Reason:** In the [Debuginfod](../../en/Debuginfod.html "Debuginfod") era, installing separate debug packages with pacman is not needed for official packages. (Discuss in [Talk:Debugging/Getting traces](../../en/Talk:Debugging/Getting_traces.html))
The first thing to do is to obtain the names of the packages which [require rebuilding](#Rebuilding_packages) or the [install of a debug package](#Installing_debug_packages).
```
[...]
Backtrace was generated from '/usr/bin/epiphany'
(no debugging symbols found)
Using host libthread_db library "/lib/libthread_db.so.1".
(no debugging symbols found)
[...]
```
For example for the above extract from a trace, the package name for the associated package can be obtained with [pacman](../../en/Pacman.html "Pacman"):
```
$ pacman -Qo /lib/libthread_db.so.1
```
```
/lib/libthread_db.so.1 is owned by glibc 2.5-8
```
The package is called [glibc](https://archlinux.org/packages/?name=glibc) in version 2.5-8. Repeat this step for every package that needs debugging information.
### Installing debug packages
**This article or section needs expansion.**
**Reason:** Explain the different scenarios properly. Either you install a debug package or you let [debuginfod](../../en/Debuginfod.html "Debuginfod") fetch the things it needs? (Discuss in [Talk:Debugging/Getting traces](../../en/Talk:Debugging/Getting_traces.html))
**Note:** Debug packages are not archived by Arch Linux on [Arch Linux Archive](../../en/Arch_Linux_Archive.html "Arch Linux Archive").
A few mirrors currently distribute debug packages in accessible repositories. These are sponsored mirrors controlled by Arch Linux and are given access to the debug repositories.
* <https://geo.mirror.pkgbuild.com> (GeoDNS mirror)
To install a package you can install it directly from the repository. For example:
```
# pacman -U https://geo.mirror.pkgbuild.com/core-debug/os/x86_64/zstd-debug-1.5.2-2-x86_64.pkg.tar.zst
```
**Warning:** Debug packages from one [mirror](../../en/Mirrors.html "Mirror") are not compatible with regular packages from another mirror, if both mirrors are not in sync, and thus have mismatching builds. In this case, avoid mixing packages from different mirrors (this would result in a [partial upgrade](../../en/System_maintenance.html#Partial_upgrades_are_unsupported "Partial upgrade")), but point all repositories to the `debug` mirror.
**This article or section is a candidate for merging with [Official repositories](../../en/Official_repositories.html "Official repositories").**
**Notes:** Official repositories have a dedicated page (Discuss in [Talk:Debugging/Getting traces#mirrors distributing debug packages.](../../en/Talk:Debugging/Getting_traces.html#mirrors_distributing_debug_packages. "Talk:Debugging/Getting traces"))
Another option is to add the repositories to your pacman configuration.
```
/etc/pacman.conf
```
```
# Testing Repositories
[core-testing-debug]
Include = /etc/pacman.d/mirrorlist
[extra-testing-debug]
Include = /etc/pacman.d/mirrorlist
[multilib-testing-debug]
Include = /etc/pacman.d/mirrorlist
# Stable repositories
[core-debug]
Include = /etc/pacman.d/mirrorlist
[extra-debug]
Include = /etc/pacman.d/mirrorlist
[multilib-debug]
Include = /etc/pacman.d/mirrorlist
```
Place a mirror with debug packages as the first one in the mirrorlist file:
```
/etc/pacman.d/mirrorlist
```
```
Server = https://geo.mirror.pkgbuild.com/$repo/os/$arch
...
```
### Rebuilding packages
If debug information is not exposed through *debuginfod* (for example, when the package originates from the [AUR](../../en/Arch_User_Repository.html "AUR")), then it can be rebuilt from source. See [ABS](../../en/Arch_build_system.html "ABS") for packages in the [official repositories](../../en/Official_repositories.html "Official repositories"), or [AUR#Acquire build files](../../en/Arch_User_Repository.html#Acquire_build_files "AUR") for packages in the [AUR](../../en/Arch_User_Repository.html "AUR").
To set the required [#Compilation options](#Compilation_options), you can modify the [makepkg configuration](../../en/Makepkg.html#Configuration "Makepkg") if you will only use *makepkg* for debug purposes. In other cases, you should modify package's `PKGBUILD` file only for each package you would like to rebuild.
#### Compilation options
As of pacman 4.1, [makepkg.conf(5)](https://man.archlinux.org/man/makepkg.conf.5) has debug compilation flags in `DEBUG_CFLAGS` and `DEBUG_CXXFLAGS`. To use them, enable the `debug` *makepkg* option, and disable `strip`.
These settings will force compilation with debug symbols and will disable their stripping from executables.
```
/etc/makepkg.conf
```
```
OPTIONS+=(debug !strip)
```
To apply this setting to a single package, modify the `PKGBUILD`:
```
PKGBUILD
```
```
options=(debug !strip)
```
Alternatively you can put the debug information in a separate package by enabling both `debug` and `strip`, debug symbols will then be stripped from the main package and placed, together with source files to aid in stepping through the debugger, in a separate `pkgbase-debug` package. This is advantageous if the package contains very large binaries (e.g. over a GB with debug symbols included) as it might cause freezing and other strange, unwanted behavior occurring.
**Note:** It is insufficient to simply install the newly compiled debug package, because the debugger will check that the file containing the debug symbols is from the same build as the associated library and executable. You must install both of the recompiled packages. In Arch, the debug symbol files are installed under `/usr/lib/debug/`, and source files are installed under `/usr/src/debug`. See the [GDB documentation](https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html) for more information about debug packages.
##### glibc
Certain packages such as *glibc* are stripped regardless. Check the `PKGBUILD` for sections such as:
```
strip $STRIP_BINARIES usr/bin/{gencat,getconf,getent,iconv,iconvconfig} \
usr/bin/{ldconfig,locale,localedef,makedb} \
usr/bin/{pcprofiledump,pldd,rpcgen,sln,sprof} \
usr/lib/getconf/*
strip $STRIP_STATIC usr/lib/*.a
strip $STRIP_SHARED usr/lib/{libanl,libBrokenLocale,libcidn,libcrypt}-*.so \
usr/lib/libnss_{compat,db,dns,files,hesiod,nis,nisplus}-*.so \
usr/lib/{libdl,libm,libnsl,libresolv,librt,libutil}-*.so \
usr/lib/{libmemusage,libpcprofile,libSegFault}.so \
usr/lib/{audit,gconv}/*.so
```
And remove them where appropriate.
##### Clang
**This article or section is out of date.**
**Reason:** The package that served as a reference is no longer in the repositories, do we have a more recent example? (Discuss in [Talk:Debugging/Getting traces](../../en/Talk:Debugging/Getting_traces.html))
Packages using [Clang](../../en/Clang.html "Clang") as the compiler will not build with the `debug` option due to the debug flag `-fvar-tracking-assignments'` not being handled (e.g. the previous [js78 PKGBUILD](https://gitlab.archlinux.org/archlinux/packaging/packages/js78/-/blob/main/PKGBUILD)).
Add the following at the top of the `build()` function to only remove the flag for the affected package:
```
build() {
CFLAGS=${CFLAGS/-fvar-tracking-assignments}
CXXFLAGS=${CXXFLAGS/-fvar-tracking-assignments}
[...]
```
##### LTO
Using [Link-time optimization (LTO)](https://en.wikipedia.org/wiki/Interprocedural_optimization#WPO_and_LTO "w:Interprocedural optimization") will, both during compiling and in a debugger, use more memory[\[1\]](https://pp.ipd.kit.edu/uploads/publikationen/weinreuter16bachelorarbeit.pdf#section.4.3)[\[2\]](https://sourceware.org/bugzilla/show_bug.cgi?id=23710). Depending on the application, especially if it is a large one like Firefox or Qt, it might exceed the available memory. Build the application without LTO if this happens.
All packages in the official repositories are generally built with LTO.
#### Building and installing the package
Build the package from source using `makepkg` while in the `PKGBUILD`'s directory. This could take some time:
```
$ makepkg
```
Then install the built package:
```
# pacman -U glibc-2.26-1-x86_64.pkg.tar.gz
```
|
Debugging/Getting traces | See also |
## See also
* [Debian:HowToGetABacktrace](https://wiki.debian.org/HowToGetABacktrace "debian:HowToGetABacktrace")
* [Gentoo:Project:Quality Assurance/Backtraces](https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces "gentoo:Project:Quality Assurance/Backtraces")
* [Fedora:StackTraces](https://fedoraproject.org/wiki/StackTraces "fedora:StackTraces")
* [GNOME - Getting Stack Traces](https://wiki.gnome.org/GettingInTouch/Bugzilla/GettingTraces/Details#Obtaining_a_stack_trace_.28the_easy_way.29)
* [gdb mini intro](https://linux.bytesex.org/gdb.html)
[Categories](../../Special:Categories.html "Special:Categories"):
* [Package development](../../en/Category:Package_development.html "Category:Package development")
* [Development](../../en/Category:Development.html "Category:Development")
Hidden categories:
* [Pages or sections flagged with Template:Out of date](../../en/Category:Pages_or_sections_flagged_with_Template:Out_of_date.html "Category:Pages or sections flagged with Template:Out of date")
* [Pages or sections flagged with Template:Expansion](../../en/Category:Pages_or_sections_flagged_with_Template:Expansion.html "Category:Pages or sections flagged with Template:Expansion")
* [Pages or sections flagged with Template:Merge](../../en/Category:Pages_or_sections_flagged_with_Template:Merge.html "Category:Pages or sections flagged with Template:Merge")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Debugging/Getting_traces&oldid=802913>"
- This page was last edited on 10 March 2024, at 22:37.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
Dell XPS M1330 / M1530 | Intro |
# Dell XPS M1330 / M1530
From ArchWiki
< [Dell XPS M1330](../../en/Dell_XPS_M1330_/_M1530.html "Dell XPS M1330")
**This article or section does not follow the [Laptop page guidelines](../../en/Help:Laptop_page_guidelines.html "Help:Laptop page guidelines").**
**Reason:** Stub (Discuss in [Talk:Dell XPS M1330 / M1530](../../en/Talk:Dell_XPS_M1330_/_M1530.html))
Dell XPS M1330 and the larger M1530 are laptops sold from 2007 to 2009. They work quite well out of the box with Arch and GNU/Linux in general.
**Note:** This article on pre-2010 hardware was almost completely rewritten in January 2021.
|
Dell XPS M1330 / M1530 | CPU |
## CPU
The CPU is either Intel Merom or Penryn. Despite their age, they are both x86\_64 and thus supported by Arch. Remember to install [intel-ucode](https://archlinux.org/packages/?name=intel-ucode) for full stability.
|
Dell XPS M1330 / M1530 | BIOS |
## BIOS
The last BIOS revision for this product was A15. You can see which version is in use on the startup screen. The best way to update to the last version is through Windows Update (on a still-supported version of Windows).
Alternatively, the BIOS can be updated in Arch using [FreeDOS](../../en/Flashing_BIOS_from_Linux.html#FreeDOS "Flashing BIOS from Linux"). Download the Dell image (M1330A15.EXE or M1530\_A12.EXE) and follow the instructions given [here](https://www.dell.com/support/kbdoc/en-is/000131486/update-the-dell-bios-in-a-linux-or-ubuntu-environment).
|
Dell XPS M1330 / M1530 | Network |
## Network
### Ethernet
The ethernet interface is made by Broadcom. The `tg3` kernel module should load automatically. To use it, install and enable your preferred network manager (see [Network configuration](../../en/Network_configuration.html "Network configuration")).
### Wireless
Make sure the wireless interfaces are [unblocked](../../en/Network_configuration/Wireless.html#Rfkill_caveat "Network configuration/Wireless").
Wi-Fi and/or Bluetooth can be turned on/off with a hardware switch located on the right-hand side of the laptop. The functionality can be changed in the BIOS settings.
**Warning:** Some users have reported problems with the wireless devices after migrating from Windows, leaving either/both of them permanently unusable! To avoid this, turn the hardware switch to 'on' and set it to control both Wi-Fi and Bluetooth in BIOS. Then boot into Windows one last time. If the devices are not working in Windows either, a Dell patch (R159805.EXE) may be of help.
#### Wi-Fi
See [Wireless network configuration](../../en/Network_configuration/Wireless.html "Wireless network configuration") for details.
M1330 and M1530 were shipped with many different Wi-Fi chipsets. Check which one you have with `lspci -k`.
* **Intel chipset: 3945abg or 4965agn**
The correct kernel module should load automatically.
* **Broadcom chipset: bcm43*xx***
You may try installing the [broadcom-wl](../../en/Broadcom_wireless.html#broadcom-wl "Broadcom wireless") driver first. The `wl` module should load on boot.
If this fails, your only option is to use the [b43](../../en/Broadcom_wireless.html#b43 "B43") driver and associated firmware. The `ssb` module loads automatically but the `b43` module needs to be enabled manually. Performance will not be great.
#### Bluetooth
Some units include a Bluetooth card. The correct kernel module should load automatically. To use it, install the [bluez](https://archlinux.org/packages/?name=bluez) package (if not already present) along with additional packages mentioned in relevant articles. Then enable `bluetooth.service`.
|
Dell XPS M1330 / M1530 | Graphics |
## Graphics
Most units were shipped with an Nvidia 8400M-GS card (G86M). It is no longer properly supported by the proprietary NVIDIA driver. You have two options:
* Use kernel mode setting (works out of the box)
- Install [xf86-video-nouveau](https://archlinux.org/packages/?name=xf86-video-nouveau) (small improvement)
Performance will not be great. Expect frequent freezes under moderate loads.
|
Dell XPS M1330 / M1530 | Sound |
## Sound
Sound works very well with [PulseAudio](../../en/PulseAudio.html "PulseAudio"). Simply install the necessary packages if not already present.
If you prefer pure [ALSA](../../en/Advanced_Linux_Sound_Architecture.html "ALSA"), be sure to unmute all channels. To get the microphone working, you may have to change the digital input source.
**Note:** You may have to manually switch between speaker and headphone output in your desktop environment. This is not a hardware/driver problem
|
Dell XPS M1330 / M1530 | Touchpad |
## Touchpad
The Synaptics-made touchpad works well with [libinput](../../en/Libinput.html "Libinput") which is included with most desktop environments.
|
Dell XPS M1330 / M1530 | Extra media keys |
## Extra media keys
The media buttons are detected automatically by [udev](../../en/Udev.html "Udev"). The *MediaDirect* (house) button can be reassigned for any purpose.
|
Dell XPS M1330 / M1530 | Fingerprint reader |
## Fingerprint reader
Some units include a fingerprint reader made by SGS Thomson Microelectronics. It should work with the generic [fprint](../../en/Fprint.html "Fprint") driver. If not try the manufacturer-supplied [ThinkFinger](../../en/ThinkFinger.html "ThinkFinger") driver.
|
Dell XPS M1330 / M1530 | SD Card Reader |
## SD Card Reader
The device is recognized by the kernel. The adapter module is `sdhci`.
The card will be available for mounting under the device `/dev/mmcblk0p1`
|
Dell XPS M1330 / M1530 | Webcam |
## Webcam
See [Webcam setup](../../en/Webcam_setup.html "Webcam setup") for details.
Most units are equipped with a webcam, If it is not working, run the built-in diagnostics (available by pushing 'F12' during the POST screen, then selecting 'Diagnostics').
|
Dell XPS M1330 / M1530 | Sensors / Hardware info |
## Sensors / Hardware info
Install i8k packages: [i8kutils](https://aur.archlinux.org/packages/i8kutils/)AUR.
This will provide many useful information (temperature, fan speed, BIOS...) and utilities (fan monitor, BIOS update...). For CPU temps, use [lm\_sensors](../../en/Lm_sensors.html "Lm sensors").
|
Dell XPS M1330 / M1530 | Hard Drive |
## Hard Drive
If the hard drive clicks regularly, it may be suffering from [this problem](https://bbs.archlinux.org/viewtopic.php?id=39258).
[Category](../../Special:Categories.html "Special:Categories"):
* [Dell](../../en/Category:Dell.html "Category:Dell")
Hidden category:
* [Pages or sections flagged with Template:Laptop style](../../en/Category:Pages_or_sections_flagged_with_Template:Laptop_style.html "Category:Pages or sections flagged with Template:Laptop style")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Dell_XPS_M1330_/_M1530&oldid=749192>"
- This page was last edited on 28 September 2022, at 10:58.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
dm-crypt/Device encryption | Intro |
# dm-crypt/Device encryption
\[ ] 5 languages
* [Español](../../es/Dm-crypt/Device_encryption.html "Dm-crypt (Español)/Device encryption – español")
* [日本語](https://wiki.archlinux.jp/index.php/Dm-crypt/%E3%83%87%E3%83%90%E3%82%A4%E3%82%B9%E3%81%AE%E6%9A%97%E5%8F%B7%E5%8C%96 "Dm-crypt/デバイスの暗号化 – 日本語")
* [Polski](../../pl/Dm-crypt/Device_encryption.html "Dm-crypt (Polski)/Device encryption – polski")
* [Português](../../pt/Dm-crypt/Device_encryption.html "Dm-crypt (Português)/Device encryption – português")
* [中文(简体)](https://wiki.archlinuxcn.org/wiki/Dm-crypt/Device_encryption "Dm-crypt/Device encryption – 中文(简体)")
From ArchWiki
< [Dm-crypt](../../en/Dm-crypt.html "Dm-crypt")
This section covers how to manually utilize *dm-crypt* from the command line to encrypt a system.
|
dm-crypt/Device encryption | Preparation |
## Preparation
Before using [cryptsetup](https://archlinux.org/packages/?name=cryptsetup), always make sure the `dm_crypt` [kernel module](../../en/Kernel_module.html "Kernel module") is loaded.
|
dm-crypt/Device encryption | Cryptsetup usage |
## Cryptsetup usage
*Cryptsetup* is the command line tool to interface with *dm-crypt* for creating, accessing and managing encrypted devices. The tool was later expanded to support different encryption types that rely on the Linux kernel **d**evice-**m**apper and the **crypt**ographic modules. The most notable expansion was for the Linux Unified Key Setup (LUKS) extension, which stores all of the needed setup information for dm-crypt on the disk itself and abstracts partition and key management in an attempt to improve ease of use. Devices accessed via the device-mapper are called block devices. For further information see [Data-at-rest encryption#Block device encryption](../../en/Data-at-rest_encryption.html#Block_device_encryption "Data-at-rest encryption").
The tool is used as follows:
```
# cryptsetup OPTIONS action action-specific-options device dmname
```
It has compiled-in defaults for the options and the encryption mode, which will be used if no others are specified on the command line. Have a look at
```
$ cryptsetup --help
```
which lists options, actions and the default parameters for the encryption modes in that order. A full list of options can be found on the man page. Since different parameters are required or optional, depending on encryption mode and action, the following sections point out differences further. Block device encryption is fast, but speed matters a lot too. Since changing an encryption cipher of a block device after setup is difficult, it is important to check *dm-crypt* performance for the individual parameters in advance:
```
$ cryptsetup benchmark
```
can give guidance on deciding for an algorithm and key-size prior to installation. If certain AES ciphers excel with a considerable higher throughput, these are probably the ones with hardware support in the CPU.
**Tip:** You may want to practise encrypting a virtual hard drive in a [virtual machine](../../en/Category:Virtualization.html "Virtual machine") when learning.
### Cryptsetup passphrases and keys
An encrypted block device is protected by a key. A key is either:
* a passphrase: see [Security#Passwords](../../en/Security.html#Passwords "Security").
* a keyfile, see [#Keyfiles](#Keyfiles).
Both key types have default maximum sizes: passphrases can be up to 512 characters and keyfiles up to 8192 KiB.
An important distinction of *LUKS* to note at this point is that the key is used to unlock the master-key of a LUKS-encrypted device and can be changed with root access. Other encryption modes do not support changing the key after setup, because they do not employ a master-key for the encryption. See [Data-at-rest encryption#Block device encryption](../../en/Data-at-rest_encryption.html#Block_device_encryption "Data-at-rest encryption") for details.
|
dm-crypt/Device encryption | Encryption options with dm-crypt |
## Encryption options with dm-crypt
*Cryptsetup* supports different encryption operating modes to use with *dm-crypt*:
* `--type luks` for using the default LUKS format version (LUKS1 with [cryptsetup](https://archlinux.org/packages/?name=cryptsetup) < 2.1.0, LUKS2 with [cryptsetup](https://archlinux.org/packages/?name=cryptsetup) ≥ 2.1.0),
* `--type luks1` for using LUKS1, the previous version of LUKS,
* `--type luks2` for using LUKS2, the current version of LUKS that introduced additional extensions,
* `--type plain` for using dm-crypt plain mode,
* `--type loopaes` for a loopaes legacy mode,
* `--type tcrypt` for a [TrueCrypt](../../en/VeraCrypt.html "TrueCrypt") compatibility mode.
* `--type bitlk` for a [BitLocker](https://en.wikipedia.org/wiki/BitLocker "wikipedia:BitLocker") compatibility mode. See [cryptsetup(8) § BITLK (WINDOWS BITLOCKER COMPATIBLE) EXTENSION](https://man.archlinux.org/man/cryptsetup.8#BITLK_\(WINDOWS_BITLOCKER_COMPATIBLE\)_EXTENSION).
The basic cryptographic options for encryption cipher and hashes available can be used for all modes and rely on the kernel cryptographic backend features. All that are loaded and available to use as options at runtime can be viewed with:
```
$ less /proc/crypto
```
**Tip:** If the list is short, execute `$ cryptsetup benchmark` which will trigger loading available modules.
The following introduces encryption options for the `luks`, `luks1`, `luks2` and `plain` modes. Note that the tables list options used in the respective examples in this article and not all available ones.
### Encryption options for LUKS mode
The *cryptsetup* action to set up a new dm-crypt device in LUKS encryption mode is `luksFormat`. Unlike what the name implies, it does not format the device, but sets up the LUKS device header and encrypts the master-key with the desired cryptographic options.
In order to create a new LUKS container with the compiled-in defaults listed by `cryptsetup --help`, simply execute:
```
# cryptsetup luksFormat device
```
As of cryptsetup 2.4.0, this is equivalent to:
```
# cryptsetup --type luks2 --cipher aes-xts-plain64 --hash sha256 --iter-time 2000 --key-size 256 --pbkdf argon2id --use-urandom --verify-passphrase luksFormat device
```
Defaults are compared with a cryptographically higher specification example in the table below, with accompanying comments:
| Options | Cryptsetup 2.1.0 defaults | Example | Comment |
| --------------------- | ------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| --cipher-c | `aes-xts-plain64` | `aes-xts-plain64` | [Release 1.6.0](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.6/v1.6.0-ReleaseNotes) changed the defaults to an AES [cipher](../../en/Data-at-rest_encryption.html#Ciphers_and_modes_of_operation "Data-at-rest encryption") in [XTS](https://en.wikipedia.org/wiki/Disk_encryption_theory#XEX-based_tweaked-codebook_mode_with_ciphertext_stealing_.28XTS.29 "wikipedia:Disk encryption theory") mode (see item 5.16 [of the FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions#5-security-aspects)). It is advised against using the previous default `--cipher aes-cbc-essiv` because of its known [issues](https://en.wikipedia.org/wiki/Disk_encryption_theory#Cipher-block_chaining_.28CBC.29 "wikipedia:Disk encryption theory") and practical [attacks](https://www.jakoblell.com/blog/2013/12/22/practical-malleability-attack-against-cbc-encrypted-luks-partitions/) against them. |
| --key-size-s | `256` (`512` for XTS) | `512` | By default a 512 bit key-size is used for XTS ciphers. Note however that [XTS splits the supplied key in half](https://en.wikipedia.org/wiki/Disk_encryption_theory#XEX-based_tweaked-codebook_mode_with_ciphertext_stealing_.28XTS.29 "wikipedia:Disk encryption theory"), so this results in AES-256 being used. |
| --hash-h | `sha256` | `sha512` | Hash algorithm used for [key derivation](../../en/Data-at-rest_encryption.html#Cryptographic_metadata "Data-at-rest encryption"). Release 1.7.0 changed defaults from `sha1` to `sha256` "*not for security reasons \[but] mainly to prevent compatibility problems on hardened systems where SHA1 is already \[being] phased out*"[\[1\]](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/v1.7.0-ReleaseNotes). The former default of `sha1` can still be used for compatibility with older versions of *cryptsetup* since it is [considered secure](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions#5-security-aspects) (see item 5.20). |
| --iter-time-i | `2000` | `5000` | Number of milliseconds to spend with PBKDF passphrase processing. Release 1.7.0 changed defaults from `1000` to `2000` to "*try to keep PBKDF2 iteration count still high enough and also still acceptable for users.*"[\[2\]](https://www.kernel.org/pub/linux/utils/cryptsetup/v1.7/v1.7.0-ReleaseNotes). This option is only relevant for LUKS operations that set or change passphrases, such as `luksFormat` or `luksAddKey`. Specifying 0 as parameter selects the compiled-in default. |
| --use-urandom | `--use-urandom` | `--use-random` | Selects which [random number generator](../../en/Random_number_generation.html "Random number generator") to use. Note that [/dev/random blocking pool has been removed](https://lwn.net/Articles/808575/). Therefore, `--use-random` flag is now equivalent to `--use-urandom`. |
| --verify-passphrase-y | Yes | - | Enabled by default in Arch Linux for `luksFormat` and `luksAddKey`. |
The properties of LUKS features and options are described in the [LUKS1](https://gitlab.com/cryptsetup/cryptsetup/wikis/Specification) (pdf) and [LUKS2](https://gitlab.com/cryptsetup/cryptsetup/blob/master/docs/on-disk-format-luks2.pdf) (pdf) specifications.
**Tip:** The project developers' [devconfcz2016](https://mbroz.fedorapeople.org/talks/devconf2016-luks2.pdf) (pdf) presentation summarizes the motivation for the major specification update to LUKS2. See also cryptsetup's major [v2 release notes](https://mirrors.edge.kernel.org/pub/linux/utils/cryptsetup/v2.0/v2.0.0-ReleaseNotes).
#### Iteration time
From [cryptsetup FAQ§2.1](https://gitlab.com/cryptsetup/cryptsetup/-/wikis/FrequentlyAskedQuestions#2-setup) and [§3.4](https://gitlab.com/cryptsetup/cryptsetup/-/wikis/FrequentlyAskedQuestions#3-common-problems):
* * The unlock time for a key-slot \[...] is calculated when setting a passphrase. By default it is 1 second (2 seconds for LUKS2). \[...]
* Passphrase iteration count is based on time and hence security level depends on CPU power of the system the LUKS container is created on. \[...]
* If you set a passphrase on a fast machine and then unlock it on a slow machine, the unlocking time can be much longer.
As such, it is better to always create a container on the machine where it will be most often accessed.
Read the rest of those sections for advice on how to correctly adjust the iteration count should the need arise.
#### Sector size
See [Advanced Format#dm-crypt](../../en/Advanced_Format.html#dm-crypt "Advanced Format").
### Encryption options for plain mode
In dm-crypt *plain* mode, there is no master-key on the device, hence, there is no need to set it up. Instead the encryption options to be employed are used directly to create the mapping between an encrypted disk and a named device. The mapping can be created against a partition or a full device. In the latter case not even a partition table is needed.
To create a *plain* mode mapping with cryptsetup's default parameters:
```
# cryptsetup options open --type plain device dmname
```
Executing it will prompt for a password, which should have very high entropy, and the `--verify-passphrase` option can be used but is not a default. In general it is advisable to make exact note of the encryption options used for the creation, because they can not be derived from the encrypted device, or an optional key-file, and upstream defaults may change.
Below a comparison of default parameters with the example in [dm-crypt/Encrypting an entire system#Plain dm-crypt](../../en/Dm-crypt/Encrypting_an_entire_system.html#Plain_dm-crypt "Dm-crypt/Encrypting an entire system").
| Option | Cryptsetup 2.7.0 defaults | Example | Comment |
| ---------------- | ------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| --hash-h | `sha256` | - | The hash is used to create the key from the passphrase; it is not used on a keyfile. |
| --cipher-c | `aes-xts-plain64` | `aes-xts-plain64` | The cipher consists of three parts: cipher-chainmode-IV generator. Please see [Data-at-rest encryption#Ciphers and modes of operation](../../en/Data-at-rest_encryption.html#Ciphers_and_modes_of_operation "Data-at-rest encryption") for an explanation of these settings, and the [DMCrypt documentation](https://gitlab.com/cryptsetup/cryptsetup/wikis/DMCrypt) for some of the options available. |
| --key-size-s | `256` | `512` | The key size (in bits). The size will depend on the cipher being used and also the chainmode in use. Xts mode requires twice the key size of cbc. |
| --size-b | real size of target disk | `2048` (mapped device will be 512B×2048=1MiB) | Limit the maximum size of the device (in 512-byte sectors). |
| --offset-o | `0` | `0` | The offset from the beginning of the target disk (in 512-byte sectors) from which to start the mapping. |
| --skip-p | `0` | `2048` (512B×2048=1MiB will be skipped) | The number of 512-byte sectors of encrypted data to skip at the beginning. |
| --key-file-d | default uses a passphrase | `/dev/sdZ` (or e.g. `/boot/keyfile.enc`) | The device or file to be used as a key. See [#Keyfiles](#Keyfiles) for further details. |
| --keyfile-offset | `0` | `0` | Offset from the beginning of the file where the key starts (in bytes). This option is supported from *cryptsetup* 1.6.7 onwards. |
| --keyfile-size-l | `8192kB` | - (default applies) | Limits the bytes read from the key file. This option is supported from *cryptsetup* 1.6.7 onwards. |
Using the device `/dev/sdX`, the above right column example results in:
```
# cryptsetup --cipher=aes-xts-plain64 --offset=0 --key-file=/dev/sdZ --key-size=512 open --type=plain /dev/sdX enc
```
**Warning:** Unlike encrypting with LUKS, the above command must be executed *in full* whenever the mapping needs to be re-established, so it is important to remember the cipher, hash and key file details. Do not rely on cryptsetup defaults since they change between versions.
We can now check that the mapping has been made:
```
# fdisk -l
```
An entry should now exist for `/dev/mapper/enc`.
|
dm-crypt/Device encryption | Encrypting devices with cryptsetup |
## Encrypting devices with cryptsetup
This section shows how to employ the options for creating new encrypted block devices and accessing them manually.
**Warning:** GRUB's support for LUKS2 is limited; see [GRUB#Encrypted /boot](../../en/GRUB.html#Encrypted_/boot "GRUB") for details. Use LUKS1 (`cryptsetup luksFormat --type luks1`) for partitions that GRUB will need to unlock.
### Encrypting devices with LUKS mode
#### Formatting LUKS partitions
In order to setup a partition as an encrypted LUKS partition execute:
```
# cryptsetup luksFormat device
```
You will then be prompted to enter a password and verify it.
See [#Encryption options for LUKS mode](#Encryption_options_for_LUKS_mode) for command line options.
You can check the results with:
```
# cryptsetup luksDump device
```
You will note that the dump not only shows the cipher header information, but also the key-slots in use for the LUKS partition.
The following example will create an encrypted root partition on `/dev/sda1` using the default AES cipher in XTS mode with an effective 256-bit encryption
```
# cryptsetup -s 512 luksFormat /dev/sda1
```
##### Using LUKS to format partitions with a keyfile
When creating a new LUKS encrypted partition, a keyfile may be associated with the partition on its creation using:
```
# cryptsetup luksFormat device /path/to/mykeyfile
```
See [#Keyfiles](#Keyfiles) for instructions on how to generate and manage keyfiles.
#### Unlocking/Mapping LUKS partitions with the device mapper
Once the LUKS partitions have been created, they can then be unlocked.
The unlocking process will map the partitions to a new device name using the device mapper. This alerts the kernel that `device` is actually an encrypted device and should be addressed through LUKS using the `/dev/mapper/dm_name` so as not to overwrite the encrypted data. To guard against accidental overwriting, read about the possibilities to [backup the cryptheader](#Backup_and_restore) after finishing setup.
In order to open an encrypted LUKS partition execute:
```
# cryptsetup open device dm_name
```
You will then be prompted for the password to unlock the partition. Usually the device mapped name is descriptive of the function of the partition that is mapped. For example the following unlocks a root luks partition `/dev/sda1` and maps it to device mapper named `root`:
```
# cryptsetup open /dev/sda1 root
```
Once opened, the root partition device address would be `/dev/mapper/root` instead of the partition (e.g. `/dev/sda1`).
For setting up LVM ontop the encryption layer the device file for the decrypted volume group would be anything like `/dev/mapper/root` instead of `/dev/sda1`. LVM will then give additional names to all logical volumes created, e.g. `/dev/lvmpool/root` and `/dev/lvmpool/swap`.
In order to write encrypted data into the partition it must be accessed through the device mapped name. The first step of access will typically be to [create a file system](../../en/File_systems.html#Create_a_file_system "Create a file system"). For example:
```
# mkfs -t ext4 /dev/mapper/root
```
The device `/dev/mapper/root` can then be [mounted](../../en/File_systems.html#Mount_a_file_system "Mount") like any other partition.
To close the LUKS container, unmount the partition and do:
```
# cryptsetup close root
```
#### Using a TPM to store keys
See [Trusted Platform Module#Data-at-rest encryption with LUKS](../../en/Trusted_Platform_Module.html#Data-at-rest_encryption_with_LUKS "Trusted Platform Module").
### Encrypting devices with plain mode
The creation and subsequent access of a *dm-crypt* plain mode encryption both require not more than using the *cryptsetup* `open` action with correct [parameters](#Encryption_options_for_plain_mode). The following shows that with two examples of non-root devices, but adds a quirk by stacking both (i.e. the second is created inside the first). Obviously, stacking the encryption doubles overhead. The usecase here is simply to illustrate another example of the cipher option usage.
A first mapper is created with *cryptsetup's* plain-mode defaults, as described in the table's left column above
```
# cryptsetup --type plain -v open /dev/sdxY plain1
```
```
Enter passphrase:
Command successful.
```
Now we add the second block device inside it, using different encryption parameters and with an (optional) offset, create a file system and mount it
```
# cryptsetup --type plain --cipher=serpent-xts-plain64 --hash=sha256 --key-size=256 --offset=10 open /dev/mapper/plain1 plain2
```
```
Enter passphrase:
```
```
# lsblk -p
```
```
NAME
/dev/sda
├─/dev/sdxY
│ └─/dev/mapper/plain1
│ └─/dev/mapper/plain2
...
```
```
# mkfs -t ext2 /dev/mapper/plain2
# mount -t ext2 /dev/mapper/plain2 /mnt
# echo "This is stacked. one passphrase per foot to shoot." > /mnt/stacked.txt
```
We close the stack to check access works
```
# cryptsetup close plain2
# cryptsetup close plain1
```
First, let us try to open the file system directly:
```
# cryptsetup --type plain --cipher=serpent-xts-plain64 --hash=sha256 --key-size=256 --offset=10 open /dev/sdxY plain2
```
```
# mount -t ext2 /dev/mapper/plain2 /mnt
```
```
mount: wrong fs type, bad option, bad superblock on /dev/mapper/plain2,
missing codepage or helper program, or other error
```
Why that did not work? Because the "plain2" starting block (`10`) is still encrypted with the cipher from "plain1". It can only be accessed via the stacked mapper. The error is arbitrary though, trying a wrong passphrase or wrong options will yield the same. For *dm-crypt* plain mode, the `open` action will not error out itself.
Trying again in correct order:
```
# cryptsetup close plain2 # dysfunctional mapper from previous try
```
```
# cryptsetup --type plain open /dev/sdxY plain1
```
```
Enter passphrase:
```
```
# cryptsetup --type plain --cipher=serpent-xts-plain64 --hash=sha256 --key-size=256 --offset=10 open /dev/mapper/plain1 plain2
```
```
Enter passphrase:
```
```
# mount /dev/mapper/plain2 /mnt && cat /mnt/stacked.txt
```
```
This is stacked. one passphrase per foot to shoot.
```
*dm-crypt* will handle stacked encryption with some mixed modes too. For example LUKS mode could be stacked on the "plain1" mapper. Its header would then be encrypted inside "plain1" when that is closed.
Available for plain mode only is the option `--shared`. With it a single device can be segmented into different non-overlapping mappers. We do that in the next example, using a *loopaes* compatible cipher mode for "plain2" this time:
```
# cryptsetup --type plain --offset 0 --size 1000 open /dev/sdxY plain1
```
```
Enter passphrase:
```
```
# cryptsetup --type plain --offset 1000 --size 1000 --shared --cipher=aes-cbc-lmk --hash=sha256 open /dev/sdxY plain2
```
```
Enter passphrase:
```
```
# lsblk -p
```
```
NAME
dev/sdxY
├─/dev/sdxY
│ ├─/dev/mapper/plain1
│ └─/dev/mapper/plain2
...
```
As the device tree shows both reside on the same level, i.e. are not stacked and "plain2" can be opened individually.
|
dm-crypt/Device encryption | Cryptsetup actions specific for LUKS |
## Cryptsetup actions specific for LUKS
### Key management
It is possible to define additional keys for the LUKS partition. This enables the user to create access keys for safe backup storage In so-called key escrow, one key is used for daily usage, another kept in escrow to gain access to the partition in case the daily passphrase is forgotten or a keyfile is lost/damaged. A different key-slot could also be used to grant access to a partition to a user by issuing a second key and later revoking it again.
Once an encrypted partition has been created, the initial keyslot 0 is created (if no other was specified manually). Additional keyslots are numbered from 1 to 7. Which keyslots are used can be seen by issuing
```
# cryptsetup luksDump /dev/device
```
Where `device` is the block device containing the LUKS header. This and all the following commands in this section work on header backup files as well.
#### Adding LUKS keys
Adding new keyslots is accomplished with the `luksAddKey` action. For safety it will always, even for already unlocked devices, ask for a valid existing key (a passphrase for any existing slot) before a new one may be entered:
```
# cryptsetup luksAddKey /dev/device [/path/to/additionalkeyfile]
```
```
Enter any passphrase:
Enter new passphrase for key slot:
Verify passphrase:
```
If `/path/to/additionalkeyfile` is given, cryptsetup will add a new keyslot for `additionalkeyfile`. Otherwise it prompts for a new passphrase. To authorize the action with an existing *keyfile*, the `--key-file` or `-d` option followed by the "old" `keyfile` will try to unlock all available keyfile keyslots:
```
# cryptsetup luksAddKey /dev/device [/path/to/additionalkeyfile] -d /path/to/keyfile
```
If it is intended to use multiple keys and change or revoke them, the `--key-slot` or `-S` option may be used to specify the slot:
```
# cryptsetup luksAddKey /dev/device -S 6
```
```
Enter any passphrase:
Enter new passphrase for key slot:
Verify passphrase:
```
```
# cryptsetup luksDump /dev/device
```
```
...
Keyslots:
...
6: luks2
Key: 512 bits
Priority: normal
...
```
**Tip:** For LUKS2 it is possible to assign priorities to individual keyslots, see [cryptsetup-config(8)](https://man.archlinux.org/man/cryptsetup-config.8). For example, if above slot `6` is intended to unlock a device at boot, execute `cryptsetup config --priority prefer --key-slot 6 /dev/device` as root.
To show an associated action in this example, we decide to change the key right away:
```
# cryptsetup luksChangeKey /dev/device -S 6
```
```
Enter LUKS passphrase to be changed:
Enter new LUKS passphrase:
```
before continuing to remove it.
#### Removing LUKS keys
There are three different actions to remove keys from the header:
* `luksRemoveKey` removes a key by specifying its passphrase/key-file.
* `luksKillSlot` removes a key by specifying its slot (needs another valid key). Obviously, this is extremely useful if you have forgotten a passphrase, lost a key-file, or have no access to it.
* `luksErase` removes **all** active keys.
**Warning:**
* All above actions can be used to irrevocably delete the last active key for an encrypted device!
* The `luksErase` command was added in version 1.6.4 to quickly nuke access to the device. This action **will not** prompt for a valid passphrase! It will not [wipe the LUKS header](../../en/Dm-crypt/Drive_preparation.html#Wipe_LUKS_header "Dm-crypt/Drive preparation"), but all keyslots at once and you will, therefore, not be able to regain access unless you have a valid backup of the LUKS header.
For above warning it is good to know the key we want to **keep** is valid. An easy check is to unlock the device with the `-v` option, which will specify which slot it occupies:
```
# cryptsetup --test-passphrase -v open /dev/device
```
```
Enter passphrase for /dev/device:
Key slot 1 unlocked.
Command successful.
```
Now we can remove the key added in the previous subsection using its passphrase:
```
# cryptsetup luksRemoveKey /dev/device
```
```
Enter LUKS passphrase to be deleted:
```
If we had used the same passphrase for two keyslots, the first slot would be wiped now. Only executing it again would remove the second one.
Alternatively, we can specify the key slot:
```
# cryptsetup luksKillSlot /dev/device 6
```
```
Enter any remaining LUKS passphrase:
```
Note that in both cases, no confirmation was required.
```
# cryptsetup luksDump /dev/sda8 | grep 'Slot 6'
```
```
Key Slot 6: DISABLED
```
To re-iterate the warning above: If the same passphrase had been used for key slots 1 and 6, both would be gone now.
### Backup and restore
If the header of a LUKS encrypted partition gets destroyed, you will not be able to decrypt your data. It is just as much of a dilemma as forgetting the passphrase or damaging a key-file used to unlock the partition. Damage may occur by your own fault while re-partitioning the disk later or by third-party programs misinterpreting the partition table. Therefore, having a backup of the header and storing it on another disk might be a good idea.
**Note:** If one of the LUKS-encrypted partitions' passphrases becomes compromised, you must revoke it on *every* copy of the cryptheader, even those you have backed up. Otherwise, a copy of the backed-up cryptheader that uses the compromised passphrase can be used to determine the master key which in turn can be used to decrypt the associated partition (even your actual partition, not only the backed-up version). On the other hand, if the master key gets compromised, you have to reencrypt your whole partition. See [LUKS FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions#6-backup-and-data-recovery) for further details.
#### Backup using cryptsetup
Cryptsetup's `luksHeaderBackup` action stores a binary backup of the LUKS header and keyslot area:
```
# cryptsetup luksHeaderBackup /dev/device --header-backup-file /mnt/backup/file.img
```
where `device` is the partition containing the LUKS volume.
You can also back up the plain text header into ramfs and encrypt it with e.g. [GPG](../../en/GnuPG.html "GPG") before writing it to persistent storage:
```
# mount --mkdir -t ramfs ramfs /root/tmp
# cryptsetup luksHeaderBackup /dev/device --header-backup-file /root/tmp/file.img
# gpg2 --recipient User_ID --encrypt /root/tmp/file.img
# cp /root/tmp/file.img.gpg /mnt/backup/
# umount /root/tmp
```
**Warning:** [tmpfs](../../en/Tmpfs.html "Tmpfs") can swap to the disk in low memory situations, so it is not recommended here.
#### Restore using cryptsetup
**Warning:** Restoring the wrong header or restoring to an unencrypted partition will cause data loss! The action can not perform a check whether the header is actually the *correct* one for that particular device.
In order to evade restoring a wrong header, you can ensure it does work by using it as a remote `--header` first:
```
# cryptsetup -v --header /mnt/backup/file.img open /dev/device test
```
```
Key slot 0 unlocked.
Command successful.
```
```
# mount /dev/mapper/test /mnt/test && ls /mnt/test
# umount /mnt/test
# cryptsetup close test
```
Now that the check succeeded, the restore may be performed:
```
# cryptsetup luksHeaderRestore /dev/device --header-backup-file ./mnt/backup/file.img
```
Now that all the keyslot areas are overwritten; only active keyslots from the backup file are available after issuing the command.
#### Manual backup and restore
The header always resides at the beginning of the device and a backup can be performed without access to *cryptsetup* as well. First you have to find out the payload offset of the crypted partition:
```
# cryptsetup luksDump /dev/device | grep "Payload offset"
```
```
Payload offset: 4040
```
Second check the sector size of the drive
```
# fdisk -l /dev/device | grep "Sector size"
```
```
Sector size (logical/physical): 512 bytes / 512 bytes
```
Now that you know the values, you can backup the header with a simple [dd](../../en/Dd.html "Dd") command:
```
# dd if=/dev/device of=/path/to/file.img bs=512 count=4040
```
and store it safely.
A restore can then be performed using the same values as when backing up:
```
# dd if=./file.img of=/dev/device bs=512 count=4040
```
### Re-encrypting devices
**This article or section needs expansion.**
**Reason:** cryptsetup 2.2 using LUKS2 (with a 16 MiB header) supports online encryption/decryption/reencryption.[\[3\]](https://mirrors.edge.kernel.org/pub/linux/utils/cryptsetup/v2.2/v2.2.0-ReleaseNotes) (Discuss in [Talk:Dm-crypt/Device encryption](../../en/Talk:Dm-crypt/Device_encryption.html))
**This article or section is out of date.**
**Reason:** cryptsetup-reencrypt was removed in cryptsetup 2.5.0.[\[4\]](https://www.kernel.org/pub/linux/utils/cryptsetup/v2.5/v2.5.0-ReleaseNotes) (Discuss in [Talk:Dm-crypt/Device encryption](../../en/Talk:Dm-crypt/Device_encryption.html))
The [cryptsetup](https://archlinux.org/packages/?name=cryptsetup) package features two options for re-encryption.
* cryptsetup reencrypt
Argument to `cryptsetup` itself: Preferred method. Currently LUKS2 devices only. Actions can be performed online. Supports multiple parallel re-encryption jobs. Resilient to system failures. See [cryptsetup(8)](https://man.archlinux.org/man/cryptsetup.8) for more information.
- cryptsetup-reencrypt
Legacy tool, supports LUKS1 in addition to LUKS2. Actions can be performed on unmounted devices only. Single process at a time. Sensitive to system failures. See [cryptsetup-reencrypt(8)](https://man.archlinux.org/man/cryptsetup-reencrypt.8) for more information.
Both can be used to convert an existing unencrypted file system to a LUKS encrypted one or permanently remove LUKS encryption from a device (using `--decrypt`). As its name suggests it can also be used to re-encrypt an existing LUKS encrypted device, though, re-encryption is not possible for a detached LUKS header or other encryption modes (e.g. plain-mode). For re-encryption it is possible to change the [#Encryption options for LUKS mode](#Encryption_options_for_LUKS_mode).
One application of re-encryption may be to secure the data again after a passphrase or [keyfile](#Keyfiles) has been compromised *and* one cannot be certain that no copy of the LUKS header has been obtained. For example, if only a passphrase has been shoulder-surfed but no physical/logical access to the device happened, it would be enough to change the respective passphrase/key only ([#Key management](#Key_management)).
**Warning:** Always make sure a **reliable backup** is available and double-check options you specify before using the tool!
The following shows an example to encrypt an unencrypted file system partition and a re-encryption of an existing LUKS device.
#### Encrypt an existing unencrypted file system
**Tip:** If you are trying to encrypt an existing root partition, you might want to create a separate and unencrypted boot partition which will be mounted to `/boot` (see [Dm-crypt/Encrypting an entire system#Preparing the boot partition](../../en/Dm-crypt/Encrypting_an_entire_system.html#Preparing_the_boot_partition "Dm-crypt/Encrypting an entire system")). It is not strictly necessary but has a number of advantages:
* If `/boot` is located inside an encrypted root partition, the system will ask for the passphrase twice when the machine is powered on. The first time will happen when the boot loader attempts to read the files located inside encrypted `/boot`, the second time will be when the kernel tries to mount the encrypted partition [\[5\]](https://opencraft.com/blog/tutorial-encrypting-an-existing-root-partition-in-ubuntu-with-dm-crypt-and-luks/). This might not be the desired behaviour and can be prevented by having a separate and unencrypted boot partition.
* Some system restore applications (e.g., [timeshift](https://archlinux.org/packages/?name=timeshift)) will not work if `/boot` is located inside an encrypted partition [\[6\]](https://github.com/teejee2008/timeshift/issues/280).
In short, create a partition with the size of at least 260 MiB if needed. See [Partitioning#/boot](../../en/Partitioning.html#/boot "Partitioning").
A LUKS encryption header is always stored at the beginning of the device. Since an existing file system will usually be allocated all partition sectors, the first step is to shrink it to make space for the LUKS header.
**This article or section needs expansion.**
**Reason:** cryptsetup man pages suggest using twice the LUKS2 header size. That implies 32 MiB and using `--reduce-device-size 32M` (Discuss in [Talk:Dm-crypt/Device encryption](../../en/Talk:Dm-crypt/Device_encryption.html))
The [default](#Encryption_options_for_LUKS_mode) LUKS2 header requires 16 MiB. If the current file system occupies all the available space, we will have to shrink it at least that much. To shrink an existing `ext4` file system on `/dev/sdxY` to its current possible minimum:
```
# umount /mnt
```
```
# e2fsck -f /dev/sdxY
```
```
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
...
/dev/sda6: 12/166320 files (0.0% non-contiguous), 28783/665062 blocks
```
```
# resize2fs -p -M /dev/sdxY
```
```
e2fsck 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/sdxY to 26347 (4k) blocks.
The filesystem on /dev/sdxY is now 26347 (4k) blocks long.
```
**Tip:** Shrinking to the minimum size with `-M` might take a long time. You might want to calculate a size just 32 MiB smaller than the current size instead of using `-M`.
**Warning:** The file system should be shrunk while the underlying device (e.g., a partition) should be kept at its original size. Some graphical tools (e.g., [GParted](../../en/Parted.html "GParted")) may resize both the file system and the partition, and data loss may occur after encryption.
Now we encrypt it, using the default cipher we do not have to specify it explicitly:
```
# cryptsetup reencrypt --encrypt --reduce-device-size 16M /dev/sdxY
```
```
WARNING!
========
This will overwrite data on LUKS2-temp-12345678-9012-3456-7890-123456789012.new irrevocably.
Are you sure? (Type 'yes' in capital letters): YES
Enter passphrase for LUKS2-temp-12345678-9012-3456-7890-123456789012.new:
Verify passphrase:
```
After it finished, the whole `/dev/sdxY` partition is encrypted, not only the space the file system was shrunk to. As a final step we extend the original `ext4` file system to occupy all available space again, on the now encrypted partition:
```
# cryptsetup open /dev/sdxY recrypt
```
```
Enter passphrase for /dev/sdxY:
...
```
```
# resize2fs /dev/mapper/recrypt
```
```
resize2fs 1.43-WIP (18-May-2015)
Resizing the filesystem on /dev/mapper/recrypt to 664807 (4k) blocks.
The filesystem on /dev/mapper/recrypt is now 664807 (4k) blocks long.
```
```
# mount /dev/mapper/recrypt /mnt
```
The file system is now ready to use. You may want to add it to your [crypttab](../../en/Dm-crypt/System_configuration.html#crypttab "Crypttab").
**Tip:** If you have just encrypted your root partition, you might need to perform a number of post-encryption adjustments.
1. Configure mkinitcpio and kernel parameters. See [dm-crypt/System configuration#Unlocking in early userspace](../../en/Dm-crypt/System_configuration.html#Unlocking_in_early_userspace "Dm-crypt/System configuration").
2. Update the entry for `/` in [fstab](../../en/Fstab.html "Fstab") to use the unlocked volume's specifier (e.g. [UUID](../../en/Persistent_block_device_naming.html#by-uuid "UUID")).
#### Re-encrypting an existing LUKS partition
In this example an existing LUKS device is re-encrypted.
**Warning:** Double-check you specify encryption options for correctly and *never* re-encrypt without a **reliable backup**!
In order to re-encrypt a device with its existing encryption options, they do not need to be specified:
```
# cryptsetup reencrypt /dev/sdxY
```
**Note:** For LUKS1 we will need to use the legacy tool:
```
# cryptsetup-reencrypt /dev/sdxY
```
Existing keys are retained when re-encrypting a device with a different cipher and/or hash. Another use case is to re-encrypt LUKS devices which have non-current encryption options. Apart from above warning on specifying options correctly, the ability to change the LUKS header may also be limited by its size. For example, if the device was initially encrypted using a CBC mode cipher and 128 bit key-size, the LUKS header will be half the size of above mentioned `4096` sectors:
```
# cryptsetup luksDump /dev/sdxY | grep -e "mode" -e "Payload" -e "MK bits"
```
```
Cipher mode: cbc-essiv:sha256
Payload offset: 2048
MK bits: 128
```
While it is possible to upgrade the encryption of such a device, it is currently only feasible in two steps. First, re-encrypting with the same encryption options, but using the `--reduce-device-size` option to make further space for the larger LUKS header. Second, re-encypt the whole device again with the desired cipher. For this reason and the fact that a backup should be created in any case, creating a new, fresh encrypted device to restore into is always the faster option.
### Conversion from LUKS1 to LUKS2 and back
The [cryptsetup](https://archlinux.org/packages/?name=cryptsetup) package has `convert` option that needed for conversion between LUKS1 and LUKS2 container types. The argument `--type` is **required**.
Migration from LUKS1 to LUKS2:
```
# cryptsetup convert --type luks2 /dev/sdxY
```
**Note:** The LUKS header size will be 16 MiB instead of 2 MiB.
Rollback to LUKS1 (for example, to boot from [GRUB with encrypted /boot](../../en/GRUB.html#Encrypted_/boot "GRUB")):
```
# cryptsetup convert --type luks1 /dev/sdxY
```
**Note:** Conversion from LUKS2 to LUKS1 is **not** always possible. You may get the following error:
```
Cannot convert to LUKS1 format - keyslot 0 is not LUKS1 compatible.
```
If the container is using Argon2, it needs to be converted to PBKDF2 to be LUKS1-compatible.
```
# cryptsetup luksConvertKey --pbkdf pbkdf2 /dev/sdxY
```
|
dm-crypt/Device encryption | Resizing encrypted devices |
## Resizing encrypted devices
**This article or section needs expansion.**
**Reason:** This section should be rewritten to introduce resizing more generically. Perhaps work on it together with [Resizing LVM-on-LUKS](../../en/Resizing_LVM-on-LUKS.html "Resizing LVM-on-LUKS"). (Discuss in [Talk:Dm-crypt/Device encryption](../../en/Talk:Dm-crypt/Device_encryption.html))
If a storage device encrypted with dm-crypt is being cloned (with a tool like dd) to another larger device, the underlying dm-crypt device must be resized to use the whole space.
The destination device is /dev/sdX2 in this example, the whole available space adjacent to the partition will be used:
```
# cryptsetup luksOpen /dev/sdX2 sdX2
# cryptsetup resize sdX2
```
Then the underlying file system must be resized.
### Loopback file system
Assume that an encrypted loopback file system is stored in a file `/bigsecret`, looped to `/dev/loop0`, mapped to `secret` and mounted on `/mnt/secret`, as in the example at [dm-crypt/Encrypting a non-root file system#File container](../../en/Dm-crypt/Encrypting_a_non-root_file_system.html#File_container "Dm-crypt/Encrypting a non-root file system").
If the container file is currently mapped and/or mounted, unmount and/or close it:
```
# umount /mnt/secret
# cryptsetup close secret
# losetup -d /dev/loop0
```
Next, expand the container file with the size of the data you want to add. In this example, the file will be expanded with 1M \* 1024, which is 1G.
**Warning:** Make absolutely sure to use **two** `>`, instead of just one, or else you will overwrite the file instead of appending to it. Making a backup before this step is strongly recommended.
```
# dd if=/dev/urandom bs=1M count=1024 | cat - >> /bigsecret
```
Now map the container to the loop device:
```
# losetup /dev/loop0 /bigsecret
# cryptsetup open /dev/loop0 secret
```
After this, resize the encrypted part of the container to the new maximum size of the container file:
```
# cryptsetup resize secret
```
Finally, perform a file system check and, if it is ok, resize it (example for ext2/3/4):
```
# e2fsck -f /dev/mapper/secret
# resize2fs /dev/mapper/secret
```
You can now mount the container again:
```
# mount /dev/mapper/secret /mnt/secret
```
### Integrity protected device
If the device was formatted with integrity support (e.g., `--integrity hmac-sha256`) and the backing block device is shrinked, it cannot be opened with this error: `device-mapper: reload ioctl on failed: Invalid argument`.
To fix this issue without wiping the device again, it can be formatted with the previous master key (keeping the per-sector tags valid).
```
# cryptsetup luksDump /dev/sdX2 --dump-master-key --master-key-file=/tmp/masterkey-in-tmpfs.key
# cryptsetup luksFormat /dev/sdX2 --type luks2 --integrity hmac-sha256 --master-key-file=/tmp/masterkey-in-tmpfs.key --integrity-no-wipe
# rm /tmp/masterkey-in-tmpfs.key
```
|
dm-crypt/Device encryption | Keyfiles |
## Keyfiles
**Note:** This section describes using a plaintext keyfile. If you want to encrypt your keyfile giving you two factor authentication see [Using GPG or OpenSSL Encrypted Keyfiles](../../en/Dm-crypt/Specialties.html#Using_GPG,_LUKS,_or_OpenSSL_Encrypted_Keyfiles "Dm-crypt/Specialties") for details, but please still read this section.
**What is a keyfile?**
A keyfile is a file whose data is used as the passphrase to unlock an encrypted volume. That means if such a file is lost or changed, decrypting the volume may no longer be possible.
**Tip:** Define a passphrase in addition to the keyfile for backup access to encrypted volumes in the event the defined keyfile is lost or changed.
**Why use a keyfile?**
There are many kinds of keyfiles. Each type of keyfile used has benefits and disadvantages summarized below:
### Types of keyfiles
#### passphrase
This is a keyfile containing a simple passphrase. The benefit of this type of keyfile is that if the file is lost the data it contained is known and hopefully easily remembered by the owner of the encrypted volume. However the disadvantage is that this does not add any security over entering a passphrase during the initial system start.
Example: `1234`
**Note:** The keyfile containing the passphrase must not have a newline in it. One option is to create it using
```
# echo -n 'your_passphrase' > /path/to/keyfile
# chown root:root /path/to/keyfile; chmod 400 /path/to/keyfile
```
If the file contains special characters such as a backslash, rather than escaping these, it is recommended to simply edit the key file directly entering or pasting the passphrase and then remove the trailing newline with a handy perl one-liner:
```
# perl -pi -e 'chomp if eof' /path/to/keyfile
```
#### randomtext
This is a keyfile containing a block of random characters. The benefit of this type of keyfile is that it is much more resistant to dictionary attacks than a simple passphrase. An additional strength of keyfiles can be utilized in this situation which is the length of data used. Since this is not a string meant to be memorized by a person for entry, it is trivial to create files containing thousands of random characters as the key. The disadvantage is that if this file is lost or changed, it will most likely not be possible to access the encrypted volume without a backup passphrase.
Example: `fjqweifj830149-57 819y4my1-38t1934yt8-91m 34co3;t8y;9p3y-`
#### binary
This is a binary file that has been defined as a keyfile. When identifying files as candidates for a keyfile, it is recommended to choose files that are relatively static such as photos, music, video clips. The benefit of these files is that they serve a dual function which can make them harder to identify as keyfiles. Instead of having a text file with a large amount of random text, the keyfile would look like a regular image file or music clip to the casual observer. The disadvantage is that if this file is lost or changed, it will most likely not be possible to access the encrypted volume without a backup passphrase. Additionally, there is a theoretical loss of randomness when compared to a randomly generated text file. This is due to the fact that images, videos and music have some intrinsic relationship between neighboring bits of data that does not exist for a random text file. However this is controversial and has never been exploited publicly.
Example: images, text, video, ...
### Creating a keyfile with random characters
#### Storing the keyfile on a file system
A keyfile can be of arbitrary content and size.
Here [dd](../../en/Dd.html "Dd") is used to generate a keyfile of 2048 random bytes, storing it in the file `/etc/mykeyfile`:
```
# dd bs=512 count=4 if=/dev/random of=/etc/mykeyfile iflag=fullblock
```
If you are planning to store the keyfile on an external device, you can also simply change the outputfile to the corresponding directory:
```
# dd bs=512 count=4 if=/dev/random of=/media/usbstick/mykeyfile iflag=fullblock
```
To deny any access for other users than `root`:
```
# chmod 600 /etc/mykeyfile
```
##### Securely overwriting stored keyfiles
If you stored your temporary keyfile on a physical storage device, and want to delete it, remember to not just remove the keyfile later on, but use something like
```
# shred --remove --zero mykeyfile
```
to securely overwrite it. For overaged file systems like FAT or ext2 this will suffice while in the case of journaling file systems, flash memory hardware and other cases it is highly recommended to [wipe the entire device](../../en/Securely_wipe_disk.html "Securely wipe disk").
#### Storing the keyfile in ramfs
Alternatively, you can mount a ramfs for storing the keyfile temporarily:
```
# mount --mkdir -t ramfs ramfs /root/myramfs
# cd /root/myramfs
```
The advantage is that it resides in RAM and not on a physical disk, therefore it can not be recovered after unmounting the ramfs. After copying the keyfile to another secure and persistent file system, unmount the ramfs again with
```
# umount /root/myramfs
```
### Configuring LUKS to make use of the keyfile
Add a keyslot for the keyfile to the LUKS header:
```
# cryptsetup luksAddKey /dev/sda2 /etc/mykeyfile
```
```
Enter any LUKS passphrase:
key slot 0 unlocked.
Command successful.
```
### Manually unlocking a partition using a keyfile
Use the `--key-file` option when opening the LUKS device:
```
# cryptsetup open /dev/sda2 dm_name --key-file /etc/mykeyfile
```
### Unlocking the root partition at boot
This is simply a matter of configuring [mkinitcpio](../../en/Mkinitcpio.html "Mkinitcpio") to include the necessary modules or files and configuring the [cryptkey](../../en/Dm-crypt/System_configuration.html#cryptkey "Dm-crypt/System configuration") [kernel parameter](../../en/Kernel_parameters.html "Kernel parameter") to know where to find the keyfile.
Two cases are covered below:
1. Using a keyfile stored on an external medium (e.g. a USB stick)
2. Using a keyfile embedded in the initramfs
#### With a keyfile stored on an external media
##### Configuring mkinitcpio
You have to add the kernel module for the drive's [file system](../../en/File_systems.html "File system") to the [MODULES array](../../en/Mkinitcpio.html#MODULES "Mkinitcpio") in `/etc/mkinitcpio.conf`. For example, add `ext4` if the file system is [Ext4](../../en/Ext4.html "Ext4") or `vfat` in case it is [FAT](../../en/FAT.html "FAT"):
```
MODULES=(vfat)
```
If there are messages about bad superblock and bad codepage at boot, then you need an extra codepage module to be loaded. For instance, you may need `nls_iso8859-1` module for `iso8859-1` codepage.
[Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs").
##### Configuring the kernel parameters
* For a busybox-based initramfs using the [encrypt](../../en/Dm-crypt/System_configuration.html#Using_encrypt_hook "Dm-crypt/System configuration") hook, see [dm-crypt/System configuration#cryptkey](../../en/Dm-crypt/System_configuration.html#cryptkey "Dm-crypt/System configuration").
* For a systemd based initramfs using the [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") hook, see [dm-crypt/System configuration#rd.luks.key](../../en/Dm-crypt/System_configuration.html#rd.luks.key "Dm-crypt/System configuration").
#### With a keyfile embedded in the initramfs
**Warning:** Use an embedded keyfile **only** if you protect the keyfile sufficiently by:
* Using some form of authentication earlier in the boot process. Otherwise auto-decryption will occur, defeating completely the purpose of block device encryption.
* `/boot` is encrypted. Otherwise root on a different installation (including the [live environment](../../en/Installation_guide.html#Boot_the_live_environment "Installation guide")) can extract your key from the initramfs, and unlock the device without any other authentication.
This method allows to use a specially named keyfile that will be embedded in the [initramfs](../../en/Arch_boot_process.html#initramfs "Initramfs") and picked up by the `encrypt` [hook](../../en/Mkinitcpio.html#HOOKS "Mkinitcpio") to unlock the root file system (`cryptdevice`) automatically. It may be useful to apply when using the [GRUB early cryptodisk](../../en/GRUB.html#Encrypted_/boot "GRUB") feature, in order to avoid entering two passphrases during boot.
The `encrypt` hook lets the user specify a keyfile with the `cryptkey` kernel parameter: in the case of initramfs, the syntax is `rootfs:/path/to/keyfile`. See [dm-crypt/System configuration#cryptkey](../../en/Dm-crypt/System_configuration.html#cryptkey "Dm-crypt/System configuration"). Besides, this kernel parameter defaults to use `/crypto_keyfile.bin`, and if the initramfs contains a valid key with this name, decryption will occur automatically without the need to configure the `cryptkey` parameter.
If using `sd-encrypt` instead of `encrypt`, specify the location of the keyfile with the `rd.luks.key` kernel parameter: in the case of initramfs, the syntax is `/path/to/keyfile`. See [dm-crypt/System configuration#rd.luks.key](../../en/Dm-crypt/System_configuration.html#rd.luks.key "Dm-crypt/System configuration"). This kernel parameter defaults to using `/etc/cryptsetup-keys.d/name.key` (where `name` is the `dm_name` used for decryption in [#Encrypting devices with cryptsetup](#Encrypting_devices_with_cryptsetup)) and can be omitted if initramfs contains a valid key with this path.
[Generate the keyfile](#Creating_a_keyfile_with_random_characters), give it suitable permissions and [add it as a LUKS key](#Adding_LUKS_keys):
```
# dd bs=512 count=4 if=/dev/random of=/crypto_keyfile.bin iflag=fullblock
# chmod 600 /crypto_keyfile.bin
# cryptsetup luksAddKey /dev/sdX# /crypto_keyfile.bin
```
**Note:** The initramfs is generated by mkinitcpio with `600` [permissions](../../en/File_permissions_and_attributes.html "Permissions") by default, so regular users are not able to read the keyfile via the generated initramfs.
Include the key in [mkinitcpio's FILES array](../../en/Mkinitcpio.html#BINARIES_and_FILES "Mkinitcpio"):
```
/etc/mkinitcpio.conf
```
```
FILES=(/crypto_keyfile.bin)
```
Finally [regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs").
On the next reboot you should only have to enter your container decryption passphrase once.
([source](https://www.pavelkogan.com/2014/05/23/luks-full-disk-encryption/#bonus-login-once))
[Category](../../Special:Categories.html "Special:Categories"):
* [Data-at-rest encryption](../../en/Category:Data-at-rest_encryption.html "Category:Data-at-rest encryption")
Hidden categories:
* [Pages or sections flagged with Template:Expansion](../../en/Category:Pages_or_sections_flagged_with_Template:Expansion.html "Category:Pages or sections flagged with Template:Expansion")
* [Pages or sections flagged with Template:Out of date](../../en/Category:Pages_or_sections_flagged_with_Template:Out_of_date.html "Category:Pages or sections flagged with Template:Out of date")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Dm-crypt/Device_encryption&oldid=808739>"
- This page was last edited on 19 May 2024, at 16:23.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
dm-crypt/Drive preparation | Intro |
# dm-crypt/Drive preparation
\[ ] 5 languages
* [Español](../../es/Dm-crypt/Drive_preparation.html "Dm-crypt (Español)/Drive preparation – español")
* [日本語](https://wiki.archlinux.jp/index.php/Dm-crypt/%E3%83%89%E3%83%A9%E3%82%A4%E3%83%96%E3%81%AE%E6%BA%96%E5%82%99 "Dm-crypt/ドライブの準備 – 日本語")
* [Polski](../../pl/Dm-crypt/Drive_preparation.html "Dm-crypt (Polski)/Drive preparation – polski")
* [Português](../../pt/Dm-crypt/Drive_preparation.html "Dm-crypt (Português)/Drive preparation – português")
* [中文(简体)](https://wiki.archlinuxcn.org/wiki/Dm-crypt/Drive_preparation "Dm-crypt/Drive preparation – 中文(简体)")
From ArchWiki
< [Dm-crypt](../../en/Dm-crypt.html "Dm-crypt")
Related articles
* [Data-at-rest encryption#Preparing the disk](../../en/Data-at-rest_encryption.html#Preparing_the_disk "Data-at-rest encryption")
* [Securely wipe disk](../../en/Securely_wipe_disk.html "Securely wipe disk")
Before encrypting a drive, it is recommended to perform a secure erase by overwriting the entire device with random data. To prevent cryptographic attacks or unwanted [file recovery](../../en/File_recovery.html "File recovery"), this data is ideally indistinguishable from data later written by dm-crypt. For a more comprehensive discussion see [Data-at-rest encryption#Preparing the disk](../../en/Data-at-rest_encryption.html#Preparing_the_disk "Data-at-rest encryption").
|
dm-crypt/Drive preparation | Secure erasure of the drive |
## Secure erasure of the drive
In deciding which method to use for secure erasure of a drive, remember that this needs only to be performed once for as long as the drive is continuously used as an encrypted device.
**Warning:**
* Make appropriate backups of valuable data prior to starting!
* Do not overwrite an [SSD](../../en/Solid_state_drive.html "SSD") with random data if you plan to [use TRIM](../../en/Dm-crypt/Specialties.html#Discard/TRIM_support_for_solid_state_drives_\(SSD\) "Dm-crypt/Specialties"). Unused blocks will be marked as empty after the first TRIM and eventually erased thus undoing your performed actions.
**Note:** When wiping large amount of data, the process will take several hours to several days to complete.
**Tip:**
* Check that your Advanced Format drives are using the [optimal logical sector size](../../en/Advanced_Format.html "Advanced Format") before proceeding.
* The process of filling an encrypted drive can take over a day to complete on a multi-terabyte device. In order not to leave the machine unusable during the operation, it may be worth to do it from a system already installed on another drive, rather than from the live Arch installation system.
* For [SSDs](../../en/Solid_state_drive.html "SSD"), as a best effort to minimize [flash memory](../../en/Securely_wipe_disk.html#Flash_memory "Securely wipe disk") cache artifacts, consider performing a [SSD memory cell clearing](../../en/Solid_state_drive/Memory_cell_clearing.html "SSD memory cell clearing") *prior* to instructions below.
### Generic methods
For detailed instructions on how to erase and prepare a drive consult [Securely wipe disk](../../en/Securely_wipe_disk.html "Securely wipe disk").
### dm-crypt specific methods
The following two methods are specific for dm-crypt and are mentioned because they are very fast and can be performed after a partition setup too.
The [cryptsetup FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions#2-setup) (item 2.19 "*How can I wipe a device with crypto-grade randomness?*") mentions a very simple procedure to use an existing dm-crypt-volume to wipe all free space accessible on the underlying block device with random data by acting as a simple pseudorandom number generator. It is also claimed to protect against disclosure of usage patterns. That is because encrypted data is practically indistinguishable from random.
#### dm-crypt wipe on an empty device or partition
First, create a temporary encrypted container on the partition (using the form `sdXY`) or complete device (using the form `sdX`) to be encrypted. It could be worth changing the cipher used from the standard aes-cbc to aes-xts, as it might be significantly faster (check with `cryptsetup benchmark`):
```
# cryptsetup open --type plain -d /dev/urandom --sector-size 4096 /dev/block-device to_be_wiped
```
You can verify that it exists:
```
# lsblk
```
```
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 1.8T 0 disk
└─to_be_wiped 252:0 0 1.8T 0 crypt
```
Wipe the container with zeros. A use of `if=/dev/urandom` is not required as the encryption cipher is used for randomness.
```
# dd if=/dev/zero of=/dev/mapper/to_be_wiped status=progress bs=1M
```
```
dd: writing to ‘/dev/mapper/to_be_wiped’: No space left on device
```
**Tip:** To perform a check of the operation, zero the partition before creating the wipe container. After the wipe command `blockdev --getsize64 /dev/mapper/container` can be used to get the exact container size as root. After the container has been closed *od* can be used to spotcheck whether the wipe overwrote the zeroed sectors. For example, `# od -j $((containersize - blocksize)) /dev/nvme0n1` to view the wipe completed to the end.
Finally, close the temporary container:
```
# cryptsetup close to_be_wiped
```
When encrypting an entire system, the next step is [#Partitioning](#Partitioning). If just encrypting a partition, continue [dm-crypt/Encrypting a non-root file system#Partition](../../en/Dm-crypt/Encrypting_a_non-root_file_system.html#Partition "Dm-crypt/Encrypting a non-root file system").
#### dm-crypt wipe free space after installation
Users who did not have time for the wipe procedure before [installation](../../en/Dm-crypt/Encrypting_an_entire_system.html "Dm-crypt/Encrypting an entire system"), can achieve a similar effect once the encrypted system is booted and the filesystems are mounted. However, consider if the concerned filesystem may have set up reserved space, e.g. for the root user, or another [disk quota](../../en/Disk_quota.html "Disk quota") mechanism, that that may limit the wipe even when performed by the root user: some parts of the underlying block device might not get written to at all.
To execute the wipe, temporarily fill the remaining free space of the partition by writing to a file inside the encrypted container:
```
# dd if=/dev/zero of=/file/in/container status=progress
```
```
dd: writing to ‘/file/in/container’: No space left on device
```
Sync the cache to disk and then delete the file to reclaim the free space.
```
# sync
# rm /file/in/container
```
The above process has to be repeated for every partition blockdevice created and filesystem in it. For example, setting-up [LVM on LUKS](../../en/Dm-crypt/Encrypting_an_entire_system.html#LVM_on_LUKS "Dm-crypt/Encrypting an entire system"), the process has to be performed for every logical volume.
#### dm-crypt wipe free space after installation (via re-encryption)
Alternatively, for users who want to completely wipe free space without re-installation, this can be achieved by [re-encrypting LUKS devices](../../en/Dm-crypt/Device_encryption.html#Re-encrypting_devices "Dm-crypt/Device encryption"). It needs to be performed once per LUKS device. But please note that this process can be slower (e.g \~50MB/s on a desktop HDD).
### Wipe LUKS header
A partition using LUKS consists of two parts: the header and the encrypted data. The header contains keys and cryptographic parameters without which it is practically impossible to recover the data. If creating a new partition or decommissioning the drive it *may* be sufficient to remove that part instead of wiping the whole device. For caveats see the paragraph at the end of this subsection.
**Warning:** The operation is irreversible, so be careful.
To erase all keys use the following command:
```
# cryptsetup erase device
```
Make sure there is no active slots left by invoking:
```
# cryptsetup luksDump device
```
Additionally the LUKS header itself may be removed to prevent `cryptsetup` from detecting it in the future, by invoking [wipefs](../../en/Device_file.html#wipefs "Wipefs") after the keys are erased:
```
# wipefs -a device
```
The encrypted data remains in place. As of 2020 there is no known practical way of decrypting the data, but that may change in the future. It is up to the user to weight security and privacy against the time needed to perform a proper wiping of the entire drive.
On some storage media, in particular flash-based, it may be impossible to reliably overwrite data. The LUKS header with keys may remain stored in a location inaccessible to the operating system (e.g. a drive-cache). If that is a concern, [ATA Secure Erase](../../en/Securely_wipe_disk.html#hdparm "Securely Wipe HDD") must be used. The operation is supposed to erase all blocks on the device, including those not visible to software. See [cryptsetup FAQ 5.19](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions#5-security-aspects) for details.
|
dm-crypt/Drive preparation | Partitioning |
## Partitioning
This section only applies when encrypting an entire system. After the drive(s) has/have been securely overwritten, a proper partitioning scheme will have to be accurately chosen, taking into account the requirements of dm-crypt, and the effects that the various choices will have on the management of the resulting system.
It is important to note from now that in [almost](#Boot_partition_\(GRUB\)) every case there has to be a separate partition for `/boot` that must remain unencrypted, because the bootloader needs to access the `/boot` directory where it will load the initramfs/encryption modules needed to load the rest of the system (see [mkinitcpio](../../en/Mkinitcpio.html "Mkinitcpio") for details). If this raises security concerns, see [dm-crypt/Specialties#Securing the unencrypted boot partition](../../en/Dm-crypt/Specialties.html#Securing_the_unencrypted_boot_partition "Dm-crypt/Specialties").
Another important factor to take into account is how the swap area and system suspension will be handled, see [dm-crypt/Swap encryption](../../en/Dm-crypt/Swap_encryption.html "Dm-crypt/Swap encryption").
### Physical partitions
In the simplest case, the encrypted layers can be based directly on the physical partitions; see [Partitioning](../../en/Partitioning.html "Partitioning") for the methods to create them. Just like in an unencrypted system, a root partition is sufficient, besides another for `/boot` as noted above. This method allows deciding which partitions to encrypt and which to leave unencrypted, and works the same regardless of the number of disks involved. It will also be possible to add or remove partitions in the future, but resizing a partition will be limited by the size of the disk that is hosting it. Finally note that separate passphrases or keys are required to open each encrypted partition, even though this can be automated during boot using the `crypttab` file, see [Dm-crypt/System configuration#crypttab](../../en/Dm-crypt/System_configuration.html#crypttab "Dm-crypt/System configuration").
### Stacked block devices
If more flexibility is needed, though, dm-crypt can coexist with other stacked block devices like [LVM](../../en/LVM.html "LVM") and [RAID](../../en/RAID.html "RAID"). The encrypted containers can either reside below or on top of other stacked block devices:
* If the LVM/RAID devices are created on top of the encrypted layer, it will be possible to add, remove and resize the file systems of the same encrypted partition liberally, and only one key or passphrase will be required for all of them. Since the encrypted layer resides on a physical partition, though, it will not be possible to exploit the ability of LVM and RAID to span multiple disks.
* If the encrypted layer is created on top of LVM/RAID devices, it will still be possible to reorganize the file systems in the future, but with added complexity, since the encryption layers will have to be adjusted accordingly. Moreover, separate passphrases or keys will be required to open each encrypted device. This, however, is the only choice for systems that need encrypted file systems to span multiple disks.
### Btrfs subvolumes
[Btrfs](../../en/Btrfs.html "Btrfs")'s built-in [subvolumes feature](../../en/Btrfs.html#Subvolumes "Btrfs") can be used with dm-crypt, fully replacing the need for LVM if no other file systems are required.
### Boot partition (GRUB)
See [dm-crypt/Encrypting an entire system#Encrypted boot partition (GRUB)](../../en/Dm-crypt/Encrypting_an_entire_system.html#Encrypted_boot_partition_\(GRUB\) "Dm-crypt/Encrypting an entire system").
[Category](../../Special:Categories.html "Special:Categories"):
* [Data-at-rest encryption](../../en/Category:Data-at-rest_encryption.html "Category:Data-at-rest encryption")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Dm-crypt/Drive_preparation&oldid=808468>"
- This page was last edited on 16 May 2024, at 19:55.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
dm-crypt/Encrypting a non-root file system | Intro |
# dm-crypt/Encrypting a non-root file system
\[ ] 5 languages
* [Español](../../es/Dm-crypt/Encrypting_a_non-root_file_system.html "Dm-crypt (Español)/Encrypting a non-root file system – español")
* [日本語](https://wiki.archlinux.jp/index.php/Dm-crypt/root_%E4%BB%A5%E5%A4%96%E3%81%AE%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E3%81%AE%E6%9A%97%E5%8F%B7%E5%8C%96 "Dm-crypt/root 以外のファイルシステムの暗号化 – 日本語")
* [Polski](../../pl/Dm-crypt/Encrypting_a_non-root_file_system.html "Dm-crypt (Polski)/Encrypting a non-root file system – polski")
* [Português](../../pt/Dm-crypt/Encrypting_a_non-root_file_system.html "Dm-crypt (Português)/Encrypting a non-root file system – português")
* [中文(简体)](https://wiki.archlinuxcn.org/wiki/Dm-crypt/Encrypting_a_non-root_file_system "Dm-crypt/Encrypting a non-root file system – 中文(简体)")
From ArchWiki
< [Dm-crypt](../../en/Dm-crypt.html "Dm-crypt")
The following are examples of encrypting a secondary, i.e. non-root, filesystem with dm-crypt.
|
dm-crypt/Encrypting a non-root file system | Overview |
## Overview
Encrypting a secondary filesystem usually protects only sensitive data while leaving the operating system and program files unencrypted. This is useful for encrypting an external medium, such as a USB drive, so that it can be moved to different computers securely. One might also choose to encrypt sets of data separately according to who has access to it.
Because dm-crypt is a [block-level encryption](../../en/Data-at-rest_encryption.html#Block_device_encryption "Data-at-rest encryption") layer, it only encrypts whole [block devices](../../en/Device_file.html#Block_devices "Block device"), e.g. [partitions](#Partition) and [loop devices](#File_container). Encrypting individual files requires a filesystem-level encryption layer, such as [eCryptfs](../../en/ECryptfs.html "ECryptfs") or [EncFS](../../en/EncFS.html "EncFS"). See [Data-at-rest encryption](../../en/Data-at-rest_encryption.html "Data-at-rest encryption") for general information about securing private data.
|
dm-crypt/Encrypting a non-root file system | Partition |
## Partition
This example covers the encryption of the `/home` partition, but it can be applied to any other comparable non-root partition containing user data.
**Tip:** You can either have a single user's `/home` directory on a partition, or create a common partition for all user's `/home` directories.
It is assumed that the [partition already exists](../../en/Partitioning.html "Partitioning"). If it contained data before, you may consider [securely erasing the partition (dm-crypt specific methods)](../../en/Dm-crypt/Drive_preparation.html#dm-crypt_specific_methods "Dm-crypt/Drive preparation"). Erasing a single partition instead of the entire disk may still leak some data.
Then setup the LUKS header with:
```
# cryptsetup options luksFormat device
```
Replace `device` with the previously created partition. See [Dm-crypt/Device encryption#Encryption options for LUKS mode](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_LUKS_mode "Dm-crypt/Device encryption") for details like the available `options`.
To gain access to the encrypted partition, unlock it with the device mapper, using:
```
# cryptsetup open device name
```
After unlocking the partition, it will be available at `/dev/mapper/name`. Now create a [file system](../../en/File_systems.html "File system") of your choice with:
```
# mkfs.fstype /dev/mapper/name
```
Mount the file system to `/home`, or if it should be accessible to only one user to `/home/username`, see [#Manual mounting and unmounting](#Manual_mounting_and_unmounting).
**Tip:** Unmount and mount once to verify that the mapping is working as intended.
### Manual mounting and unmounting
To mount the partition:
```
# cryptsetup open device name
# mount -t fstype /dev/mapper/name /mnt/home
```
To unmount it:
```
# umount /mnt/home
# cryptsetup close name
```
**Tip:** [GVFS](../../en/File_manager_functionality.html#Mounting "GVFS") can also mount encrypted partitions. One can use a file manager with gvfs support (e.g. [Thunar](../../en/Thunar.html "Thunar")) to mount the partition, and a password dialog will pop-up. For other desktops, [zulucrypt](https://aur.archlinux.org/packages/zulucrypt/)AUR also provides a GUI.
### Automated unlocking and mounting
There are three different solutions for automating the process of unlocking the partition and mounting its filesystem.
#### At boot time
Using the `/etc/crypttab` configuration file, unlocking happens at boot time by systemd's automatic parsing. This is the recommended solution if you want to use one common partition for all user's home partitions or automatically mount another encrypted block device.
See [Dm-crypt/System configuration#crypttab](../../en/Dm-crypt/System_configuration.html#crypttab "Dm-crypt/System configuration") for references and [Dm-crypt/System configuration#Mounting at boot time](../../en/Dm-crypt/System_configuration.html#Mounting_at_boot_time "Dm-crypt/System configuration") for an example setup.
#### On user login
* Using [pam-exec](../../en/Dm-crypt/Mounting_at_login.html "Dm-crypt/Mounting at login"): recommended if you want to have a single user's home directory on a partition.
* Using [pam\_mount](../../en/Pam_mount.html "Pam mount").
|
dm-crypt/Encrypting a non-root file system | File container |
## File container
Cryptsetup operates with devices, therefore a loop device is required when using a file container. But *cryptsetup* can take care of the loop device management in the background (see [Gentoo:Custom Initramfs#Encrypted keyfile](https://wiki.gentoo.org/wiki/Custom_Initramfs#Encrypted_keyfile "gentoo:Custom Initramfs")), the user is not required to invoke `losetup` manually.
First, start by creating an encrypted file container with [dd](../../en/Dd.html "Dd"), using an appropriate [random number generator](../../en/Random_number_generation.html "Random number generator"):
```
$ dd if=/dev/urandom of=bigsecret.img bs=100M count=1 iflag=fullblock
```
This will create the file `bigsecret.img` with a size of 100 mebibytes.
Make sure to not omit the `iflag=fullblock` option, otherwise *dd* might return a partial read. See [dd#Partial read: copied data is smaller than requested](../../en/Dd.html#Partial_read:_copied_data_is_smaller_than_requested "Dd") for details.
To avoid having to [resize](../../en/Dm-crypt/Device_encryption.html#Loopback_file_system "Dm-crypt/Device encryption") the container later on, make sure to make it larger than the total size of the files to be encrypted, plus internal file-system/metadata overhead, plus LUKS header. If you are going to use LUKS mode, its metadata header alone requires up to 16 mebibytes. Creating a file smaller than the LUKS2 header (16 MiB) will give a `Requested offset is beyond real size of device bigsecret.img` error when trying to open the device.
The subsequent steps are the same as described in [#Partition](#Partition), but instead of using a `device` use `bigsecret.img`.
In the background, cryptsetup will take care of finding a free loop device and attaching the file to it. After unmouting, the file container should be closed accordingly; cryptsetup will also detach the used loop device afterwards.
**Tip:** Containers with *dm-crypt* can be very flexible. Have a look at the features and documentation of [Tomb](../../en/Tomb.html "Tomb"). It provides a *dm-crypt* script wrapper for fast and flexible handling.
### Manual mounting and unmounting using losetup
To manually mount a file container with a LUKS and an ext4 filesystem inside, first find an unused loop device:
```
# losetup --find
```
Then attach the file container to a loop device, e.g. `loop0`:
```
# losetup /dev/loop0 bigsecret.img
```
**Note:** If it gives you the error `/dev/loop0: No such file or directory`, you need to first load the kernel module with `modprobe loop` as root. These days (Kernel 3.2) loop devices are created on demand. Ask for a new loop device with `losetup -f` as root.
Now proceed with the normal cryptsetup operation:
```
# cryptsetup open /dev/loop0 secret
# mount -t ext4 /dev/mapper/secret /mnt/secret
```
Proceed in reverse order to unmount the container properly:
```
# umount /mnt/secret
# cryptsetup close secret
```
To detach the used loop device:
```
# losetup --detach /dev/loop0
```
[Category](../../Special:Categories.html "Special:Categories"):
* [Data-at-rest encryption](../../en/Category:Data-at-rest_encryption.html "Category:Data-at-rest encryption")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Dm-crypt/Encrypting_a_non-root_file_system&oldid=793199>"
- This page was last edited on 25 November 2023, at 11:08.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
dm-crypt/Encrypting an entire system | Intro |
# dm-crypt/Encrypting an entire system
\[ ] 6 languages
* [Deutsch](https://wiki.archlinux.de/title/Systemverschl%C3%BCsselung_mit_dm-crypt "Systemverschlüsselung mit dm-crypt – Deutsch")
* [Español](../../es/Dm-crypt/Encrypting_an_entire_system.html "Dm-crypt (Español)/Encrypting an entire system – español")
* [日本語](https://wiki.archlinux.jp/index.php/Dm-crypt/%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E5%85%A8%E4%BD%93%E3%81%AE%E6%9A%97%E5%8F%B7%E5%8C%96 "Dm-crypt/システム全体の暗号化 – 日本語")
* [Polski](../../pl/Dm-crypt/Encrypting_an_entire_system.html "Dm-crypt (Polski)/Encrypting an entire system – polski")
* [Português](../../pt/Dm-crypt/Encrypting_an_entire_system.html "Dm-crypt (Português)/Encrypting an entire system – português")
* [中文(简体)](https://wiki.archlinuxcn.org/wiki/dm-crypt/%E5%8A%A0%E5%AF%86%E6%95%B4%E4%B8%AA%E7%B3%BB%E7%BB%9F "dm-crypt/加密整个系统 – 中文(简体)")
From ArchWiki
< [Dm-crypt](../../en/Dm-crypt.html "Dm-crypt")
The following are examples of common scenarios of full system encryption with *dm-crypt*. They explain all the adaptations that need to be done to the normal [installation procedure](../../en/Installation_guide.html "Installation guide"). All the necessary tools are on the [installation image](https://archlinux.org/download/).
If you want to encrypt an existing unencrypted file system, see [dm-crypt/Device encryption#Encrypt an existing unencrypted file system](../../en/Dm-crypt/Device_encryption.html#Encrypt_an_existing_unencrypted_file_system "Dm-crypt/Device encryption").
|
dm-crypt/Encrypting an entire system | Overview |
## Overview
Securing a root file system is where *dm-crypt* excels, feature and performance-wise. Unlike selectively encrypting non-root file systems, an encrypted root file system can conceal information such as which programs are installed, the usernames of all user accounts, and common data-leakage vectors such as [mlocate](../../en/Locate.html "Mlocate") and `/var/log/`. Furthermore, an encrypted root file system makes tampering with the system far more difficult, as everything except the [boot loader](../../en/Arch_boot_process.html#Boot_loader "Boot loader") and (usually) the kernel is encrypted.
All scenarios illustrated in the following share these advantages, other pros and cons differentiating them are summarized below:
| Scenarios | Advantages | Disadvantages |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [#LUKS on a partition](#LUKS_on_a_partition)shows a basic and straightforward set-up for a fully LUKS encrypted root. | * Simple partitioning and setup
* On a GPT partitioned disk, [systemd can auto-mount](../../en/Systemd.html#GPT_partition_automounting "Systemd") the root partition. | - Inflexible; disk-space to be encrypted has to be pre-allocated |
| [#LUKS on a partition with TPM2 and Secure Boot](#LUKS_on_a_partition_with_TPM2_and_Secure_Boot)Similar to the example above, with Secure Boot and TPM2 providing additional layers of security. | Same advantages as above, and- Secure Boot protects against [Evil maid attacks](https://en.wikipedia.org/wiki/Evil_maid_attack "wikipedia:Evil maid attack")
- TPM2 prevents the system from being unlocked if Secure Boot is disabled or modified | Same disadvantages as above, and- LUKS volume is automatically unlocked (only if the system was not tampered with). |
| [#LVM on LUKS](#LVM_on_LUKS)achieves partitioning flexibility by using LVM inside a single LUKS encrypted partition. | * Simple partitioning with knowledge of LVM
* Only one key required to unlock all volumes (e.g. easy resume-from-disk setup)
* Volume layout not visible when locked
* Easiest method to allow [suspension to disk](../../en/Dm-crypt/Swap_encryption.html#With_suspend-to-disk_support "Dm-crypt/Swap encryption") | - LVM adds an additional mapping layer and hook
- Less useful, if a singular volume should receive a separate key |
| [#LUKS on LVM](#LUKS_on_LVM)uses dm-crypt only after the LVM is setup. | * LVM can be used to have encrypted volumes span multiple disks
* Easy mix of un-/encrypted volume groups | - Complex; changing volumes requires changing encryption mappers too
- Volumes require individual keys
- LVM layout is visible when locked
- Slower boot time; each encrypted LV must be unlocked seperately |
| [#LUKS on software RAID](#LUKS_on_software_RAID)uses dm-crypt only after RAID is setup. | * Analogous to LUKS on LVM | - Analogous to LUKS on LVM |
| [#Plain dm-crypt](#Plain_dm-crypt)uses dm-crypt plain mode, i.e. without a LUKS header and its options for multiple keys. This scenario also employs USB devices for `/boot` and key storage, which may be applied to the other scenarios. | * Data resilience for cases where a LUKS header may be damaged
* Allows [Full Disk Encryption](https://en.wikipedia.org/wiki/Disk_encryption#Full_disk_encryption "wikipedia:Disk encryption")
* Helps addressing [problems](../../en/Dm-crypt/Specialties.html#Discard/TRIM_support_for_solid_state_drives_\(SSD\) "Dm-crypt/Specialties") with SSDs | - High care to all encryption parameters is required
- Single encryption key and no option to change it |
| [#Encrypted boot partition (GRUB)](#Encrypted_boot_partition_\(GRUB\))shows how to encrypt the boot partition using the GRUB bootloader. This scenario also employs an EFI system partition, which may be applied to the other scenarios. | * Same advantages as the scenario the installation is based on (LVM on LUKS for this particular example)
* Less data is left unencrypted, i.e. the boot loader and the EFI system partition, if present | - Same disadvantages as the scenario the installation is based on (LVM on LUKS for this particular example)
- More complicated configuration
- Not supported by other boot loaders |
| [#Root on ZFS](#Root_on_ZFS) | | |
While all above scenarios provide much greater protection from outside threats than encrypted secondary file systems, they also share a common disadvantage: any user in possession of the encryption key is able to decrypt the entire drive, and therefore can access other users' data. If that is of concern, it is possible to use a combination of block device and stacked file system encryption and reap the advantages of both. See [Data-at-rest encryption](../../en/Data-at-rest_encryption.html "Data-at-rest encryption") to plan ahead.
See [dm-crypt/Drive preparation#Partitioning](../../en/Dm-crypt/Drive_preparation.html#Partitioning "Dm-crypt/Drive preparation") for a general overview of the partitioning strategies used in the scenarios.
Another area to consider is whether to set up an encrypted swap partition and what kind. See [dm-crypt/Swap encryption](../../en/Dm-crypt/Swap_encryption.html "Dm-crypt/Swap encryption") for alternatives.
If you anticipate to protect the system's data not only against physical theft, but also have a requirement of precautions against logical tampering, see [dm-crypt/Specialties#Securing the unencrypted boot partition](../../en/Dm-crypt/Specialties.html#Securing_the_unencrypted_boot_partition "Dm-crypt/Specialties") for further possibilities after following one of the scenarios.
For [solid state drives](../../en/Solid_state_drive.html "Solid state drive") you might want to consider enabling TRIM support, but be warned, there are potential security implications. See [dm-crypt/Specialties#Discard/TRIM support for solid state drives (SSD)](../../en/Dm-crypt/Specialties.html#Discard/TRIM_support_for_solid_state_drives_\(SSD\) "Dm-crypt/Specialties") for more information.
**Warning:**
* In any scenario, never use file system repair software such as [fsck](../../en/Fsck.html "Fsck") directly on an encrypted volume, or it will destroy any means to recover the key used to decrypt your files. Such tools must be used on the decrypted (opened) device instead.
* For the LUKS2 format:
* GRUB's support for LUKS2 is limited; see [GRUB#Encrypted /boot](../../en/GRUB.html#Encrypted_/boot "GRUB") for details. Use LUKS1 (`cryptsetup luksFormat --type luks1`) for partitions that GRUB will need to unlock.
* The LUKS2 format has a high RAM usage per design, defaulting to 1GB per encrypted mapper. Machines with low RAM and/or multiple LUKS2 partitions unlocked in parallel may error on boot. See the `--pbkdf-memory` option to control memory usage.[\[1\]](https://gitlab.com/cryptsetup/cryptsetup/issues/372)
|
dm-crypt/Encrypting an entire system | LUKS on a partition |
## LUKS on a partition
This example covers a full system encryption with *dm-crypt* + LUKS in a simple partition layout:
```
+-----------------------+------------------------+-----------------------+
| Boot partition | LUKS2 encrypted root | Optional free space |
| | partition | for additional |
| | | partitions to be set |
| /boot | / | up later |
| | | |
| | /dev/mapper/root | |
| |------------------------| |
| /dev/sda1 | /dev/sda2 | |
+-----------------------+------------------------+-----------------------+
```
The first steps can be performed directly after booting the Arch Linux install image.
### Preparing the disk
Prior to creating any partitions, you should inform yourself about the importance and methods to securely erase the disk, described in [dm-crypt/Drive preparation](../../en/Dm-crypt/Drive_preparation.html "Dm-crypt/Drive preparation").
Then create the needed partitions, at least one for `/` (e.g. `/dev/sda2`) and `/boot` (`/dev/sda1`). See [Partitioning](../../en/Partitioning.html "Partitioning").
### Preparing non-boot partitions
This and the next section replace the instructions of [Installation guide#Format the partitions](../../en/Installation_guide.html#Format_the_partitions "Installation guide").
The following commands create and mount the encrypted root partition. They correspond to the procedure described in detail in [dm-crypt/Encrypting a non-root file system#Partition](../../en/Dm-crypt/Encrypting_a_non-root_file_system.html#Partition "Dm-crypt/Encrypting a non-root file system") (which, despite the title, *can* be applied to root partitions, as long as [mkinitcpio](#Configuring_mkinitcpio) and the [boot loader](#Configuring_the_boot_loader) are correctly configured). If you want to use particular non-default encryption options (e.g. cipher, key length), see the [encryption options](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_LUKS_mode "Dm-crypt/Device encryption") before executing the first command. For information on changing the default sector size, see [dm-crypt/Device encryption#Sector size](../../en/Dm-crypt/Device_encryption.html#Sector_size "Dm-crypt/Device encryption").
```
# cryptsetup -y -v luksFormat /dev/sda2
# cryptsetup open /dev/sda2 root
# mkfs.ext4 /dev/mapper/root
# mount /dev/mapper/root /mnt
```
Check the mapping works as intended:
```
# umount /mnt
# cryptsetup close root
# cryptsetup open /dev/sda2 root
# mount /dev/mapper/root /mnt
```
If you created separate partitions (e.g. `/home`), these steps have to be adapted and repeated for all of them, *except* for `/boot`. See [dm-crypt/Encrypting a non-root file system#Automated unlocking and mounting](../../en/Dm-crypt/Encrypting_a_non-root_file_system.html#Automated_unlocking_and_mounting "Dm-crypt/Encrypting a non-root file system") on how to handle additional partitions at boot.
Note that each block device requires its own passphrase. This may be inconvenient, because it results in a separate passphrase to be input during boot. An alternative is to use a keyfile stored in the root partition to unlock the separate partition via `crypttab`. See [dm-crypt/Device encryption#Using LUKS to format partitions with a keyfile](../../en/Dm-crypt/Device_encryption.html#Using_LUKS_to_format_partitions_with_a_keyfile "Dm-crypt/Device encryption") for instructions.
### Preparing the boot partition
What you do have to setup is a non-encrypted `/boot` partition, which is needed for an encrypted root. For an ordinary boot partition on BIOS systems, for example, execute:
```
# mkfs.ext4 /dev/sda1
```
or for an [EFI system partition](../../en/EFI_system_partition.html "EFI system partition") on UEFI systems:
```
# mkfs.fat -F32 /dev/sda1
```
Afterwards create the directory for the mountpoint and mount the partition:
```
# mount --mkdir /dev/sda1 /mnt/boot
```
### Mounting the devices
At [Installation guide#Mount the file systems](../../en/Installation_guide.html#Mount_the_file_systems "Installation guide") you will have to mount the mapped devices, not the actual partitions. Of course `/boot`, which is not encrypted, will still have to be mounted directly. It should be mounted at `/mnt`.
### Configuring mkinitcpio
Before following [Installation guide#Initramfs](../../en/Installation_guide.html#Initramfs "Installation guide") you must do the following to your new system:
If using the default busybox-based initramfs, add the `keyboard` and `encrypt` hooks to [mkinitcpio.conf](../../en/Mkinitcpio.html#Configuration "Mkinitcpio.conf"). If you use a non-US console keymap or a non-default console font, additionally add the `keymap` and `consolefont` hooks, respectively.
```
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block encrypt filesystems fsck)
```
If using a systemd-based initramfs, instead add the `keyboard` and `sd-encrypt` hooks. If you use a non-US console keymap or a non-default console font, additionally add the `sd-vconsole` hook.
```
HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt filesystems fsck)
```
[Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs") after saving the changes. See [dm-crypt/System configuration#mkinitcpio](../../en/Dm-crypt/System_configuration.html#mkinitcpio "Dm-crypt/System configuration") for details and other hooks that you may need.
### Configuring the boot loader
In order to unlock the encrypted root partition at boot, the following [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters") need to be set by the boot loader:
```
cryptdevice=UUID=device-UUID:root root=/dev/mapper/root
```
If using the [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") hook, the following need to be set instead:
```
rd.luks.name=device-UUID=root root=/dev/mapper/root
```
The `device-UUID` refers to the UUID of the LUKS superblock, in this example it is the UUID of `/dev/sda2`. See [Persistent block device naming](../../en/Persistent_block_device_naming.html "Persistent block device naming") for details.
Also see [dm-crypt/System configuration#Kernel parameters](../../en/Dm-crypt/System_configuration.html#Kernel_parameters "Dm-crypt/System configuration") for more details.
**Tip:** If the root partition is on the same disk as the `/boot` partition and your UEFI boot loader supports [GPT partition automounting](../../en/Systemd.html#GPT_partition_automounting "Systemd"), you can configure the [partition type GUID](https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs "wikipedia:GUID Partition Table") (type should be "Root partition", not "LUKS partition") and rely on [systemd-gpt-auto-generator(8)](https://man.archlinux.org/man/systemd-gpt-auto-generator.8) instead of using the kernel parameters.
|
dm-crypt/Encrypting an entire system | LUKS on a partition with TPM2 and Secure Boot |
## LUKS on a partition with TPM2 and Secure Boot
This example is similar to [#LUKS on a partition](#LUKS_on_a_partition), but integrates the use of [Secure Boot](../../en/Unified_Extensible_Firmware_Interface/Secure_Boot.html "Secure Boot") and a [Trusted Platform Module](../../en/Trusted_Platform_Module.html "Trusted Platform Module") (TPM), enhancing the overall security of the boot process.
In this configuration, only the [EFI system partition](../../en/EFI_system_partition.html "EFI system partition") remains unencrypted, housing a [unified kernel image](../../en/Unified_kernel_image.html "Unified kernel image") and [systemd-boot](../../en/Systemd-boot.html "Systemd-boot")—both signed for use with Secure Boot. The TPM plays a crucial role by monitoring the Secure Boot state. If Secure Boot is disabled or its key databases are tampered with, the encrypted partition will not unlock. This approach is akin to BitLocker on Windows or FileVault on macOS. A recovery-key will also be created to make sure the data remains accessible in case of a problem with the TPM unlocking mechanism (unsigned bootloader or kernel update, firmware update, etc.)
**Warning:** Implementing this method on your root volume means your computer will **automatically unlock** at boot without requiring an encryption password under specific conditions. However, be cautious of the following risks:
* On systems with multiple users, without additional protection, data is accessible between users.
* Weak user passwords increase the risk of data exposure in case of theft.
* The setup is susceptible to [cold boot attacks](https://en.wikipedia.org/wiki/Cold_boot_attack "wikipedia:Cold boot attack"), where an attacker, even after a prolonged power-off period, could exploit the automatic loading of the TPM key upon turning on the computer. This is particularly relevant for high-value targets.
In this example, partitions are created respecting [systemd#GPT partition automounting](../../en/Systemd.html#GPT_partition_automounting "Systemd"), there is no need for an fstab or crypttab file.
```
+-----------------------+------------------------------------------------+
| ESP | Root partition |
| unencrypted | encrypted |
| | |
| /efi | / |
| | |
| | /dev/mapper/root |
| |------------------------------------------------|
| /dev/sda1 | /dev/sda2 |
+-----------------------+------------------------------------------------+
```
Follow the [Installation guide](../../en/Installation_guide.html "Installation guide") up to step [Installation guide#Partition the disks](../../en/Installation_guide.html#Partition_the_disks "Installation guide").
### Preparing the disk
Prior to creating any partitions, you should inform yourself about the importance and methods to securely erase the disk, described in [dm-crypt/Drive preparation](../../en/Dm-crypt/Drive_preparation.html "Dm-crypt/Drive preparation").
[Partition](../../en/Partitioning.html "Partition") the drive with the [GUID Partition Table](../../en/Partitioning.html#GUID_Partition_Table "GUID Partition Table") (GPT). Then create the needed partitions.
Create an [EFI system partition](../../en/EFI_system_partition.html "EFI system partition") (`/dev/sda1` in this example) with an appropriate size. It will later be mounted at `/efi`.
In the remaining space on the drive create a root partition (`/dev/sda2` in this example) which will be encrypted and later mounted to `/`. Set its partition type GUID to `4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709` ("Linux root (x86-64)" in [fdisk](../../en/Fdisk.html "Fdisk"), `8304` in [gdisk](../../en/GPT_fdisk.html "Gdisk")).
### Preparing the root partition
The following commands create and mount the encrypted root partition. See [dm-crypt/Encrypting a non-root file system#Partition](../../en/Dm-crypt/Encrypting_a_non-root_file_system.html#Partition "Dm-crypt/Encrypting a non-root file system") (which, despite the title, *can* be applied to root partitions, as long as [mkinitcpio](#Configuring_mkinitcpio) and the [boot loader](#Configuring_the_boot_loader) are correctly configured).
If you want to use particular non-default encryption options (e.g. cipher, key length), or if you don't want to use TPM based decryption, see the [encryption options](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_LUKS_mode "Dm-crypt/Device encryption") before executing the first command.
Create the luks volume (you can simply use a blank password, as it will be wiped later) and mount it:
```
# cryptsetup luksFormat /dev/sda2
# cryptsetup open /dev/sda2 root
# mkfs.ext4 /dev/mapper/root
# mount /dev/mapper/root /mnt
```
### Preparing the EFI system partition
Format the newly created EFI system partition as instructed in [EFI system partition#Format the partition](../../en/EFI_system_partition.html#Format_the_partition "EFI system partition") and mount it afterwards.
```
# mount --mkdir /dev/sda1 /mnt/efi
```
Continue the installation process until [Installation guide#Initramfs](../../en/Installation_guide.html#Initramfs "Installation guide"). You can skip [Installation guide#Fstab](../../en/Installation_guide.html#Fstab "Installation guide").
### Configuring mkinitcpio
To build a working systemd based initramfs, modify the `HOOKS=` line in [mkinitcpio.conf](../../en/Mkinitcpio.html#Configuration "Mkinitcpio.conf") as follows:
```
HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt filesystems fsck)
```
Next, see [Unified kernel image#mkinitcpio](../../en/Unified_kernel_image.html#mkinitcpio "Unified kernel image") to configure mkinitcpio for [Unified kernel images](../../en/Unified_kernel_image.html "Unified kernel image").
Do **not** regenerate the initramfs **yet**, as the `/efi/EFI/Linux` directory needs to be created by the boot loader installer first.
### Installing the boot loader
Install [systemd-boot](../../en/Systemd-boot.html "Systemd-boot") with:
```
# bootctl install
```
The [Unified kernel image](../../en/Unified_kernel_image.html "Unified kernel image") generated by mkinitcpio will be automatically recognized and does not need an entry in `/efi/loader/entries/`.
See [systemd-boot#Updating the UEFI boot manager](../../en/Systemd-boot.html#Updating_the_UEFI_boot_manager "Systemd-boot") and [systemd-boot#Loader configuration](../../en/Systemd-boot.html#Loader_configuration "Systemd-boot") for further configuration.
### Finalizing the installation
First, [Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs"), and make sure the image generation is successful.
Make sure you did not forget to [set a root password](../../en/Installation_guide.html#Root_password "Installation guide"), [reboot](../../en/Installation_guide.html#Reboot "Installation guide") to finish the installation.
### Secure Boot
You can now sign the boot loader executables and the EFI binary, in order to enable [Secure Boot](../../en/Unified_Extensible_Firmware_Interface/Secure_Boot.html "Secure Boot"). For a quick and easy way, see [Unified Extensible Firmware Interface/Secure Boot#Assisted process with sbctl](../../en/Unified_Extensible_Firmware_Interface/Secure_Boot.html#Assisted_process_with_sbctl "Unified Extensible Firmware Interface/Secure Boot").
### Enrolling the TPM
After signing the boot loader executables and enabling Secure Boot, you can now enroll the TPM in order to use it to unlock the LUKS volume. The following commands will remove the empty passphrase created during the LUKS format process, create a key bound to the TPM [PCR 7](../../en/Trusted_Platform_Module.html#Accessing_PCR_registers "Trusted Platform Module") (default, [Secure Boot](../../en/Unified_Extensible_Firmware_Interface/Secure_Boot.html "Secure Boot") state and firmware certificates) and create a recovery key to be used in case of any problems. The TPM will automatically release the key as long as the boot chain is not tampered with. See [systemd-cryptenroll#Trusted Platform Module](../../en/Systemd-cryptenroll.html#Trusted_Platform_Module "Systemd-cryptenroll") and [systemd-cryptenroll(1)](https://man.archlinux.org/man/systemd-cryptenroll.1).
```
# systemd-cryptenroll /dev/sda2 --recovery-key
# systemd-cryptenroll /dev/sda2 --wipe-slot=empty --tpm2-device=auto
```
**Warning:**
* Make sure [Secure Boot](../../en/Unified_Extensible_Firmware_Interface/Secure_Boot.html "Secure Boot") is active and in user mode when binding to PCR 7, otherwise, unauthorized boot devices could unlock the encrypted volume.
* The state of PCR 7 can change if firmware certificates change, which can risk locking the user out. This can be implicitly done by [fwupd](../../en/Fwupd.html "Fwupd")[\[2\]](https://raw.githubusercontent.com/systemd/systemd/ed272a9ff59a26beedaab508dd3c9d631de67165/TODO) or explicitly by rotating Secure Boot keys.
|
dm-crypt/Encrypting an entire system | LVM on LUKS |
## LVM on LUKS
The straightforward method is to set up [LVM](../../en/LVM.html "LVM") on top of the encrypted partition instead of the other way round. Technically the LVM is setup inside one big encrypted block device. Hence, the LVM is not visible until the block device is unlocked and the underlying volume structure is scanned and mounted during boot.
The disk layout in this example is:
```
+-----------------------------------------------------------------------+ +----------------+
| Logical volume 1 | Logical volume 2 | Logical volume 3 | | Boot partition |
| | | | | |
| [SWAP] | / | /home | | /boot |
| | | | | |
| /dev/MyVolGroup/swap | /dev/MyVolGroup/root | /dev/MyVolGroup/home | | |
|_ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _| | (may be on |
| | | other device) |
| LUKS2 encrypted partition | | |
| /dev/sda1 | | /dev/sdb1 |
+-----------------------------------------------------------------------+ +----------------+
```
**Note:** While using the `encrypt` hook this method does not allow you to span the logical volumes over multiple disks; either use the [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") or see [dm-crypt/Specialties#Modifying the encrypt hook for multiple partitions](../../en/Dm-crypt/Specialties.html#Modifying_the_encrypt_hook_for_multiple_partitions "Dm-crypt/Specialties").
**Tip:** Two variants of this setup:
* Instructions at [dm-crypt/Specialties#Encrypted system using a detached LUKS header](../../en/Dm-crypt/Specialties.html#Encrypted_system_using_a_detached_LUKS_header "Dm-crypt/Specialties") use this setup with a detached LUKS header on a USB device to achieve a two factor authentication with it.
* Instructions at [dm-crypt/Specialties#Encrypted /boot and a detached LUKS header on USB](../../en/Dm-crypt/Specialties.html#Encrypted_/boot_and_a_detached_LUKS_header_on_USB "Dm-crypt/Specialties") use this setup with a detached LUKS header, encrypted `/boot` partition, and encrypted keyfile all on a USB device.
### Preparing the disk
Prior to creating any partitions, you should inform yourself about the importance and methods to securely erase the disk, described in [dm-crypt/Drive preparation](../../en/Dm-crypt/Drive_preparation.html "Dm-crypt/Drive preparation").
**Tip:** When using the [GRUB](../../en/GRUB.html "GRUB") boot loader for BIOS booting from a [GPT](../../en/Partitioning.html#GUID_Partition_Table "GPT") disk, create a [BIOS boot partition](../../en/GRUB.html#GUID_Partition_Table_\(GPT\)_specific_instructions "BIOS boot partition").
[Create a partition](../../en/Installation_guide.html#Partition_the_disks "Installation guide") to be mounted at `/boot` with a size of 1 GiB or more.
**Tip:** UEFI systems can use the [EFI system partition](../../en/EFI_system_partition.html "EFI system partition") for `/boot`.
Create a partition which will later contain the encrypted container.
Create the LUKS encrypted container at the designated partition. Enter the chosen password twice.
```
# cryptsetup luksFormat /dev/sda1
```
For more information about the available cryptsetup options see the [LUKS encryption options](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_LUKS_mode "Dm-crypt/Device encryption") prior to above command.
Open the container:
```
# cryptsetup open /dev/sda1 cryptlvm
```
The decrypted container is now available at `/dev/mapper/cryptlvm`.
### Preparing the logical volumes
Create a physical volume on top of the opened LUKS container:
```
# pvcreate /dev/mapper/cryptlvm
```
Create a volume group (in this example named `MyVolGroup`, but it can be whatever you want) and add the previously created physical volume to it:
```
# vgcreate MyVolGroup /dev/mapper/cryptlvm
```
Create all your logical volumes on the volume group:
**Tip:** If a logical volume will be formatted with [ext4](../../en/Ext4.html "Ext4"), leave at least 256 MiB free space in the volume group to allow using [e2scrub(8)](https://man.archlinux.org/man/e2scrub.8). After creating the last volume with `-l 100%FREE`, this can be accomplished by reducing its size with `lvreduce -L -256M MyVolGroup/home`.
```
# lvcreate -L 8G MyVolGroup -n swap
# lvcreate -L 32G MyVolGroup -n root
# lvcreate -l 100%FREE MyVolGroup -n home
```
Format your file systems on each logical volume:
```
# mkfs.ext4 /dev/MyVolGroup/root
# mkfs.ext4 /dev/MyVolGroup/home
# mkswap /dev/MyVolGroup/swap
```
Mount your file systems:
```
# mount /dev/MyVolGroup/root /mnt
# mount --mkdir /dev/MyVolGroup/home /mnt/home
# swapon /dev/MyVolGroup/swap
```
### Preparing the boot partition
The bootloader loads the kernel, [initramfs](../../en/Arch_boot_process.html#initramfs "Initramfs"), and its own configuration files from the `/boot` directory. Any file system on a disk that can be read by the bootloader is eligible.
Create a [file system](../../en/File_systems.html "File system") on the partition intended for `/boot`:
```
# mkfs.ext4 /dev/sdb1
```
**Tip:** When opting to keep `/boot` on an [EFI system partition](../../en/EFI_system_partition.html "EFI system partition") the recommended formatting is
```
# mkfs.fat -F32 /dev/sdb1
```
Mount the partition to `/mnt/boot`:
```
# mount --mkdir /dev/sdb1 /mnt/boot
```
At this point resume the common [Installation guide#Installation](../../en/Installation_guide.html#Installation "Installation guide") steps. Return to this page to customize the [Initramfs](../../en/Installation_guide.html#Initramfs "Installation guide") and [Boot loader](../../en/Installation_guide.html#Boot_loader "Installation guide") steps.
### Configuring mkinitcpio
Make sure the [lvm2](https://archlinux.org/packages/?name=lvm2) package is [installed](../../en/Help:Reading.html#Installation_of_packages "Install").
If using the default busybox-based initramfs, add the `keyboard`, `encrypt` and `lvm2` hooks to [mkinitcpio.conf](../../en/Mkinitcpio.html#Configuration "Mkinitcpio.conf"). If you use a non-US console keymap or a non-default console font, additionally add the `keymap` and `consolefont` hooks, respectively.
```
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block encrypt lvm2 filesystems fsck)
```
If using a systemd-based initramfs, instead add the `keyboard`, `sd-encrypt` and `lvm2` hooks. if you use a non-US console keymap or a non-default console font, additionally add the `sd-vconsole` hook.
```
HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt lvm2 filesystems fsck)
```
[Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs") after saving the changes. See [dm-crypt/System configuration#mkinitcpio](../../en/Dm-crypt/System_configuration.html#mkinitcpio "Dm-crypt/System configuration") for details and other hooks that you may need.
Note: When using [dracut](../../en/Dracut.html "Dracut"), no additional setup is required, as the required modules are already included.
### Configuring the boot loader
In order to unlock the encrypted root partition at boot, the following [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters") need to be set by the boot loader:
```
cryptdevice=UUID=device-UUID:cryptlvm root=/dev/MyVolGroup/root
```
If using the [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") hook, the following needs to be set instead:
```
rd.luks.name=device-UUID=cryptlvm root=/dev/MyVolGroup/root
```
The `device-UUID` refers to the UUID of the LUKS superblock, in this example it is the UUID of `/dev/sda1`. See [Persistent block device naming](../../en/Persistent_block_device_naming.html "Persistent block device naming") for details.
If using [dracut](../../en/Dracut.html "Dracut"), these parameters are known to work:
```
rd.luks.uuid=device-UUID root=/dev/MyVolGroup/root
```
you may need a more extensive list of parameters, try:
```
rd.luks.uuid=luks-deviceUUID rd.lvm.lv=MyVolGroup/root rd.lvm.lv=MyVolGroup/swap root=/dev/mapper/MyVolGroup-root rootfstype=ext4 rootflags=rw,relatime
```
See [dm-crypt/System configuration#Kernel parameters](../../en/Dm-crypt/System_configuration.html#Kernel_parameters "Dm-crypt/System configuration") for details.
|
dm-crypt/Encrypting an entire system | LUKS on LVM |
## LUKS on LVM
To use encryption on top of [LVM](../../en/LVM.html "LVM"), the LVM volumes are set up first and then used as the base for the encrypted partitions. This way, a mixture of encrypted and non-encrypted volumes/partitions is possible as well.
**Tip:** Unlike [#LVM on LUKS](#LVM_on_LUKS), this method allows normally spanning the logical volumes over multiple disks.
The following short example creates a LUKS on LVM setup and mixes in the use of a key-file for the /home partition and temporary crypt volumes for `/tmp` and `/swap`. The latter is considered desirable from a security perspective, because no potentially sensitive temporary data survives the reboot, when the encryption is re-initialised. If you are experienced with LVM, you will be able to ignore/replace LVM and other specifics according to your plan.
If you want to span a logical volume over multiple disks that have already been set up, or expand the logical volume for `/home` (or any other volume), a procedure to do so is described in [dm-crypt/Specialties#Expanding LVM on multiple disks](../../en/Dm-crypt/Specialties.html#Expanding_LVM_on_multiple_disks "Dm-crypt/Specialties"). It is important to note that the LUKS encrypted container has to be resized as well.
**This article or section needs expansion.**
**Reason:** The intro of this scenario needs some adjustment now that a comparison has been added to [#Overview](#Overview). A suggested structure is to make it similar to the [#LUKS on a partition](#LUKS_on_a_partition) intro. (Discuss in [Talk:Dm-crypt/Encrypting an entire system](../../en/Talk:Dm-crypt/Encrypting_an_entire_system.html))
### Preparing the disk
Partitioning scheme:
```
+----------------+-------------------------------------------------------------------------------------------------+
| Boot partition | dm-crypt plain encrypted volume | LUKS2 encrypted volume | LUKS2 encrypted volume |
| | | | |
| /boot | [SWAP] | / | /home |
| | | | |
| | /dev/mapper/swap | /dev/mapper/root | /dev/mapper/home |
| |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|
| | Logical volume 1 | Logical volume 2 | Logical volume 3 |
| | /dev/MyVolGroup/cryptswap | /dev/MyVolGroup/cryptroot | /dev/MyVolGroup/crypthome |
| |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|
| | |
| /dev/sda1 | /dev/sda2 |
+----------------+-------------------------------------------------------------------------------------------------+
```
Randomise `/dev/sda2` according to [dm-crypt/Drive preparation#dm-crypt wipe on an empty device or partition](../../en/Dm-crypt/Drive_preparation.html#dm-crypt_wipe_on_an_empty_device_or_partition "Dm-crypt/Drive preparation").
### Preparing the logical volumes
```
# pvcreate /dev/sda2
# vgcreate MyVolGroup /dev/sda2
# lvcreate -L 32G -n cryptroot MyVolGroup
# lvcreate -L 500M -n cryptswap MyVolGroup
# lvcreate -L 500M -n crypttmp MyVolGroup
# lvcreate -l 100%FREE -n crypthome MyVolGroup
```
```
# cryptsetup luksFormat /dev/MyVolGroup/cryptroot
# cryptsetup open /dev/MyVolGroup/cryptroot root
# mkfs.ext4 /dev/mapper/root
# mount /dev/mapper/root /mnt
```
More information about the encryption options can be found in [dm-crypt/Device encryption#Encryption options for LUKS mode](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_LUKS_mode "Dm-crypt/Device encryption"). Note that `/home` will be encrypted in [#Encrypting logical volume /home](#Encrypting_logical_volume_/home).
**Tip:** If you ever have to access the encrypted root from the Arch-ISO, the above `open` action will allow you to after the [LVM shows up](../../en/LVM.html#Logical_volumes_do_not_show_up "LVM").
### Preparing the boot partition
```
# dd if=/dev/zero of=/dev/sda1 bs=1M status=progress
# mkfs.ext4 /dev/sda1
# mount --mkdir /dev/sda1 /mnt/boot
```
### Configuring mkinitcpio
Make sure the [lvm2](https://archlinux.org/packages/?name=lvm2) package is [installed](../../en/Help:Reading.html#Installation_of_packages "Install").
If using the default busybox-based initramfs, add the `keyboard`, `encrypt` and `lvm2` hooks to [mkinitcpio.conf](../../en/Mkinitcpio.html#Configuration "Mkinitcpio.conf"). If you use a non-US console keymap or a non-default console font, additionally add the `keymap` and `consolefont` hooks, respectively.
```
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block lvm2 encrypt filesystems fsck)
```
If using a systemd-based initramfs, instead add the `keyboard`, `sd-encrypt` and `lvm2` hooks. if you use a non-US console keymap or a non-default console font, additionally add the `sd-vconsole` hook.
```
HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt lvm2 filesystems fsck)
```
[Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs") after saving the changes. See [dm-crypt/System configuration#mkinitcpio](../../en/Dm-crypt/System_configuration.html#mkinitcpio "Dm-crypt/System configuration") for details and other hooks that you may need.
### Configuring the boot loader
In order to unlock the encrypted root partition at boot, the following [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters") need to be set by the boot loader:
```
cryptdevice=UUID=device-UUID:root root=/dev/mapper/root
```
If using the [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") hook, the following need to be set instead:
```
rd.luks.name=device-UUID=root root=/dev/mapper/root
```
The `device-UUID` refers to the UUID of the LUKS superblock, in this example it is the UUID of `/dev/MyVolGroup/cryptroot`. See [Persistent block device naming](../../en/Persistent_block_device_naming.html "Persistent block device naming") for details.
See [dm-crypt/System configuration#Kernel parameters](../../en/Dm-crypt/System_configuration.html#Kernel_parameters "Dm-crypt/System configuration") for details.
### Configuring fstab and crypttab
Both [crypttab](../../en/Dm-crypt/System_configuration.html#crypttab "Crypttab") and [fstab](../../en/Fstab.html "Fstab") entries are required to both unlock the device and mount the file systems, respectively. The following lines will re-encrypt the temporary file systems on each reboot:
```
/etc/crypttab
```
```
swap /dev/MyVolGroup/cryptswap /dev/urandom swap,cipher=aes-xts-plain64,size=256
tmp /dev/MyVolGroup/crypttmp /dev/urandom tmp,cipher=aes-xts-plain64,size=256
```
```
/etc/fstab
```
```
/dev/mapper/root / ext4 defaults 0 1
/dev/sda1 /boot ext4 defaults 0 2
/dev/mapper/tmp /tmp tmpfs defaults 0 0
/dev/mapper/swap none swap sw 0 0
```
### Encrypting logical volume /home
Since this scenario uses LVM as the primary and dm-crypt as secondary mapper, each encrypted logical volume requires its own encryption. Yet, unlike the temporary file systems configured with volatile encryption above, the logical volume for `/home` should of course be persistent. The following assumes you have rebooted into the installed system, otherwise you have to adjust paths. To save on entering a second passphrase at boot, a [keyfile](../../en/Dm-crypt/Device_encryption.html#Keyfiles "Dm-crypt/Device encryption") is created:
```
# mkdir -m 700 /etc/luks-keys
# dd if=/dev/random of=/etc/luks-keys/home bs=1 count=256 status=progress
```
The logical volume is encrypted with it:
```
# cryptsetup luksFormat -v /dev/MyVolGroup/crypthome /etc/luks-keys/home
# cryptsetup -d /etc/luks-keys/home open /dev/MyVolGroup/crypthome home
# mkfs.ext4 /dev/mapper/home
# mount /dev/mapper/home /home
```
The encrypted mount is configured in both [crypttab](../../en/Dm-crypt/System_configuration.html#crypttab "Crypttab") and [fstab](../../en/Fstab.html "Fstab"):
```
/etc/crypttab
```
```
home /dev/MyVolGroup/crypthome /etc/luks-keys/home
```
```
/etc/fstab
```
```
/dev/mapper/home /home ext4 defaults 0 2
```
|
dm-crypt/Encrypting an entire system | LUKS on software RAID |
## LUKS on software RAID
This example is based on a real-world setup for a workstation class laptop equipped with two SSDs of equal size, and an additional HDD for bulk storage. The end result is LUKS1 based full disk encryption (including `/boot`) for all drives, with the SSDs in a [RAID0](../../en/RAID.html "RAID") array, and keyfiles used to unlock all encryption after [GRUB](../../en/GRUB.html "GRUB") is given a correct passphrase at boot.
This setup utilizes a very simplistic partitioning scheme, with all the available RAID storage being mounted at `/` (no separate `/boot` partition), and the decrypted HDD being mounted at `/data`.
Please note that regular [backups](../../en/System_backup.html "System backup") are very important in this setup. If either of the SSDs fail, the data contained in the RAID array will be practically impossible to recover. You may wish to select a different [RAID level](../../en/RAID.html#Standard_RAID_levels "RAID") if fault tolerance is important to you.
The encryption is not deniable in this setup.
For the sake of the instructions below, the following block devices are used:
```
/dev/sda = first SSD
/dev/sdb = second SSD
/dev/sdc = HDD
```
```
+---------------------+---------------------------+---------------------------+ +---------------------+---------------------------+---------------------------+ +---------------------------+
| BIOS boot partition | EFI system partition | LUKS1 encrypted volume | | BIOS boot partition | EFI system partition | LUKS1 encrypted volume | | LUKS2 encrypted volume |
| | | | | | | | | |
| | /efi | / | | | /efi | / | | /data |
| | | | | | | | | |
| | | /dev/mapper/root | | | | /dev/mapper/root | | |
| +---------------------------+---------------------------+ | +---------------------------+---------------------------+ | |
| | RAID1 array (part 1 of 2) | RAID0 array (part 1 of 2) | | | RAID1 array (part 2 of 2) | RAID0 array (part 2 of 2) | | |
| | | | | | | | | |
| | /dev/md/ESP | /dev/md/root | | | /dev/md/ESP | /dev/md/root | | /dev/mapper/data |
| +---------------------------+---------------------------+ | +---------------------------+---------------------------+ +---------------------------+
| /dev/sda1 | /dev/sda2 | /dev/sda3 | | /dev/sdb1 | /dev/sdb2 | /dev/sdb3 | | /dev/sdc1 |
+---------------------+---------------------------+---------------------------+ +---------------------+---------------------------+---------------------------+ +---------------------------+
```
Be sure to substitute them with the appropriate device designations for your setup, as they may be different.
### Preparing the disks
Prior to creating any partitions, you should inform yourself about the importance and methods to securely erase the disk, described in [dm-crypt/Drive preparation](../../en/Dm-crypt/Drive_preparation.html "Dm-crypt/Drive preparation").
For [BIOS systems](../../en/GRUB.html#BIOS_systems "GRUB") with GPT, create a [BIOS boot partition](../../en/GRUB.html#GUID_Partition_Table_\(GPT\)_specific_instructions "BIOS boot partition") with size of 1 MiB for GRUB to store the second stage of BIOS bootloader. Do not mount the partition.
For [UEFI systems](../../en/GRUB.html#UEFI_systems "GRUB") create an [EFI system partition](../../en/EFI_system_partition.html "EFI system partition") with an appropriate size, it will later be mounted at `/efi`.
In the remaining space on the drive create a partition (`/dev/sda3` in this example) for "Linux RAID". Choose partition type ID `fd` for MBR or partition type GUID `A19D880F-05FC-4D3B-A006-743F0F84911E` for GPT.
Once partitions have been created on `/dev/sda`, the following commands can be used to clone them to `/dev/sdb`.
```
# sfdisk -d /dev/sda > sda.dump
# sfdisk /dev/sdb < sda.dump
```
The HDD is prepared with a single Linux partition covering the whole drive at `/dev/sdc1`.
### Building the RAID array
Create the RAID array for the SSDs.
**Note:**
* All parts of an EFI system partition RAID array must be individually usable, that means that ESP can only placed in a RAID1 array.
* The RAID superblock must be placed at the end of the EFI system partition using `--metadata=1.0`, otherwise the firmware will not be able to access the partition.
```
# mdadm --create --verbose --level=1 --metadata=1.0 --raid-devices=2 /dev/md/ESP /dev/sda2 /dev/sdb2
```
This example utilizes RAID0 for root, you may wish to substitute a different level based on your preferences or requirements.
```
# mdadm --create --verbose --level=0 --metadata=1.2 --raid-devices=2 /dev/md/root /dev/sda3 /dev/sdb3
```
### Preparing the block devices
As explained in [dm-crypt/Drive preparation](../../en/Dm-crypt/Drive_preparation.html "Dm-crypt/Drive preparation"), the devices are wiped with random data utilizing `/dev/zero` and a crypt device with a random key. Alternatively, you could use `dd` with `/dev/random` or `/dev/urandom`, though it will be much slower.
```
# cryptsetup open --type plain /dev/md/root container --key-file /dev/random
# dd if=/dev/zero of=/dev/mapper/container bs=1M status=progress
# cryptsetup close container
```
And repeat above for the HDD (`/dev/sdc1` in this example).
Set up encryption for `/dev/md/root`:
**Warning:** GRUB's support for LUKS2 is limited; see [GRUB#Encrypted /boot](../../en/GRUB.html#Encrypted_/boot "GRUB") for details. Use LUKS1 (`cryptsetup luksFormat --type luks1`) for partitions that GRUB will need to unlock.
```
# cryptsetup -y -v luksFormat --type luks1 /dev/md/root
# cryptsetup open /dev/md/root root
# mkfs.ext4 /dev/mapper/root
# mount /dev/mapper/root /mnt
```
And repeat for the HDD:
```
# cryptsetup -y -v luksFormat /dev/sdc1
# cryptsetup open /dev/sdc1 data
# mkfs.ext4 /dev/mapper/data
# mount --mkdir /dev/mapper/data /mnt/data
```
For UEFI systems, set up the EFI system partition:
```
# mkfs.fat -F32 /dev/md/ESP
# mount --mkdir /dev/md/ESP /mnt/efi
```
### Configuring GRUB
Configure [GRUB](../../en/GRUB.html "GRUB") for the LUKS1 encrypted system by editing `/etc/default/grub` with the following:
```
GRUB_CMDLINE_LINUX="cryptdevice=/dev/md/root:root"
GRUB_ENABLE_CRYPTODISK=y
```
**This article or section is a candidate for merging with [GRUB#Troubleshooting](../../en/GRUB.html#Troubleshooting "GRUB").**
**Notes:** GRUB troubleshooting issues belong in the [GRUB](../../en/GRUB.html "GRUB") page. It should be moved there and simply linked from this section. (Discuss in [Talk:Dm-crypt/Encrypting an entire system](../../en/Talk:Dm-crypt/Encrypting_an_entire_system.html))
If you have a USB keyboard on a newer system either enable legacy USB support in firmware or add the following to `/etc/default/grub`:
```
GRUB_TERMINAL_INPUT="usb_keyboard"
GRUB_PRELOAD_MODULES="usb usb_keyboard ohci uhci ehci"
```
Otherwise you may not be able to use your keyboard at the LUKS prompt.
See [dm-crypt/System configuration#Kernel parameters](../../en/Dm-crypt/System_configuration.html#Kernel_parameters "Dm-crypt/System configuration") and [GRUB#Encrypted /boot](../../en/GRUB.html#Encrypted_/boot "GRUB") for details.
Complete the GRUB install to both SSDs (in reality, installing only to `/dev/sda` will work).
```
# grub-install --target=i386-pc /dev/sda
# grub-install --target=i386-pc /dev/sdb
# grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB
# grub-mkconfig -o /boot/grub/grub.cfg
```
### Creating the keyfiles
The next steps save you from entering your passphrase twice when you boot the system (once so GRUB can unlock the LUKS1 device, and second time once the initramfs assumes control of the system). This is done by creating a [keyfile](../../en/Dm-crypt/Device_encryption.html#Keyfiles "Dm-crypt/Device encryption") for the encryption and adding it to the initramfs image to allow the encrypt hook to unlock the root device. See [dm-crypt/Device encryption#With a keyfile embedded in the initramfs](../../en/Dm-crypt/Device_encryption.html#With_a_keyfile_embedded_in_the_initramfs "Dm-crypt/Device encryption") for details.
* Create the [keyfile](../../en/Dm-crypt/Device_encryption.html#Keyfiles "Dm-crypt/Device encryption") and add the key to `/dev/md/root`.
* Create another keyfile for the HDD (`/dev/sdc1`) so it can also be unlocked at boot. For convenience, leave the passphrase created above in place as this can make recovery easier if you ever need it. Edit `/etc/crypttab` to decrypt the HDD at boot. See [dm-crypt/System configuration#Unlocking with a keyfile](../../en/Dm-crypt/System_configuration.html#Unlocking_with_a_keyfile "Dm-crypt/System configuration").
### Configuring the system
Edit [fstab](../../en/Fstab.html "Fstab") to mount the root and data block devices and the ESP:
```
/dev/mapper/root / ext4 rw,noatime 0 1
/dev/mapper/data /data ext4 defaults 0 2
/dev/md/ESP /efi vfat rw,relatime,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,tz=UTC,errors=remount-ro 0 2
```
Save the RAID configuration:
```
# mdadm --detail --scan >> /etc/mdadm.conf
```
Edit [mkinitcpio.conf](../../en/Mkinitcpio.html#Configuration "Mkinitcpio.conf") to include your keyfile and add the proper hooks:
```
FILES=(/crypto_keyfile.bin)
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block mdadm_udev encrypt filesystems fsck)
```
See [dm-crypt/System configuration#mkinitcpio](../../en/Dm-crypt/System_configuration.html#mkinitcpio "Dm-crypt/System configuration") for details.
|
dm-crypt/Encrypting an entire system | Plain dm-crypt |
## Plain dm-crypt
Contrary to LUKS, dm-crypt *plain* mode does not require a header on the encrypted device: this scenario exploits this feature to set up a system on an unpartitioned, encrypted disk that will be indistinguishable from a disk filled with random data, which could allow [deniable encryption](https://en.wikipedia.org/wiki/Deniable_encryption "wikipedia:Deniable encryption"). See also [wikipedia:Disk encryption#Full disk encryption](https://en.wikipedia.org/wiki/Disk_encryption#Full_disk_encryption "wikipedia:Disk encryption").
Note that if full-disk encryption is not required, the methods using LUKS described in the sections above are better options for both system encryption and encrypted partitions. LUKS features like key management with multiple passphrases/key-files or re-encrypting a device in-place are unavailable with *plain* mode.
*Plain* dm-crypt encryption can be more resilient to damage than LUKS, because it does not rely on an encryption master-key which can be a single-point of failure if damaged. However, using *plain* mode also requires more manual configuration of encryption options to achieve the same cryptographic strength. See also [Data-at-rest encryption#Cryptographic metadata](../../en/Data-at-rest_encryption.html#Cryptographic_metadata "Data-at-rest encryption"). Using *plain* mode could also be considered if concerned with the problems explained in [dm-crypt/Specialties#Discard/TRIM support for solid state drives (SSD)](../../en/Dm-crypt/Specialties.html#Discard/TRIM_support_for_solid_state_drives_\(SSD\) "Dm-crypt/Specialties").
**Tip:** If headerless encryption is your goal but you are unsure about the lack of key-derivation with *plain* mode, then two alternatives are:
* [dm-crypt LUKS mode with a detached header](../../en/Dm-crypt/Specialties.html#Encrypted_system_using_a_detached_LUKS_header "Dm-crypt/Specialties") by using the *cryptsetup* `--header` option. It cannot be used with the standard *encrypt* hook, but the hook may be modified.
* [tcplay](../../en/Tcplay.html "Tcplay") which offers headerless encryption but with the PBKDF2 function.
The scenario uses two USB sticks:
* one for the boot device, which also allows storing the options required to open/unlock the plain encrypted device in the boot loader configuration, since typing them on each boot would be error prone;
* another for the encryption key file, assuming it stored as raw bits so that to the eyes of an unaware attacker who might get the usbkey the encryption key will appear as random data instead of being visible as a normal file. See also [Wikipedia:Security through obscurity](https://en.wikipedia.org/wiki/Security_through_obscurity "wikipedia:Security through obscurity"), follow [dm-crypt/Device encryption#Keyfiles](../../en/Dm-crypt/Device_encryption.html#Keyfiles "Dm-crypt/Device encryption") to prepare the keyfile.
The disk layout is:
```
+----------------------+----------------------+----------------------+ +----------------+ +----------------+
| Logical volume 1 | Logical volume 2 | Logical volume 3 | | Boot device | | Encryption key |
| | | | | | | file storage |
| / | [SWAP] | /home | | /boot | | (unpartitioned |
| | | | | | | in example) |
| /dev/MyVolGroup/root | /dev/MyVolGroup/swap | /dev/MyVolGroup/home | | /dev/sdb1 | | /dev/sdc |
|----------------------+----------------------+----------------------| |----------------| |----------------|
| disk drive /dev/sda encrypted using plain mode and LVM | | USB stick 1 | | USB stick 2 |
+--------------------------------------------------------------------+ +----------------+ +----------------+
```
**Tip:**
* It is also possible to use a single USB key physical device:
* By putting the key on another partition (/dev/sdb2) of the USB storage device (/dev/sdb).
* By copying the keyfile to the initramfs directly. An example keyfile `/etc/keyfile` gets copied to the initramfs image by setting `FILES=(/etc/keyfile)` in `/etc/mkinitcpio.conf`. The way to instruct the `encrypt` hook to read the keyfile in the initramfs image is using `rootfs:` prefix before the filename, e.g. `cryptkey=rootfs:/etc/keyfile`.
* Another option is using a passphrase with good [entropy](../../en/Security.html#Choosing_secure_passwords "Security").
### Preparing the disk
It is vital that the mapped device is filled with random data. In particular this applies to the scenario use case we apply here.
See [dm-crypt/Drive preparation](../../en/Dm-crypt/Drive_preparation.html "Dm-crypt/Drive preparation") and [dm-crypt/Drive preparation#dm-crypt specific methods](../../en/Dm-crypt/Drive_preparation.html#dm-crypt_specific_methods "Dm-crypt/Drive preparation")
### Preparing the non-boot partitions
See [dm-crypt/Device encryption#Encryption options for plain mode](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_plain_mode "Dm-crypt/Device encryption") for details.
Using the device `/dev/sda`, with the aes-xts cipher with a 512 bit key size and using a keyfile we have the following options for this scenario:
```
# cryptsetup --cipher=aes-xts-plain64 --offset=0 --key-file=/dev/sdc --key-size=512 open --type plain /dev/sda cryptlvm
```
Unlike encrypting with LUKS, the above command must be executed *in full* whenever the mapping needs to be re-established, so it is important to remember the cipher, and key file details.
We can now check a mapping entry has been made for `/dev/mapper/cryptlvm`:
```
# fdisk -l
```
**Tip:** A simpler alternative to using LVM, advocated in the cryptsetup FAQ for cases where LVM is not necessary, is to just create a file system on the entirety of the mapped dm-crypt device.
Next, we setup [LVM](../../en/LVM.html "LVM") logical volumes on the mapped device. See [Install Arch Linux on LVM](../../en/Install_Arch_Linux_on_LVM.html "Install Arch Linux on LVM") for further details:
```
# pvcreate /dev/mapper/cryptlvm
# vgcreate MyVolGroup /dev/mapper/cryptlvm
# lvcreate -L 32G MyVolGroup -n root
# lvcreate -L 10G MyVolGroup -n swap
# lvcreate -l 100%FREE MyVolGroup -n home
```
We format and mount them and activate swap. See [File systems#Create a file system](../../en/File_systems.html#Create_a_file_system "File systems") for further details:
```
# mkfs.ext4 /dev/MyVolGroup/root
# mkfs.ext4 /dev/MyVolGroup/home
# mount /dev/MyVolGroup/root /mnt
# mount --mkdir /dev/MyVolGroup/home /mnt/home
# mkswap /dev/MyVolGroup/swap
# swapon /dev/MyVolGroup/swap
```
### Preparing the boot partition
The `/boot` partition can be installed on the standard vfat partition of a USB stick, if required. But if manual partitioning is needed, then a small 1 GiB partition is all that is required. Create the partition using a [partitioning tool](../../en/Partitioning.html#Partitioning_tools "Partitioning") of your choice.
Create a [file system](../../en/File_systems.html "File system") on the partition intended for `/boot`:
```
# mkfs.fat -F32 /dev/sdb1
# mount --mkdir /dev/sdb1 /mnt/boot
```
### Configuring mkinitcpio
Make sure the [lvm2](https://archlinux.org/packages/?name=lvm2) package is [installed](../../en/Help:Reading.html#Installation_of_packages "Install").
If using the default busybox-based initramfs, add the `keyboard`, `encrypt` and `lvm2` hooks to [mkinitcpio.conf](../../en/Mkinitcpio.html#Configuration "Mkinitcpio.conf"). If you use a non-US console keymap or a non-default console font, additionally add the `keymap` and `consolefont` hooks, respectively.
```
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block encrypt lvm2 filesystems fsck)
```
[Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs") after saving the changes. See [dm-crypt/System configuration#mkinitcpio](../../en/Dm-crypt/System_configuration.html#mkinitcpio "Dm-crypt/System configuration") for details and other hooks that you may need.
### Configuring the boot loader
In order to boot the encrypted root partition, the following [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters") need to be set by the boot loader (note that 64 is the number of bytes in 512 bits):
```
cryptdevice=/dev/disk/by-id/disk-ID-of-sda:cryptlvm cryptkey=/dev/disk/by-id/disk-ID-of-sdc:0:64 crypto=:aes-xts-plain64:512:0:
```
The `disk-ID-of-disk` refers to the id of the referenced disk. See [Persistent block device naming](../../en/Persistent_block_device_naming.html "Persistent block device naming") for details.
See [dm-crypt/System configuration#Kernel parameters](../../en/Dm-crypt/System_configuration.html#Kernel_parameters "Dm-crypt/System configuration") for details and other parameters that you may need.
**Tip:** If using [GRUB](../../en/GRUB.html "GRUB"), you can install it on the same USB as the `/boot` partition.
For BIOS:
```
# grub-install --target=i386-pc --recheck /dev/sdb
```
For UEFI:
```
# grub-install --target=x86_64-efi --efi-directory=/boot --removable
```
### Post-installation
You may wish to remove the USB sticks after booting. Since the `/boot` partition is not usually needed, the `noauto` option can be added to the relevant line in `/etc/fstab`:
```
/etc/fstab
```
```
# /dev/sdb1
/dev/sdb1 /boot vfat noauto,rw,noatime 0 2
```
However, when an update to anything used in the initramfs, or a kernel, or the bootloader is required; the `/boot` partition must be present and mounted. As the entry in `fstab` already exists, it can be mounted simply with:
```
# mount /boot
```
|
dm-crypt/Encrypting an entire system | Encrypted boot partition (GRUB) |
## Encrypted boot partition (GRUB)
This setup utilizes the same partition layout and configuration as the previous [#LVM on LUKS](#LVM_on_LUKS) section, with the difference that the [GRUB](../../en/GRUB.html "GRUB") boot loader is used since it is capable of booting from an LVM logical volume and a LUKS1-encrypted `/boot`. See also [GRUB#Encrypted /boot](../../en/GRUB.html#Encrypted_/boot "GRUB").
The disk layout in this example is:
```
+---------------------+----------------------+----------------------+----------------------+----------------------+
| BIOS boot partition | EFI system partition | Logical volume 1 | Logical volume 2 | Logical volume 3 |
| | | | | |
| | /efi | / | [SWAP] | /home |
| | | | | |
| | | /dev/MyVolGroup/root | /dev/MyVolGroup/swap | /dev/MyVolGroup/home |
| /dev/sda1 | /dev/sda2 |----------------------+----------------------+----------------------+
| unencrypted | unencrypted | /dev/sda3 encrypted using LVM on LUKS1 |
+---------------------+----------------------+--------------------------------------------------------------------+
```
**Tip:**
* All scenarios are intended as examples. It is, of course, possible to apply both of the two above distinct installation steps with the other scenarios as well. See also the variants linked in [#LVM on LUKS](#LVM_on_LUKS).
* You can use `cryptboot` script from [cryptboot](https://aur.archlinux.org/packages/cryptboot/)AUR package for simplified encrypted boot management (mounting, unmounting, upgrading packages) and as a defense against [Evil Maid](https://www.schneier.com/blog/archives/2009/10/evil_maid_attac.html) attacks with [UEFI Secure Boot](../../en/Unified_Extensible_Firmware_Interface/Secure_Boot.html#Using_your_own_keys "Secure Boot"). For more information and limitations see [cryptboot project](https://github.com/kmille/cryptboot) page.
### Preparing the disk
Prior to creating any partitions, you should inform yourself about the importance and methods to securely erase the disk, described in [dm-crypt/Drive preparation](../../en/Dm-crypt/Drive_preparation.html "Dm-crypt/Drive preparation").
For [BIOS/GPT systems](../../en/GRUB.html#GUID_Partition_Table_\(GPT\)_specific_instructions "GRUB") create a [BIOS boot partition](../../en/GRUB.html#GUID_Partition_Table_\(GPT\)_specific_instructions "BIOS boot partition") with size of 1 MiB for GRUB to store the second stage of BIOS bootloader. Do not mount the partition. For BIOS/MBR systems this is not necessary.
For [UEFI systems](../../en/GRUB.html#UEFI_systems "GRUB") create an [EFI system partition](../../en/EFI_system_partition.html "EFI system partition") with an appropriate size, it will later be mounted at `/efi`.
Create a partition of type `8309`, which will later contain the encrypted container for the LVM.
Create the LUKS encrypted container:
**Warning:** GRUB's support for LUKS2 is limited; see [GRUB#Encrypted /boot](../../en/GRUB.html#Encrypted_/boot "GRUB") for details. Use LUKS1 (`cryptsetup luksFormat --type luks1`) for partitions that GRUB will need to unlock.
```
# cryptsetup luksFormat --type luks1 /dev/sda3
```
For more information about the available cryptsetup options see the [LUKS encryption options](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_LUKS_mode "Dm-crypt/Device encryption") prior to above command.
Your partition layout should look similar to this:
```
# gdisk -l /dev/sda
```
```
...
Number Start (sector) End (sector) Size Code Name
1 2048 4095 1024.0 KiB EF02 BIOS boot partition
2 4096 2101247 1024.0 MiB EF00 EFI system partition
3 2101248 69210111 32.0 GiB 8309 Linux LUKS
```
Open the container:
```
# cryptsetup open /dev/sda3 cryptlvm
```
The decrypted container is now available at `/dev/mapper/cryptlvm`.
### Preparing the logical volumes
The LVM logical volumes of this example follow the exact layout as the [#LVM on LUKS](#LVM_on_LUKS) scenario. Therefore, please follow [#Preparing the logical volumes](#Preparing_the_logical_volumes) above and adjust as required.
If you plan to boot in UEFI mode, create a mountpoint for the [EFI system partition](../../en/EFI_system_partition.html "EFI system partition") at `/efi` for compatibility with `grub-install` and mount it:
```
# mount --mkdir /dev/sda2 /mnt/efi
```
At this point, you should have the following partitions and logical volumes inside of `/mnt`:
```
$ lsblk
```
```
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 550M 0 part /mnt/efi
└─sda3 8:3 0 100G 0 part
└─cryptlvm 254:0 0 100G 0 crypt
├─MyVolGroup-swap 254:1 0 8G 0 lvm [SWAP]
├─MyVolGroup-root 254:2 0 32G 0 lvm /mnt
└─MyVolGroup-home 254:3 0 60G 0 lvm /mnt/home
```
### Configuring mkinitcpio
Make sure the [lvm2](https://archlinux.org/packages/?name=lvm2) package is [installed](../../en/Help:Reading.html#Installation_of_packages "Install").
If using the default busybox-based initramfs, add the `keyboard`, `encrypt` and `lvm2` hooks to [mkinitcpio.conf](../../en/Mkinitcpio.html#Configuration "Mkinitcpio.conf"). If you use a non-US console keymap or a non-default console font, additionally add the `keymap` and `consolefont` hooks, respectively.
```
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block encrypt lvm2 filesystems fsck)
```
If using a systemd-based initramfs, instead add the `keyboard`, `sd-encrypt` and `lvm2` hooks. if you use a non-US console keymap or a non-default console font, additionally add the `sd-vconsole` hook.
```
HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt lvm2 filesystems fsck)
```
[Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs") after saving the changes. See [dm-crypt/System configuration#mkinitcpio](../../en/Dm-crypt/System_configuration.html#mkinitcpio "Dm-crypt/System configuration") for details and other hooks that you may need.
### Configuring GRUB
Configure GRUB to allow booting from `/boot` on a LUKS1 encrypted partition:
```
/etc/default/grub
```
```
GRUB_ENABLE_CRYPTODISK=y
```
Set the kernel parameters, so that the initramfs can unlock the encrypted root partition. Using the `encrypt` hook:
```
/etc/default/grub
```
```
GRUB_CMDLINE_LINUX="... cryptdevice=UUID=device-UUID:cryptlvm ..."
```
If using the [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") hook, the following need to be set instead:
```
/etc/default/grub
```
```
GRUB_CMDLINE_LINUX="... rd.luks.name=device-UUID=cryptlvm ..."
```
See [dm-crypt/System configuration#Kernel parameters](../../en/Dm-crypt/System_configuration.html#Kernel_parameters "Dm-crypt/System configuration") and [GRUB#Encrypted /boot](../../en/GRUB.html#Encrypted_/boot "GRUB") for details. The `device-UUID` refers to the UUID of the LUKS superblock, in this example it is the UUID of `/dev/sda3` (the partition which holds the lvm containing the root file system). See [Persistent block device naming](../../en/Persistent_block_device_naming.html "Persistent block device naming").
[install GRUB](../../en/GRUB.html#Installation_2 "GRUB") to the mounted ESP for UEFI booting:
```
# grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB --recheck
```
[install GRUB](../../en/GRUB.html#Installation "GRUB") to the disk for BIOS booting:
```
# grub-install --target=i386-pc --recheck /dev/sda
```
Generate GRUB's [configuration](../../en/GRUB.html#Generate_the_main_configuration_file "GRUB") file:
```
# grub-mkconfig -o /boot/grub/grub.cfg
```
If all commands finished without errors, GRUB should prompt for the passphrase to unlock the `/dev/sda3` partition after the next reboot.
### Avoiding having to enter the passphrase twice
**This article or section is a candidate for merging with [Dm-crypt/Device encryption#With a keyfile embedded in the initramfs](../../en/Dm-crypt/Device_encryption.html#With_a_keyfile_embedded_in_the_initramfs "Dm-crypt/Device encryption").**
**Notes:** Too much duplicated content, too much detail here for this overview page. (Discuss in [Talk:Dm-crypt/Encrypting an entire system#Security Issue with Grub Keyfile](../../en/Talk:Dm-crypt/Encrypting_an_entire_system.html#Security_Issue_with_Grub_Keyfile "Talk:Dm-crypt/Encrypting an entire system"))
While GRUB asks for a passphrase to unlock the LUKS1 encrypted partition after above instructions, the partition unlock is not passed on to the initramfs. Hence, you have to enter the passphrase twice at boot: once for GRUB and once for the initramfs.
This section deals with extra configuration to let the system boot by only entering the passphrase once, in GRUB. This is accomplished by [with a keyfile embedded in the initramfs](../../en/Dm-crypt/Device_encryption.html#With_a_keyfile_embedded_in_the_initramfs "Dm-crypt/Device encryption").
First create a keyfile and add it as LUKS key:
```
# dd bs=512 count=4 if=/dev/random of=/root/cryptlvm.keyfile iflag=fullblock
# chmod 000 /root/cryptlvm.keyfile
# cryptsetup -v luksAddKey /dev/sda3 /root/cryptlvm.keyfile
```
Add the keyfile to the initramfs image:
```
/etc/mkinitcpio.conf
```
```
FILES=(/root/cryptlvm.keyfile)
```
Recreate the initramfs image and secure the embedded keyfile:
```
# chmod 600 /boot/initramfs-linux*
```
Set the following kernel parameters to unlock the LUKS partition with the keyfile. Using the `encrypt` hook:
```
GRUB_CMDLINE_LINUX="... cryptkey=rootfs:/root/cryptlvm.keyfile"
```
Or, using the [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") hook:
```
GRUB_CMDLINE_LINUX="... rd.luks.key=device-UUID=/root/cryptlvm.keyfile"
```
If for some reason the keyfile fails to unlock the boot partition, systemd will fallback to ask for a passphrase to unlock and, in case that is correct, continue booting.
**Tip:** If you want to encrypt the `/boot` partition to protect against offline tampering threats, the [mkinitcpio-chkcryptoboot](../../en/Dm-crypt/Specialties.html#mkinitcpio-chkcryptoboot "Dm-crypt/Specialties") hook has been contributed to help.
### Using a USB drive to unlock /boot
To avoid having to memorise a complicated password, or using a simple one which may be guessed, a keyfile stored on an external USB drive can be used to unlock the LUKS volume. For this to be secure, this USB drive must be stored securely away from the computer when not in use.
First, generate a keyfile in the same way as in [#Avoiding having to enter the passphrase twice](#Avoiding_having_to_enter_the_passphrase_twice). Do not use the same keyfile as if the USB drive is lost or compromised you will need to replace the keyfile embedded in initramfs.
Copy this keyfile to your USB drive and create a new GRUB configuration file:
```
/boot/grub/grub-pre.cfg
```
```
set crypto_uuid=UUID-of-the-luks-volume
set key_disk=UUID-of-the-volume-with-the-key
cryptomount -u $crypto_uuid -k ($key_disk)/the-location-of-the-key-on-your-usb
set root=UUID-of-the-unlocked-volume-as-in-grub.cfg
set prefix=($root)/boot/grub
insmod normal
normal
```
Create a GRUB image and install it (not all of these modules will be needed depending on your file system):
```
# grub-mkimage -p /boot/grub -O x86_64-efi -c /boot/grub/grub-pre.cfg -o /tmp/grubx64.efi part_gpt part_msdos cryptodisk luks gcry_rijndael gcry_sha512 lvm ext2 ntfs fat exfat
# install -v /tmp/grubx64.efi /efi/EFI/GRUB/grubx64.efi
```
|
dm-crypt/Encrypting an entire system | Root on ZFS |
## Root on ZFS
To use dm-crypt with [ZFS](../../en/ZFS.html "ZFS"), see [ZFS#Encryption in ZFS using dm-crypt](../../en/ZFS.html#Encryption_in_ZFS_using_dm-crypt "ZFS").
Additionally, ZFS features [native encryption](../../en/ZFS.html#Native_encryption "ZFS"), which may also be utilized to encrypt the system root, excluding the boot loader and file system metadata. See:
* [Arch Linux Root on ZFS](https://openzfs.github.io/openzfs-docs/Getting%20Started/Arch%20Linux/Root%20on%20ZFS.html) guide on the OpenZFS page,
* [Install Arch Linux on ZFS#Installation](../../en/Install_Arch_Linux_on_ZFS.html#Installation "Install Arch Linux on ZFS").
After the installation, a boot loader can be verified with [Secure Boot](../../en/Unified_Extensible_Firmware_Interface/Secure_Boot.html "Secure Boot") on UEFI-based systems.
[Categories](../../Special:Categories.html "Special:Categories"):
* [Data-at-rest encryption](../../en/Category:Data-at-rest_encryption.html "Category:Data-at-rest encryption")
* [Installation process](../../en/Category:Installation_process.html "Category:Installation process")
Hidden categories:
* [Pages or sections flagged with Template:Expansion](../../en/Category:Pages_or_sections_flagged_with_Template:Expansion.html "Category:Pages or sections flagged with Template:Expansion")
* [Pages or sections flagged with Template:Merge](../../en/Category:Pages_or_sections_flagged_with_Template:Merge.html "Category:Pages or sections flagged with Template:Merge")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Dm-crypt/Encrypting_an_entire_system&oldid=808715>"
- This page was last edited on 19 May 2024, at 13:08.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
dm-crypt/Mounting at login | Intro |
# dm-crypt/Mounting at login
\[ ] 2 languages
* [Español](../../es/Dm-crypt/Mounting_at_login.html "Dm-crypt (Español)/Mounting at login – español")
* [日本語](https://wiki.archlinux.jp/index.php/Dm-crypt/%E3%83%AD%E3%82%B0%E3%82%A4%E3%83%B3%E6%99%82%E3%81%AB%E3%83%9E%E3%82%A6%E3%83%B3%E3%83%88 "Dm-crypt/ログイン時にマウント – 日本語")
From ArchWiki
< [Dm-crypt](../../en/Dm-crypt.html "Dm-crypt")
Related articles
* [pam\_mount](../../en/Pam_mount.html "Pam mount")
**The factual accuracy of this article or section is disputed.**
**Reason:** Would benefit from instanced units, e.g `cryptsetup@.service` (Discuss in [Talk:Dm-crypt/Mounting at login](../../en/Talk:Dm-crypt/Mounting_at_login.html))
It is possible to configure [PAM](../../en/PAM.html "PAM") and [systemd](../../en/Systemd.html "Systemd") to automatically mount a [dm-crypt](../../en/Dm-crypt.html "Dm-crypt") encrypted home partition when its owner logs in, and to unmount it when they log out.
This tutorial assumes you have already created your encrypted partition, as described in [Dm-crypt/Encrypting a non-root file system](../../en/Dm-crypt/Encrypting_a_non-root_file_system.html "Dm-crypt/Encrypting a non-root file system").
**Note:**
* You need to use the same password for your user account and for LUKS.
* In all the examples, replace `username` with your username, `1000` with your user ID and `PARTITION` with the name of your encrypted partition's device.
|
dm-crypt/Mounting at login | Unlocking at login |
## Unlocking at login
*pam\_exec* can be used to unlock the device at login. Edit `/etc/pam.d/system-login` and add the line below emphasized in bold after `auth include system-auth`:
**This article or section needs expansion.**
**Reason:** GDM, LightDM, and maybe other display managers might require `pam_exec` for `session` as well, see [Talk:Dm-crypt/Mounting at login#pam\_exec required for session & using script](../../en/Talk:Dm-crypt/Mounting_at_login.html#pam_exec_required_for_session_&_using_script "Talk:Dm-crypt/Mounting at login"). (Discuss in [Talk:Dm-crypt/Mounting at login](../../en/Talk:Dm-crypt/Mounting_at_login.html))
```
/etc/pam.d/system-login
```
```
...
auth include system-auth
auth optional pam_exec.so expose_authtok /etc/pam_cryptsetup.sh
...
```
Then create the mentioned script.
```
/etc/pam_cryptsetup.sh
```
```
#!/bin/sh
CRYPT_USER="username"
PARTITION="/dev/sdXY"
NAME="home-$CRYPT_USER"
if [ "$PAM_USER" = "$CRYPT_USER" ] && ! [ -e "/dev/mapper/$NAME" ]; then
/usr/bin/cryptsetup open "$PARTITION" "$NAME"
fi
```
Make the script [executable](../../en/Help:Reading.html#Make_executable "Executable").
|
dm-crypt/Mounting at login | Mounting and unmounting automatically |
## Mounting and unmounting automatically
*systemd-logind* maintains `user@1000.service` for as long as at least one session is active for the user. It is started automatically after a first successful login and stopped after a logout from the last session. Hence, we can create and [enable](../../en/Help:Reading.html#Control_of_systemd_units "Enable") a [systemd.mount(5)](https://man.archlinux.org/man/systemd.mount.5) unit for the mapped volume and connect it to `user@1000.service` in order to make it mount and unmount automatically:
```
/etc/systemd/system/home-username.mount
```
```
[Unit]
Requires=user@1000.service
Before=user@1000.service
[Mount]
Where=/home/username
What=/dev/mapper/home-username
Type=btrfs
Options=defaults,relatime,compress=zstd
[Install]
RequiredBy=user@1000.service
```
|
dm-crypt/Mounting at login | Locking after unmounting |
## Locking after unmounting
After unmounting, the device will still be unlocked, and it will be possible to mount it without re-entering password. You can create and [enable](../../en/Help:Reading.html#Control_of_systemd_units "Enable") a service that starts when the device gets unlocked (`BindsTo=dev-mapper-home\x2dusername.device`) and dies after the device gets unmounted (`Requires,Before=home-username.mount`), locking the device in the process (`ExecStop=cryptsetup close`):
```
/etc/systemd/system/cryptsetup-username.service
```
```
[Unit]
DefaultDependencies=no
BindsTo=dev-PARTITION.device
After=dev-PARTITION.device
BindsTo=dev-mapper-home\x2dusername.device
Requires=home-username.mount
Before=home-username.mount
Conflicts=umount.target
Before=umount.target
[Service]
Type=oneshot
RemainAfterExit=yes
TimeoutSec=0
ExecStop=/usr/bin/cryptsetup close home-username
[Install]
RequiredBy=dev-mapper-home\x2dusername.device
```
**Note:** `dev-PARTITION` is the result of `systemd-escape -p /dev/PARTITION`
[Category](../../Special:Categories.html "Special:Categories"):
* [Data-at-rest encryption](../../en/Category:Data-at-rest_encryption.html "Category:Data-at-rest encryption")
Hidden categories:
* [Pages or sections flagged with Template:Accuracy](../../en/Category:Pages_or_sections_flagged_with_Template:Accuracy.html "Category:Pages or sections flagged with Template:Accuracy")
* [Pages or sections flagged with Template:Expansion](../../en/Category:Pages_or_sections_flagged_with_Template:Expansion.html "Category:Pages or sections flagged with Template:Expansion")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Dm-crypt/Mounting_at_login&oldid=806738>"
- This page was last edited on 23 April 2024, at 18:33.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
dm-crypt/Specialties | Intro |
# dm-crypt/Specialties
\[ ] 3 languages
* [Español](../../es/Dm-crypt/Specialties.html "Dm-crypt (Español)/Specialties – español")
* [日本語](https://wiki.archlinux.jp/index.php/Dm-crypt/%E7%89%B9%E8%A8%98%E4%BA%8B%E9%A0%85 "Dm-crypt/特記事項 – 日本語")
* [Polski](../../pl/Dm-crypt/Specialties.html "Dm-crypt (Polski)/Specialties – polski")
From ArchWiki
< [Dm-crypt](../../en/Dm-crypt.html "Dm-crypt")
|
dm-crypt/Specialties | Securing the unencrypted boot partition |
## Securing the unencrypted boot partition
The `/boot` partition and the [Master Boot Record](../../en/Partitioning.html#Master_Boot_Record "Master Boot Record") are the two areas of the disk that are not encrypted, even in an [encrypted root](../../en/Dm-crypt/Encrypting_an_entire_system.html "Dm-crypt/Encrypting an entire system") configuration. They cannot usually be encrypted because the [boot loader](../../en/Arch_boot_process.html#Boot_loader "Boot loader") and BIOS (respectively) are unable to unlock a dm-crypt container in order to continue the boot process. An exception is [GRUB](../../en/GRUB.html "GRUB"), which gained a feature to unlock a LUKS encrypted `/boot` - see [dm-crypt/Encrypting an entire system#Encrypted boot partition (GRUB)](../../en/Dm-crypt/Encrypting_an_entire_system.html#Encrypted_boot_partition_\(GRUB\) "Dm-crypt/Encrypting an entire system").
This section describes steps that can be taken to make the boot process more secure.
**Warning:** Note that securing the `/boot` partition and MBR can mitigate numerous attacks that occur during the boot process, but systems configured this way may still be vulnerable to BIOS/UEFI/firmware tampering, hardware keyloggers, cold boot attacks, and many other threats that are beyond the scope of this article. For an overview of system-trust issues and how these relate to full-disk encryption, refer to [\[1\]](https://www.youtube.com/watch?v=pKeiKYA03eE).
**Note:** When using [UEFI](../../en/Unified_Extensible_Firmware_Interface.html "UEFI"), only an [ESP](../../en/EFI_system_partition.html "ESP") needs to remain unencrypted, if using [Unified kernel images](../../en/Unified_kernel_image.html "Unified kernel image") for example. You can then use [Secure Boot](../../en/Unified_Extensible_Firmware_Interface/Secure_Boot.html "Secure Boot") to make sure the boot chain has not been tampered with, which is an easy way to achieve the same result as the below methods. See [dm-crypt/Encrypting an entire system#LUKS on a partition with TPM2 and Secure Boot](../../en/Dm-crypt/Encrypting_an_entire_system.html#LUKS_on_a_partition_with_TPM2_and_Secure_Boot "Dm-crypt/Encrypting an entire system").
### Booting from a removable device
Using a separate device to boot a system is a fairly straightforward procedure, and offers a significant security improvement against some kinds of attacks. Two vulnerable parts of a system employing an [encrypted root filesystem](../../en/Dm-crypt/Encrypting_an_entire_system.html "Dm-crypt/Encrypting an entire system") are
* the [Master Boot Record](../../en/Partitioning.html#Master_Boot_Record "Master Boot Record"), and
* the `/boot` partition.
These must be stored unencrypted in order for the system to boot. In order to protect these from tampering, it is advisable to store them on a removable medium, such as a USB drive, and boot from that drive instead of the hard disk. As long as you keep the drive with you at all times, you can be certain that those components have not been tampered with, making authentication far more secure when unlocking your system.
It is assumed that you already have your system configured with a dedicated partition mounted at `/boot`. If you do not, please follow the steps in [dm-crypt/System configuration#Kernel parameters](../../en/Dm-crypt/System_configuration.html#Kernel_parameters "Dm-crypt/System configuration"), substituting your hard disk for a removable drive.
**Note:** You must make sure your system supports booting from the chosen medium, be it a USB drive, an external hard drive, an SD card, or anything else.
Prepare the removable drive (`/dev/sdx`).
```
# gdisk /dev/sdx #format if necessary. Alternatively, cgdisk, fdisk, cfdisk, gparted...
# mkfs.ext2 /dev/sdx1 #for BIOS systems
# mkfs.fat -F 32 /dev/sdx1 #for UEFI systems
# mount /dev/sdx1 /mnt
```
Copy your existing `/boot` contents to the new one.
```
# cp -ai /boot/* /mnt/
```
Mount the new partition. Do not forget to update your [fstab](../../en/Fstab.html "Fstab") file accordingly.
```
# umount /boot
# umount /mnt
# mount /dev/sdx1 /boot
# genfstab -p -U / > /etc/fstab
```
Update [GRUB](../../en/GRUB.html "GRUB"). `grub-mkconfig` should detect the new partition UUID automatically, but custom menu entries may need to be updated manually.
```
# grub-mkconfig -o /boot/grub/grub.cfg
# grub-install /dev/sdx #install to the removable device, not the hard disk. for BIOS systems
# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub #for UEFI systems
```
Reboot and test the new configuration. Remember to set your device boot order accordingly in your BIOS or [UEFI](../../en/Unified_Extensible_Firmware_Interface.html "UEFI"). If the system fails to boot, you should still be able to boot from the hard drive in order to correct the problem.
### chkboot
**Warning:** chkboot makes a `/boot` partition **tamper-evident**, not **tamper-proof**. By the time the chkboot script is run, you have already typed your password into a potentially compromised boot loader, kernel, or initrd. If your system fails the chkboot integrity test, no assumptions can be made about the security of your data.
Referring to an article from the ct-magazine (Issue 3/12, page 146, 01.16.2012, [\[2\]](https://www.heise.de/ct/inhalt/2012/03/6/)) the following script checks files under `/boot` for changes of SHA-1 hash, inode, and occupied blocks on the hard drive. It also checks the [Master Boot Record](../../en/Partitioning.html#Master_Boot_Record "Master Boot Record"). The script cannot prevent certain type of attacks, but a lot are made harder. No configuration of the script itself is stored in unencrypted `/boot`. With a locked/powered-off encrypted system, this makes it harder for some attackers because it is not apparent that an automatic checksum comparison of the partition is done upon boot. However, an attacker who anticipates these precautions can manipulate the firmware to run their own code on top of your kernel and intercept file system access, e.g. to `boot`, and present the untampered files. Generally, no security measures below the level of the firmware are able to guarantee trust and tamper evidence.
The script with installation instructions is [available](https://ftp.heise.de/pub/ct/listings/1203-146.zip) (Author: Juergen Schmidt, ju at heisec.de; License: GPLv2). There is also package [chkboot](https://aur.archlinux.org/packages/chkboot/)AUR to [install](../../en/Help:Reading.html#Installation_of_packages "Install").
After installing, [enable](../../en/Help:Reading.html#Control_of_systemd_units "Enable") `chkboot.service`.
As `/usr/local/bin/chkboot_user.sh` needs to be executed right after login, you need to add it to the [autostart](../../en/Autostarting.html "Autostart") (e.g. under KDE -> *System Settings -> Startup and Shutdown -> Autostart*; GNOME 3: *gnome-session-properties*).
With Arch Linux, changes to `/boot` are pretty frequent, for example by new kernels rolling-in. Therefore it may be helpful to use the scripts with every full system update. One way to do so:
```
#!/bin/sh
#
# Note: Insert your <user> and execute it with sudo for pacman & chkboot to work automagically
#
echo "Pacman update [1] Quickcheck before updating" &
sudo -u <user> /usr/local/bin/chkboot_user.sh
/usr/local/bin/chkboot.sh
sudo -u <user> /usr/local/bin/chkboot_user.sh
echo "Pacman update [2] Syncing repos for pacman"
pacman -Syu
/usr/local/bin/chkboot.sh
sudo -u <user> /usr/local/bin/chkboot_user.sh
echo "Pacman update [3] All done, let us roll on ..."
```
### mkinitcpio-chkcryptoboot
**Warning:** This hook does **not** encrypt [GRUB](../../en/GRUB.html "GRUB")'s core (MBR) code or EFI stub, nor does it protect against situations where an attacker is able to modify the behaviour of the boot loader to compromise the kernel and/or initramfs at run-time.
[mkinitcpio-chkcryptoboot](https://aur.archlinux.org/packages/mkinitcpio-chkcryptoboot/)AUR is a [mkinitcpio](../../en/Mkinitcpio.html "Mkinitcpio") hook that performs integrity checks during early-userspace and advises the user not to enter their root partition password if the system appears to have been compromised. Security is achieved through an [encrypted boot partition](../../en/Dm-crypt/Encrypting_an_entire_system.html#Encrypted_boot_partition_\(GRUB\) "Dm-crypt/Encrypting an entire system"), which is unlocked using [GRUB](../../en/GRUB.html#Encrypted_/boot "GRUB")'s `cryptodisk.mod` module, and a root filesystem partition, which is encrypted with a password different from the former. This way, the [initramfs](../../en/Arch_boot_process.html#initramfs "Initramfs") and [kernel](../../en/Kernel.html "Kernel") are secured against offline tampering, and the root partition can remain secure even if the `/boot` partition password is entered on a compromised machine (provided that the chkcryptoboot hook detects the compromise, and is not itself compromised at run-time).
This hook requires [grub](https://archlinux.org/packages/?name=grub) release >=2.00 to function, and a dedicated, LUKS encrypted `/boot` partition with its own password in order to be secure.
#### Installation
[Install](../../en/Help:Reading.html#Installation_of_packages "Install") [mkinitcpio-chkcryptoboot](https://aur.archlinux.org/packages/mkinitcpio-chkcryptoboot/)AUR and edit `/etc/default/chkcryptoboot.conf`. If you want the ability of detecting if your boot partition was bypassed, edit the `CMDLINE_NAME` and `CMDLINE_VALUE` variables, with values known only to you. You can follow the advice of using two hashes as is suggested right after the installation. Also, be sure to make the appropriate changes to the [kernel command line](../../en/Kernel_parameters.html "Kernel command line") in `/etc/default/grub`. Edit the `HOOKS=` line in `/etc/mkinitcpio.conf`, and insert the `chkcryptoboot` hook **before** `encrypt`. When finished, [regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs").
#### Technical overview
[mkinitcpio-chkcryptoboot](https://aur.archlinux.org/packages/mkinitcpio-chkcryptoboot/)AUR consists of an install hook and a run-time hook for mkinitcpio. The install hook runs every time the initramfs is rebuilt, and hashes the GRUB [EFI](../../en/Unified_Extensible_Firmware_Interface.html "EFI") stub (`$esp/EFI/grub_uefi/grubx64.efi`) (in the case of [UEFI](../../en/Unified_Extensible_Firmware_Interface.html "UEFI") systems) or the first 446 bytes of the disk on which GRUB is installed (in the case of BIOS systems), and stores that hash inside the initramfs located inside the encrypted `/boot` partition. When the system is booted, GRUB prompts for the `/boot` password, then the run-time hook performs the same hashing operation and compares the resulting hashes before prompting for the root partition password. If they do not match, the hook will print an error like this:
```
CHKCRYPTOBOOT ALERT!
CHANGES HAVE BEEN DETECTED IN YOUR BOOT LOADER EFISTUB!
YOU ARE STRONGLY ADVISED NOT TO ENTER YOUR ROOT CONTAINER PASSWORD!
Please type uppercase yes to continue:
```
In addition to hashing the boot loader, the hook also checks the parameters of the running kernel against those configured in `/etc/default/chkcryptoboot.conf`. This is checked both at run-time and after the boot process is done. This allows the hook to detect if GRUB's configuration was not bypassed at run-time and afterwards to detect if the entire `/boot` partition was not bypassed.
For BIOS systems the hook creates a hash of GRUB's first stage boot loader (installed to the first 446 bytes of the bootdevice) to compare at the later boot processes. The main second-stage GRUB boot loader `core.img` is not checked.
### AIDE
Alternatively to above scripts, a hash check can be set up with [AIDE](../../en/AIDE.html "AIDE") which can be customized via a very flexible configuration file.
### STARK
While one of these methods should serve the purpose for most users, they do not address all security problems associated with the unencrypted `/boot`. One approach which endeavours to provide a fully authenticated boot chain was published with POTTS as an academic thesis to implement the [STARK](https://www1.informatik.uni-erlangen.de/stark) authentication framework.
The POTTS proof-of-concept uses Arch Linux as a base distribution and implements a system boot chain with:
* POTTS - a boot menu for a one-time authentication message prompt
* TrustedGrub - a [GRUB Legacy](../../en/GRUB_Legacy.html "GRUB Legacy") implementation which authenticates the kernel and initramfs against [TPM chip](../../en/Trusted_Platform_Module.html "Trusted Platform Module") PCR registers
* TRESOR - a kernel patch which implements AES but keeps the master-key not in RAM but in CPU registers during runtime.
As part of the thesis [installation](https://13.tc/p/potts/manual.html) instructions based on Arch Linux (ISO as of 2013-01) have been published. If you want to try it, be aware these tools are not in standard repositories and the solution will be time consuming to maintain.
|
dm-crypt/Specialties | Using GPG, LUKS, or OpenSSL Encrypted Keyfiles |
## Using GPG, LUKS, or OpenSSL Encrypted Keyfiles
The following forum posts give instructions to use two factor authentication, gpg or openssl encrypted keyfiles, instead of a plaintext keyfile described earlier in this wiki article [System Encryption using LUKS with GPG encrypted keys](https://bbs.archlinux.org/viewtopic.php?id=120243):
* GnuPG: [Post regarding GPG encrypted keys](https://bbs.archlinux.org/viewtopic.php?pid=943338#p943338) This post has the generic instructions.
* OpenSSL: [Post regarding OpenSSL encrypted keys](https://bbs.archlinux.org/viewtopic.php?pid=947805#p947805) This post only has the `ssldec` hooks.
* OpenSSL: [Post regarding OpenSSL salted bf-cbc encrypted keys](https://bbs.archlinux.org/viewtopic.php?id=155393) This post has the `bfkf` initcpio hooks, install, and encrypted keyfile generator scripts.
* LUKS: [Post regarding LUKS encrypted keys](https://bbs.archlinux.org/viewtopic.php?pid=1502651#p1502651) with a `lukskey` initcpio hook. Or [#Encrypted /boot and a detached LUKS header on USB](#Encrypted_/boot_and_a_detached_LUKS_header_on_USB) below with a custom encrypt hook for initcpio.
Note that:
* You can follow the above instructions with only two primary partitions, one boot partition (required because of encryption) and one primary LVM partition. Within the LVM partition you can have as many partitions as you need, but most importantly it should contain at least root, swap, and home logical volume partitions. This has the added benefit of having only one keyfile for all your partitions, and having the ability to hibernate your computer (suspend to disk) where the swap partition is encrypted. If you decide to do so your hooks in `/etc/mkinitcpio.conf` should look like this:
```
HOOKS=( ... usb usbinput (etwo or ssldec) encrypt (if using openssl) lvm2 resume ... )
```
and you should add
```
resume=/dev/<VolumeGroupName>/<LVNameOfSwap>
```
to your [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters").
* If you need to temporarily store the unencrypted keyfile somewhere, do not store them on an unencrypted disk. Even better make sure to store them to RAM such as `/dev/shm`.
* If you want to use a GPG encrypted keyfile, you need to use a statically compiled GnuPG version 1.4 or you could edit the hooks and use [gnupg1](https://aur.archlinux.org/packages/gnupg1/)AUR
* It is possible that an update to OpenSSL could break the custom `ssldec` mentioned in the second forum post.
|
dm-crypt/Specialties | Remote unlocking of root (or other) partition |
## Remote unlocking of root (or other) partition
Imagine a system with one or more LUKS encrypted partitions (root or others) or volumes and you need to unlock these partitions/volumes during startup. In this case you need to be able to log in from remote and provide a password during an early boot phase. This can be achieved by using one or more [mkinitcpio](../../en/Mkinitcpio.html "Mkinitcpio") hook(s) that configure a network interface and start some kind of SSH server. Some packages listed below contribute various [mkinitcpio build hooks](../../en/Mkinitcpio.html#Build_hooks "Mkinitcpio") to ease the configuration.
**Note:**
* Keep in mind to use kernel device names for the network interface (e.g. `eth0`) and not [udev's](../../en/Udev.html "Udev") ones (e.g. `enp1s0`), as those will not work.
* By default, Predictable Network Interface Names are activated and change the kernel device name during late boot. Use [dmesg](../../en/Core_utilities.html#Essentials "Dmesg") and look what your Network kernel module does to find the original name (e.g. `eth0`)
* It could be necessary to add the module for your [ethernet](../../en/Network_configuration/Ethernet.html#Device_driver "Network configuration/Ethernet") or [wireless](../../en/Network_configuration/Wireless.html#Device_driver "Network configuration/Wireless") network card to the [MODULES](../../en/Mkinitcpio.html#MODULES "Mkinitcpio") array.
### Busybox based initramfs (built with mkinitcpio)
For busybox based initramfs the packages [mkinitcpio-netconf](https://archlinux.org/packages/?name=mkinitcpio-netconf) and/or [mkinitcpio-ppp](https://aur.archlinux.org/packages/mkinitcpio-ppp/)AUR provide network connectivity. As [SSH](../../en/Secure_Shell.html "SSH") server you have the option of using either [mkinitcpio-dropbear](https://archlinux.org/packages/?name=mkinitcpio-dropbear) or [mkinitcpio-tinyssh](https://archlinux.org/packages/?name=mkinitcpio-tinyssh). Those hooks do not install any shell, so you also need to [install](../../en/Help:Reading.html#Installation_of_packages "Install") the [mkinitcpio-utils](https://archlinux.org/packages/?name=mkinitcpio-utils) package. The instructions below can be used in any combination of the packages above. When there are different paths, it will be noted.
1. If you do not have an SSH key pair yet, [generate one](../../en/SSH_keys.html#Generating_an_SSH_key_pair "SSH keys") on the client system (the one which will be used to unlock the remote machine).
**Note:**
* `tinyssh` only supports [Ed25519](../../en/SSH_keys.html#Ed25519 "SSH keys") and [ECDSA](../../en/SSH_keys.html#ECDSA "SSH keys") key types without passphrase. If you chose to use [mkinitcpio-tinyssh](https://archlinux.org/packages/?name=mkinitcpio-tinyssh), you need to create/use one of these.
* `mkinitcpio-tinyssh` currently has a bug affecting it's use of tinyssh-convert. See [Github](https://github.com/grazzolini/mkinitcpio-tinyssh/issues/10) for details and a fix.
* `mkinitcpio-dropbear` in version 0.0.3-5 is not compatible with the current dropbear implementation that removed dss. See [Github](https://github.com/grazzolini/mkinitcpio-dropbear/issues/8) for details and a fix.
2.
3. Insert your SSH public key (i.e. the one you usually put onto hosts so that you can ssh in without a password, or the one you just created and which ends with *.pub*) into the remote machine's `/etc/dropbear/root_key` or `/etc/tinyssh/root_key` file.
**Tip:** This method can later be used to add other SSH public keys as needed; In the case of simply copying the content of the remote's `~/.ssh/authorized_keys`, be sure to verify that it only contains keys you intend to be using to unlock the remote machine. When adding additional keys, regenerate your initrd as well using `mkinitcpio`. See also [OpenSSH#Protection](../../en/OpenSSH.html#Protection "OpenSSH").
4. Add all three `<netconf and/or ppp> <dropbear or tinyssh> encryptssh` [hooks](../../en/Mkinitcpio.html#HOOKS "Mkinitcpio") before `filesystems` within the "HOOKS" array in `/etc/mkinitcpio.conf` (the `encryptssh` replaces the `encrypt` hook). Then [regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs").
**Note:** The `net` hook provided by [mkinitcpio-nfs-utils](https://archlinux.org/packages/?name=mkinitcpio-nfs-utils) is **not** needed.
5. Configure the required `cryptdevice=` [parameter](../../en/Dm-crypt/System_configuration.html#Kernel_parameters "Dm-crypt/System configuration") and add the `ip=` [kernel command parameter](../../en/Kernel_parameters.html "Kernel parameters") to your boot loader configuration with the appropriate arguments. For example, if you want the IP address to be assigned by DHCP, you can use the following parameter:
```
ip=dhcp
```
This is most useful if your DHCP server is configured to always assign the same IP for this host, as otherwise accessing the system via SSH is going to be difficult. In that case, you can use a static IP:
```
ip=192.168.1.1:::::eth0:none
```
Alternatively, you can also specify the subnet mask and gateway required by the network:
```
ip=192.168.1.1::192.168.1.254:255.255.255.0::eth0:none
```
**Note:** As of version 0.0.4 of [mkinitcpio-netconf](https://archlinux.org/packages/?name=mkinitcpio-netconf), you can nest multiple `ip=` parameters in order to configure multiple interfaces. You cannot mix it with `ip=dhcp` (`ip=:::::eth0:dhcp`) alone. An interface needs to be specified.
```
ip=ip=192.168.1.1:::::eth0:none:ip=172.16.1.1:::::eth1:none
```
If using DHCP, consider adding the `netconf_timeout=` kernel parameter, to prevent netconf from trying to obtain an IP forever. For a detailed description of the `ip=` parameter, have a look at the [according mkinitcpio section](../../en/Mkinitcpio.html#Using_net "Mkinitcpio"). When finished, update the configuration of your [boot loader](../../en/Arch_boot_process.html#Boot_loader "Boot loader").
6. Finally, restart the remote system and try to [ssh to it](../../en/OpenSSH.html#Client_usage "OpenSSH"), **explicitly stating the "root" username** (even if the root account is disabled on the machine, this root user is used only in the initrd for the purpose of unlocking the remote system). If you are using the [mkinitcpio-dropbear](https://archlinux.org/packages/?name=mkinitcpio-dropbear) package and you also have the [openssh](https://archlinux.org/packages/?name=openssh) package installed, then you most probably will not get any warnings before logging in, because it convert and use the same host keys openssh uses (except Ed25519 keys, as dropbear does not support them). In case you are using [mkinitcpio-tinyssh](https://archlinux.org/packages/?name=mkinitcpio-tinyssh), a script `tinyssh-convert` is bundled, so you can use the same keys as your [openssh](https://archlinux.org/packages/?name=openssh) installation (currently only Ed25519 keys). It may be required to manually copy the host key, via `tinyssh-convert`, to `/etc/tinyssh/sshkeydir`. In either case, you should have run [the ssh daemon](../../en/OpenSSH.html#Daemon_management "OpenSSH") at least once, using the provided systemd units, so the keys can be generated first. After rebooting the machine, you should be prompted for the passphrase to unlock the root device. The system will complete its boot process and you can then ssh to it [as you normally would](../../en/OpenSSH.html#Client_usage "OpenSSH") (with the remote user of your choice).
#### Enabling Wi-Fi
The `netconf` hook is normally used with an Ethernet connection. In case you want to setup a computer with wireless only, and unlock it via Wi-Fi, you can use a predefined hook or create a custom hook to connect to a Wi-Fi network before the `netconf` hook is run.
##### Predefined hook
You can install a predefined hook based on the one in this wiki:
1. Install [mkinitcpio-wifi](https://aur.archlinux.org/packages/mkinitcpio-wifi/)AUR.
2. Configure your Wi-Fi connection by creating a *wpa\_supplicant* configuration with your network properties:
```
wpa_passphrase "ESSID" "passphrase" > /etc/wpa_supplicant/initcpio.conf
```
3. Add the `wifi` hook before `netconf` in your `/etc/mkinitcpio.conf`. Your Wi-Fi-related modules should be auto-detected, if not: add them to the `MODULES` section.
4. Add `ip=:::::wlan0:dhcp` to the [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters").
5. [Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs").
6. Update the configuration of your [boot loader](../../en/Arch_boot_process.html#Boot_loader "Boot loader").
##### Custom hook
Below example shows a setup using a USB Wi-Fi adapter, connecting to a Wi-Fi network protected with WPA2-PSK. In case you use for example WEP or another initramfs generator, you might need to adjust accordingly.
1. Modify `/etc/mkinitcpio.conf`:
* Add the needed kernel module for your specific Wi-Fi adapter.
* Include the `wpa_passphrase` and `wpa_supplicant` binaries.
* Add a hook `wifi` (or a name of your choice, this is the custom hook that will be created) before the `net` hook.
```
MODULES=(module)
BINARIES=(wpa_passphrase wpa_supplicant)
HOOKS=(base udev autodetect ... wifi net ... dropbear encryptssh ...)
```
2. Create the `wifi` hook in `/etc/initcpio/hooks/wifi`:
```
run_hook ()
{
# Sleep a couple of seconds so wlan0 is setup by kernel
sleep 5
# Set wlan0 to up
ip link set wlan0 up
# Associate with Wi-Fi network
# 1. Save temp config file
wpa_passphrase "network ESSID" "pass phrase" > /tmp/wifi
# 2. Associate
wpa_supplicant -B -D nl80211,wext -i wlan0 -c /tmp/wifi
# Sleep a couple of seconds so that wpa_supplicant finishes connecting
sleep 5
# wlan0 should now be connected and ready to be assigned an ip by the net hook
}
run_cleanuphook ()
{
# Kill wpa_supplicant running in the background
killall wpa_supplicant
# Set wlan0 link down
ip link set wlan0 down
# wlan0 should now be fully disconnected from the Wi-Fi network
}
```
3. Create the hook installation file in `/etc/initcpio/install/wifi`:
```
build ()
{
add_runscript
}
help ()
{
cat<<HELPEOF
Enables Wi-Fi on boot, for dropbear ssh unlocking of disk.
HELPEOF
}
```
4. Add `ip=:::::wlan0:dhcp` to the [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters"). Remove `ip=:::::eth0:dhcp` so it does not conflict.
5. Optionally create an additional boot entry with kernel parameter `ip=:::::eth0:dhcp`.
6. [Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs").
7. Update the configuration of your [boot loader](../../en/Arch_boot_process.html#Boot_loader "Boot loader").
Remember to setup [Wi-Fi](../../en/Network_configuration/Wireless.html "Wi-Fi"), so you are able to login once the system is fully booted. In case you are unable to connect to the Wi-Fi network, try increasing the sleep times a bit.
### systemd based initramfs (built with mkinitcpio)
For systemd based initramfs the AUR package [mkinitcpio-systemd-extras](https://aur.archlinux.org/packages/mkinitcpio-systemd-extras/)AUR provides a collection of build hooks (aka install hooks) to achieve network connectivity and SSH login during early boot. Depending on the concrete setup this either gives you access to the initramfs environment via busybox' dash or just a password prompt.
A minimal setup:
```
/etc/mkinitcpio.conf
```
```
HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole sd-network block sd-tinyssh sd-encrypt filesystems fsck)
SD_TINYSSH_COMMAND="systemd-tty-ask-password-agent --query --watch"
```
When building the initramfs with `mkinitcpio` this setup copies the already existing configuration of [systemd-networkd](../../en/Systemd-networkd.html "Systemd-networkd") from the main system and also tries to copy / convert existing SSH server keys from an existing TinySSH or OpenSSH installation. [tinyssh](https://archlinux.org/packages/?name=tinyssh) needs to be installed (but not necessarily enabled) on the main system. There are additional configuration parameters in case [systemd-networkd](../../en/Systemd-networkd.html "Systemd-networkd") is not used by the main system. See the [documentation](https://github.com/wolegis/mkinitcpio-systemd-extras/wiki) of [mkinitcpio-systemd-extras](https://aur.archlinux.org/packages/mkinitcpio-systemd-extras/)AUR for further details.
**Note:** This section used to mention [mkinitcpio-systemd-tool](https://archlinux.org/packages/?name=mkinitcpio-systemd-tool) as another alternative to achieve remote login and LUKS unlocking during early startup. The approach is completely different as it requires only one additional hook `systemd-tool` and all further setup is done in special `[X-SystemdTool]` sections in systemd service files. Unfortunately, documentation about this approach and how to use the tool itself is very limited.
### systemd based initramfs (built with dracut)
If you are using [dracut](../../en/Dracut.html "Dracut") instead of [mkinitcpio](../../en/Mkinitcpio.html "Mkinitcpio"), you might want to check out [dracut-sshd](https://github.com/gsauthof/dracut-sshd) as an alternative to the above options.
|
dm-crypt/Specialties | One-time password-less reboot |
## One-time password-less reboot
Another method that can be used to reboot a remote, headless or otherwise inaccessible system whilst not needing to be at the terminal to type the encrypted root drive password, is to use a temporary [keyfile](../../en/Dm-crypt/System_configuration.html#Unlocking_with_a_keyfile "Dm-crypt/System configuration"). This will need to be placed in a location that is accessible to the kernel at boot, the [cryptkey](../../en/Dm-crypt/System_configuration.html#cryptkey "Dm-crypt/System configuration") boot parameter will be needed, and that particular keyfile will need to be registered as a valid key by way of the "cryptsetup luksAddKey" command.
This can be done conveniently with the help of [passless-boot](https://aur.archlinux.org/packages/passless-boot/)AUR. The procedure described to setup that tool on [the script's readme file](https://gitlab.com/Marcool04/passless-boot) might serve as a template for setting up a home-made solution also. Do take a look at the discussion in the [Security considerations](https://gitlab.com/Marcool04/passless-boot#security-considerations-and-threat-model) section.
|
dm-crypt/Specialties | Discard/TRIM support for solid state drives (SSD) |
## Discard/TRIM support for solid state drives (SSD)
[Solid state drive](../../en/Solid_state_drive.html "Solid state drive") users should be aware that, by default, TRIM commands are not enabled by the device-mapper, i.e. block-devices are mounted without the `discard` option unless you override the default.
The device-mapper maintainers have made it clear that TRIM support will never be enabled by default on dm-crypt devices because of the potential security implications.[\[3\]](http://www.saout.de/pipermail/dm-crypt/2011-September/002019.html)[\[4\]](http://www.saout.de/pipermail/dm-crypt/2012-April/002420.html) Minimal data leakage in the form of freed block information, perhaps sufficient to determine the filesystem in use, may occur on devices with TRIM enabled. An illustration and discussion of the issues arising from activating TRIM is available in the [blog](https://asalor.blogspot.de/2011/08/trim-dm-crypt-problems.html) of a *cryptsetup* developer. If you are worried about such factors, keep also in mind that threats may add up: for example, if your device is still encrypted with the previous (cryptsetup <1.6.0) default cipher `--cipher aes-cbc-essiv`, more information leakage may occur from trimmed sector observation than with the current [default](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_LUKS_mode "Dm-crypt/Device encryption").
The following cases can be distinguished:
* The device is encrypted with default dm-crypt LUKS mode:
* By default the LUKS header is stored at the beginning of the device and using TRIM is useful to protect header modifications. If for example a compromised LUKS password is revoked, without TRIM the old header will in general still be available for reading until overwritten by another operation; if the drive is stolen in the meanwhile, the attackers could in theory find a way to locate the old header and use it to decrypt the content with the compromised password. See [cryptsetup FAQ, section 5.19 What about SSDs, Flash and Hybrid Drives?](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions#5-security-aspects) and [Full disk encryption on an ssd](https://www.reddit.com/r/archlinux/comments/2f370s/full_disk_encryption_on_an_ssd/ck5p5c5).
* TRIM can be left disabled if the security issues stated at the top of this section are considered a worse threat than the above bullet.
- See also [Securely wipe disk#Flash memory](../../en/Securely_wipe_disk.html#Flash_memory "Securely wipe disk").
* The device is encrypted with dm-crypt plain mode, or the LUKS header is stored [separately](#Encrypted_system_using_a_detached_LUKS_header):
* If plausible deniability is required, TRIM should **never** be used because of the considerations at the top of this section, or the use of encryption will be given away.
* If plausible deniability is not required, TRIM can be used for its performance gains, provided that the security dangers described at the top of this section are not of concern.
**Warning:** Before enabling TRIM on a drive, make sure the device fully supports TRIM commands, or data loss can occur. See [Solid State Drives#TRIM](../../en/Solid_state_drive.html#TRIM "Solid State Drives").
To enable TRIM support during boot, set the following [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters").
If using the [encrypt](../../en/Dm-crypt/System_configuration.html#Using_encrypt_hook "Dm-crypt/System configuration") hook:
```
cryptdevice=/dev/sdaX:root:allow-discards
```
If using the [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") hook with systemd-based initramfs:
```
rd.luks.options=discard
```
**Note:** The `rd.luks.options=discard` kernel option does not have any effect on devices included in the initramfs image's `/etc/crypttab` file (`/etc/crypttab.initramfs` on real root). You must specify option `discard` in `/etc/crypttab.initramfs`.
Besides the kernel option, it is also required to periodically run `fstrim` or mount the filesystem (e.g. `/dev/mapper/root` in this example) with the `discard` option in `/etc/fstab`. For details, please refer to the [TRIM](../../en/Solid_state_drive.html#TRIM "TRIM") page.
For LUKS devices unlocked via `/etc/crypttab` use option `discard`, e.g.:
```
/etc/crypttab
```
```
luks-123abcdef-etc UUID=123abcdef-etc none discard
```
When manually unlocking devices on the console use `--allow-discards`.
Alternatively, *cryptsetup* gained a new `--allow-discards` option for opening a blockdevice with the option, as well as a [cryptsetup-refresh(8)](https://man.archlinux.org/man/cryptsetup-refresh.8) command to persistently set it in the LUKS2 header.
For example, you can open a LUKS device with the `--allow-discards` option to execute a manual *fstrim* command:
```
# cryptsetup --allow-discards open /dev/sdaX root
```
When the device is already opened, the `open` action will raise an error. For a LUKS2 device, you can still use the `refresh` command in these cases, as well as set the `--persistent` option for the LUKS2 header:
```
# cryptsetup --allow-discards --persistent refresh root
```
You can confirm the flag is persistently set in the LUKS2 header by looking at the `cryptsetup luksDump` output:
```
# cryptsetup luksDump /dev/sdaX | grep Flags
```
```
Flags: allow-discards
```
In any case, you can verify whether the device actually was opened with discards by inspecting the `dmsetup table` output:
```
# dmsetup table
```
```
luks-123abcdef-etc: 0 1234567 crypt aes-xts-plain64 000etc000 0 8:2 4096 1 allow_discards
```
|
dm-crypt/Specialties | Disable workqueue for increased solid state drive (SSD) performance |
## Disable workqueue for increased solid state drive (SSD) performance
[Solid state drive](../../en/Solid_state_drive.html "Solid state drive") users should be aware that, by default, discarding internal read and write workqueue commands are not enabled by the device-mapper, i.e. block-devices are mounted without the `no_read_workqueue` and `no_write_workqueue` option unless you override the default.
The `no_read_workqueue` and `no_write_workqueue` flags were introduced by internal Cloudflare research [Speeding up Linux disk encryption](https://blog.cloudflare.com/speeding-up-linux-disk-encryption/) made while investigating overall encryption performance. One of the conclusions is that internal dm-crypt read and write queues decrease performance for SSD drives. While queuing disk operations makes sense for spinning drives, bypassing the queue and writing data synchronously doubled the throughput and cut the SSD drives' IO await operations latency in half. The patches were upstreamed and are available since [linux](https://archlinux.org/packages/?name=linux) 5.9 and up [\[5\]](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/md/dm-crypt.c?id=39d42fa96ba1b7d2544db3f8ed5da8fb0d5cb877).
**Tip:** [linux-zen](https://archlinux.org/packages/?name=linux-zen) has dm-crypt workqueues [disabled by default](https://github.com/zen-kernel/zen-kernel/issues/282).
To disable workqueue for LUKS devices unlocked via [crypttab](../../en/Dm-crypt/System_configuration.html#crypttab "Crypttab") use one or more of the desired `no-read-workqueue` or `no-write-workqueue` options. E.g.:
```
/etc/crypttab
```
```
luks-123abcdef-etc UUID=123abcdef-etc none no-read-workqueue
```
To disable both read and write workqueue add both flags:
```
/etc/crypttab
```
```
luks-123abcdef-etc UUID=123abcdef-etc none no-read-workqueue,no-write-workqueue
```
With LUKS2 you can set `--perf-no_read_workqueue` and `--perf-no_write_workqueue` as default flags for a device by opening it once with the option `--persistent`. For example:
```
# cryptsetup --perf-no_read_workqueue --perf-no_write_workqueue --persistent open /dev/sdaX root
```
When the device is already opened, the `open` action will raise an error. You can use the `refresh` option in these cases, e.g.:
```
# cryptsetup --perf-no_read_workqueue --perf-no_write_workqueue --persistent refresh root
```
You can confirm which flags are persistently set in the LUKS2 header by looking at the `cryptsetup luksDump` output:
```
# cryptsetup luksDump /dev/sdaX | grep Flags
```
```
Flags: no-read-workqueue
```
In any case, you can verify whether the device actually was opened with these flags by inspecting the `dmsetup table` output:
```
# dmsetup table
```
```
luks-123abcdef-etc: 0 1234567 crypt aes-xts-plain64 000etc000 0 8:2 4096 1 no_read_workqueue
```
**Note:** Setting new persistent flags via `cryptsetup --persistent` replaces old flags with new ones instead of adding a new flag to the already set flags. This means if you want to enable both `--perf-no_read_workqueue` and `--perf-no_write_workqueue` (or more) you have to set them all at once.
Example for setting both `no_read_workqueue` and `no_write_workqueue` with `cryptsetup`:
```
# cryptsetup --perf-no_read_workqueue --perf-no_write_workqueue --persistent refresh root
```
You can confirm both flags being set by inspecting the LUKS2 `cryptsetup luksDump` output:
```
# cryptsetup luksDump /dev/sdaX | grep Flags
```
```
Flags: no-read-workqueue no-write-workqueue
```
|
dm-crypt/Specialties | The encrypt hook and multiple disks |
## The encrypt hook and multiple disks
**Tip:** `sd-encrypt` hook supports unlocking multiple devices. They can be specified on the kernel command line or in `/etc/crypttab.initramfs`. See [dm-crypt/System configuration#Using systemd-cryptsetup-generator](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Dm-crypt/System configuration").
The `encrypt` hook only allows for a **single** `cryptdevice=` entry ([FS#23182](https://bugs.archlinux.org/task/23182)). In system setups with multiple drives this may be limiting, because *dm-crypt* has no feature to exceed the physical device. For example, take "LVM on LUKS": The entire LVM exists inside a LUKS mapper. This is perfectly fine for a single-drive system, since there is only one device to decrypt. But what happens when you want to increase the size of the LVM? You cannot, at least not without modifying the `encrypt` hook.
The following sections briefly show alternatives to overcome the limitation. The first deals with how to expand a [LUKS on LVM](../../en/Dm-crypt/Encrypting_an_entire_system.html#LUKS_on_LVM "Dm-crypt/Encrypting an entire system") setup to a new disk. The second with modifying the `encrypt` hook to unlock multiple disks in LUKS setups without LVM.
### Expanding LVM on multiple disks
The management of multiple disks is a basic [LVM](../../en/LVM.html "LVM") feature and a major reason for its partitioning flexibility. It can also be used with *dm-crypt*, but only if LVM is employed as the first mapper. In such a [LUKS on LVM](../../en/Dm-crypt/Encrypting_an_entire_system.html#LUKS_on_LVM "Dm-crypt/Encrypting an entire system") setup the encrypted devices are created inside the logical volumes (with a separate passphrase/key per volume). The following covers the steps to expand that setup to another disk.
**Warning:** Back up! While resizing filesystems may be standard, keep in mind that operations **may** go wrong and the following might not apply to a particular setup. Generally, extending a filesystem to free disk space is less problematic than shrinking one. This in particular applies when stacked mappers are used, as it is the case in the following example.
#### Adding a new drive
First, it may be desired to prepare a new disk according to [dm-crypt/Drive preparation](../../en/Dm-crypt/Drive_preparation.html "Dm-crypt/Drive preparation"). Second, it is partitioned as a LVM, e.g. all space is allocated to `/dev/sdY1` with partition type `8E00` (Linux LVM). Third, the new disk/partition is attached to the existing LVM volume group, e.g.:
```
# pvcreate /dev/sdY1
# vgextend MyStorage /dev/sdY1
```
#### Extending the logical volume
For the next step, the final allocation of the new diskspace, the logical volume to be extended has to be unmounted. It can be performed for the `cryptdevice` root partition, but in this case the procedure has to be performed from an Arch Install ISO.
In this example, it is assumed that the logical volume for `/home` (lv-name `homevol`) is going to be expanded with the fresh disk space:
```
# umount /home
# fsck /dev/mapper/home
# cryptsetup close /dev/mapper/home
# lvextend -l +100%FREE MyStorage/homevol
```
Now the logical volume is extended and the LUKS container comes next:
```
# cryptsetup open /dev/MyStorage/homevol home
# umount /home # as a safety, in case it was automatically remounted
# cryptsetup --verbose resize home
```
Finally, the filesystem itself is resized:
```
# e2fsck -f /dev/mapper/home
# resize2fs /dev/mapper/home
```
Done! If it went to plan, `/home` can be remounted and now includes the span to the new disk:
```
# mount /dev/mapper/home /home
```
Note that the `cryptsetup resize` action does not affect encryption keys, and these have not changed.
### Modifying the encrypt hook for multiple partitions
Note that [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") supports multiple partitions out of the box. If several (or all) partitions opened this way share the same passphrase, sd-encrypt will try it for each and not ask for it multiple times. This may be an easier alternative to the following.
#### Root filesystem spanning multiple partitions
It is possible to modify the encrypt hook to allow multiple hard drive decrypt root (`/`) at boot. One way:
```
# cp /usr/lib/initcpio/install/encrypt /etc/initcpio/install/encrypt2
# cp /usr/lib/initcpio/hooks/encrypt /etc/initcpio/hooks/encrypt2
# sed -i "s/cryptdevice/cryptdevice2/" /etc/initcpio/hooks/encrypt2
# sed -i "s/cryptkey/cryptkey2/" /etc/initcpio/hooks/encrypt2
```
Add `cryptdevice2=` to your boot options (and `cryptkey2=` if needed), and add the `encrypt2` hook to your [mkinitcpio.conf](../../en/Mkinitcpio.html#Configuration "Mkinitcpio.conf") before rebuilding it. See [dm-crypt/System configuration](../../en/Dm-crypt/System_configuration.html "Dm-crypt/System configuration").
#### Multiple non-root partitions
Maybe you have a requirement for using the `encrypt` hook on a non-root partition. Arch does not support this out of the box, however, you can easily change the cryptdev and cryptname values in `/lib/initcpio/hooks/encrypt` (the first one to your `/dev/sd*` partition, the second to the name you want to attribute). That should be enough.
The big advantage is you can have everything automated, while setting up `/etc/crypttab` with an external key file (i.e. the keyfile is not on any internal hard drive partition) can be a pain - you need to make sure the USB/FireWire/... device gets mounted before the encrypted partition, which means you have to change the order of `/etc/fstab` (at least).
Of course, if the [cryptsetup](https://archlinux.org/packages/?name=cryptsetup) package gets upgraded, you will have to change this script again. Unlike `/etc/crypttab`, only one partition is supported, but with some further hacking one should be able to have multiple partitions unlocked.
**The factual accuracy of this article or section is disputed.**
**Reason:** Why not use the supported Grub2 right away? See also [mkinitcpio#Using RAID](../../en/Mkinitcpio.html#Using_RAID "Mkinitcpio") (Discuss in [Talk:Dm-crypt/Specialties](../../en/Talk:Dm-crypt/Specialties.html))
If you want to do this on a software RAID partition, there is one more thing you need to do. Just setting the `/dev/mdX` device in `/lib/initcpio/hooks/encrypt` is not enough; the `encrypt` hook will fail to find the key for some reason, and not prompt for a passphrase either. It looks like the RAID devices are not brought up until after the `encrypt` hook is run. You can solve this by putting the RAID array in `/boot/grub/menu.lst`, like
```
kernel /boot/vmlinuz-linux md=1,/dev/hda5,/dev/hdb5
```
If you set up your root partition as a RAID, you will notice the similarities with that setup. [GRUB](../../en/GRUB.html "GRUB") can handle multiple array definitions just fine:
```
kernel /boot/vmlinuz-linux root=/dev/md0 ro md=0,/dev/sda1,/dev/sdb1 md=1,/dev/sda5,/dev/sdb5,/dev/sdc5
```
|
dm-crypt/Specialties | Encrypted system using a detached LUKS header |
## Encrypted system using a detached LUKS header
This example follows the same setup as in [dm-crypt/Encrypting an entire system#Plain dm-crypt](../../en/Dm-crypt/Encrypting_an_entire_system.html#Plain_dm-crypt "Dm-crypt/Encrypting an entire system"), which should be read first before following this guide.
By using a detached header the encrypted blockdevice itself only carries encrypted data, which gives [deniable encryption](https://en.wikipedia.org/wiki/Deniable_encryption "wikipedia:Deniable encryption") as long as the existence of a header is unknown to the attackers. It is similar to using [plain dm-crypt](../../en/Dm-crypt/Encrypting_an_entire_system.html#Plain_dm-crypt "Dm-crypt/Encrypting an entire system"), but with the LUKS advantages such as multiple passphrases for the masterkey and key derivation. Further, using a detached header offers a form of two factor authentication with an easier setup than [using GPG or OpenSSL encrypted keyfiles](#Using_GPG,_LUKS,_or_OpenSSL_Encrypted_Keyfiles), while still having a built-in password prompt for multiple retries. See [Data-at-rest encryption#Cryptographic metadata](../../en/Data-at-rest_encryption.html#Cryptographic_metadata "Data-at-rest encryption") for more information.
See [dm-crypt/Device encryption#Encryption options for LUKS mode](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_LUKS_mode "Dm-crypt/Device encryption") for encryption options before performing the first step to setup the encrypted system partition and creating a header file to use with `cryptsetup`:
```
# dd if=/dev/zero of=header.img bs=16M count=1
# cryptsetup luksFormat --offset 32768 --header header.img /dev/sdX
```
**Tip:** The `--offset` option allows specifying the start of encrypted data on a device. By reserving a space at the beginning of device you have the option of later [reattaching the LUKS header](../../en/Dm-crypt/Device_encryption.html#Restore_using_cryptsetup "Dm-crypt/Device encryption"). The value is specified in 512-byte sectors, see [cryptsetup-luksFormat(8)](https://man.archlinux.org/man/cryptsetup-luksFormat.8) for more details.
Open the container:
```
# cryptsetup open --header header.img /dev/sdX enc
```
Now follow the [LVM on LUKS setup](../../en/Dm-crypt/Encrypting_an_entire_system.html#Preparing_the_non-boot_partitions "Dm-crypt/Encrypting an entire system") to your requirements. The same applies for [preparing the boot partition](../../en/Dm-crypt/Encrypting_an_entire_system.html#Preparing_the_boot_partition_4 "Dm-crypt/Encrypting an entire system") on the removable device (because if not, there is no point in having a separate header file for unlocking the encrypted disk). Next move the `header.img` onto it:
```
# mv header.img /mnt/boot
```
Follow the installation procedure up to the mkinitcpio step (you should now be `arch-chroot`ed inside the encrypted system).
**Tip:** You will notice that since the system partition only has "random" data, it does not have a partition table and by that an `UUID` or a `LABEL`. But you can still have a consistent mapping using the [Persistent block device naming#by-id and by-path](../../en/Persistent_block_device_naming.html#by-id_and_by-path "Persistent block device naming"). E.g. using disk id from `/dev/disk/by-id/`.
There are two options for initramfs to support a detached LUKS header.
### Using systemd hook
Set the following [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters"):
```
rd.luks.name=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=enc rd.luks.options=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=header=/header.img:UUID=ZZZZZZZZ-ZZZZ-ZZZZ-ZZZZ-ZZZZZZZZZZZZ rd.luks.data=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=/dev/disk/by-id/your-disk_id
```
* Replace `XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX` with the LUKS super block UUID. It can be acquired with `cryptsetup luksDump header.img` or `blkid -s UUID -o value header.img`.
* Replace `UUID=ZZZZZZZZ-ZZZZ-ZZZZ-ZZZZ-ZZZZZZZZZZZZ` with the block device of volume in which the header file is located.
Alternatively, instead of using the `rd.luks` kernel parameters, the options can be specified in a `/etc/crypttab.initramfs` file:
```
/etc/crypttab.initramfs
```
```
enc /dev/disk/by-id/your-disk_id none header=/header.img:UUID=ZZZZZZZZ-ZZZZ-ZZZZ-ZZZZ-ZZZZZZZZZZZZ
```
Next, modify `/etc/mkinitcpio.conf` [to use systemd](../../en/Mkinitcpio.html#Common_hooks "Mkinitcpio") and to include the [file system](../../en/File_systems.html "File system") module for the volume in which the header is located. For example, if it is a [FAT](../../en/FAT.html "FAT") volume:
```
/etc/mkinitcpio.conf
```
```
...
MODULES=(vfat)
...
HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt lvm2 filesystems fsck)
...
```
[Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs") and you are done.
**Note:**
* When using `/etc/crypttab.initramfs`, no cryptsetup parameters need to be passed to the kernel command line, since `/etc/crypttab.initramfs` will be added as `/etc/crypttab` in the initramfs.
* Refrain from using the `rd.luks` kernel parameters together with `/etc/crypttab.initramfs` as it can cause conflicts. See the warning in [dm-crypt/System configuration#Using systemd-cryptsetup-generator](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Dm-crypt/System configuration") for details.
### Modifying encrypt hook
This method shows how to modify the `encrypt` hook in order to use a detached LUKS header. Now the `encrypt` hook has to be modified to let `cryptsetup` use the separate header ([FS#42851](https://bugs.archlinux.org/task/42851); base source and idea for these changes [published on the BBS](https://bbs.archlinux.org/viewtopic.php?pid=1076346#p1076346)). Make a copy so it is not overwritten on a [mkinitcpio](../../en/Mkinitcpio.html "Mkinitcpio") update:
```
# cp /usr/lib/initcpio/hooks/encrypt /etc/initcpio/hooks/encrypt2
# cp /usr/lib/initcpio/install/encrypt /etc/initcpio/install/encrypt2
```
```
/etc/initcpio/hooks/encrypt2 (around line 52)
```
```
warn_deprecated() {
echo "The syntax 'root=${root}' where '${root}' is an encrypted volume is deprecated"
echo "Use 'cryptdevice=${root}:root root=/dev/mapper/root' instead."
}
local headerFlag=false
for cryptopt in ${cryptoptions//,/ }; do
case ${cryptopt} in
allow-discards)
cryptargs="${cryptargs} --allow-discards"
;;
header)
cryptargs="${cryptargs} --header /boot/header.img"
headerFlag=true
;;
*)
echo "Encryption option '${cryptopt}' not known, ignoring." >&2
;;
esac
done
if resolved=$(resolve_device "${cryptdev}" ${rootdelay}); then
if $headerFlag || cryptsetup isLuks ${resolved} >/dev/null 2>&1; then
[ ${DEPRECATED_CRYPT} -eq 1 ] && warn_deprecated
dopassphrase=1
```
Now edit the [mkinitcpio.conf](../../en/Mkinitcpio.html#Configuration "Mkinitcpio.conf") to add the `encrypt2` and `lvm2` hooks, the `header.img` to `FILES` and the `loop` to `MODULES`, apart from other configuration the system requires:
```
/etc/mkinitcpio.conf
```
```
...
MODULES=(loop)
...
FILES=(/boot/header.img)
...
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block encrypt2 lvm2 filesystems fsck)
...
```
This is required so the LUKS header is available on boot allowing the decryption of the system, exempting us from a more complicated setup to mount another separate USB device in order to access the header. After this set up [the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Mkinitcpio") is created.
Next the [boot loader is configured](../../en/Dm-crypt/Encrypting_an_entire_system.html#Configuring_the_boot_loader_4 "Dm-crypt/Encrypting an entire system") to specify the `cryptdevice=` also passing the new `header` option for this setup:
```
cryptdevice=/dev/disk/by-id/your-disk_id:enc:header
```
To finish, following [dm-crypt/Encrypting an entire system#Post-installation](../../en/Dm-crypt/Encrypting_an_entire_system.html#Post-installation "Dm-crypt/Encrypting an entire system") is particularly useful with a `/boot` partition on an USB storage medium.
|
dm-crypt/Specialties | Encrypted /boot and a detached LUKS header on USB |
## Encrypted /boot and a detached LUKS header on USB
**This article or section is out of date.**
**Reason:** This scenario was based on [\[6\]](https://wiki.archlinux.org/index.php?title=Dm-crypt/Encrypting_an_entire_system\&oldid=562642#Encrypted_boot_partition_\(GRUB\)), whose structure was then changed with [\[7\]](https://wiki.archlinux.org/index.php?title=Dm-crypt/Encrypting_an_entire_system\&diff=next\&oldid=562642). (Discuss in [Talk:Dm-crypt/Specialties#Encrypted /boot and a detached LUKS header on USB](../../en/Talk:Dm-crypt/Specialties.html#Encrypted_/boot_and_a_detached_LUKS_header_on_USB "Talk:Dm-crypt/Specialties"))
Rather than embedding the `header.img` and keyfile into the [initramfs](../../en/Arch_boot_process.html#initramfs "Initramfs") image, this setup will make your system depend entirely on the usb key rather than just the image to boot, and on the encrypted keyfile inside of the encrypted boot partition. Since the header and keyfile are not included in the [initramfs](../../en/Arch_boot_process.html#initramfs "Initramfs") image and the custom encrypt hook is specifically for the usb's [by-id](../../en/Persistent_block_device_naming.html#by-id_and_by-path "Persistent block device naming"), you will literally need the usb key to boot.
For the usb drive, since you are encrypting the drive and the keyfile inside, it is preferred to cascade the ciphers as to not use the same one twice. Whether a [meet-in-the-middle](https://en.wikipedia.org/wiki/Meet-in-the-middle_attack "wikipedia:Meet-in-the-middle attack") attack would actually be feasible is debatable. You can do twofish-serpent or serpent-twofish.
### Preparing the disk devices
`sdb` will be assumed to be the USB drive, `sda` will be assumed to be the main hard drive.
Prepare the devices according to [dm-crypt/Drive preparation](../../en/Dm-crypt/Drive_preparation.html "Dm-crypt/Drive preparation").
#### Preparing the USB key
Use [gdisk](../../en/GPT_fdisk.html "Gdisk") to partition the disk according to the layout [shown here](../../en/Dm-crypt/Encrypting_an_entire_system.html#Preparing_the_disk_5 "Dm-crypt/Encrypting an entire system"), with the exception that it should only include the first two partitions. So as follows:
```
# gdisk /dev/sdb
```
```
Number Start (sector) End (sector) Size Code Name
1 2048 1050623 512.0 MiB EF00 EFI System
2 1050624 1460223 200.0 MiB 8300 Linux filesystem
```
Before running `cryptsetup`, look at the [Encryption options for LUKS mode](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_LUKS_mode "Dm-crypt/Device encryption") and [Ciphers and modes of operation](../../en/Data-at-rest_encryption.html#Ciphers_and_modes_of_operation "Disk encryption") first to select your desired settings.
[Prepare the boot partition](../../en/Dm-crypt/Encrypting_an_entire_system.html#Preparing_the_boot_partition "Dm-crypt/Encrypting an entire system") but do not `mount` any partition yet and [Format the EFI system partition](../../en/EFI_system_partition.html#Format_the_partition "EFI system partition").
```
# mount /dev/mapper/cryptboot /mnt
# dd if=/dev/urandom of=/mnt/key.img bs=filesize count=1
# cryptsetup luksFormat /mnt/key.img
# cryptsetup open /mnt/key.img lukskey
```
*filesize* is in bytes but can be followed by a suffix such as `M`. Having too small of a file will get you a nasty `Requested offset is beyond real size of device /dev/loop0` error. As a rough reference, creating a 4M file will encrypt it successfully. You should make the file larger than the space needed since the encrypted loop device will be a little smaller than the file's size.
With a big file, you can use `--keyfile-offset=offset` and `--keyfile-size=size` to navigate to the correct position (see [Gentoo:Custom Initramfs#Encrypted keyfile](https://wiki.gentoo.org/wiki/Custom_Initramfs#Encrypted_keyfile "gentoo:Custom Initramfs")).
Now you should have `lukskey` opened in a loop device (underneath `/dev/loop1`), mapped as `/dev/mapper/lukskey`.
#### The main drive
```
# truncate -s 16M /mnt/header.img
# cryptsetup --key-file=/dev/mapper/lukskey --keyfile-offset=offset --keyfile-size=size luksFormat /dev/sda --offset 32768 --header /mnt/header.img
```
Pick an *offset* and *size* in bytes (8192 KiB is the maximum keyfile size for `cryptsetup`).
```
# cryptsetup open --header /mnt/header.img --key-file=/dev/mapper/lukskey --keyfile-offset=offset --keyfile-size=size /dev/sda enc
# cryptsetup close lukskey
# umount /mnt
```
Follow [Preparing the logical volumes](../../en/Dm-crypt/Encrypting_an_entire_system.html#Preparing_the_logical_volumes "Dm-crypt/Encrypting an entire system") to set up LVM on LUKS.
See [Partitioning#Discrete partitions](../../en/Partitioning.html#Discrete_partitions "Partitioning") for recommendations on the size of your partitions.
Once your root partition is mounted, `mount` your encrypted boot partition as `/mnt/boot` and your EFI system partition as `/mnt/efi`.
### Installation procedure and custom encrypt hook
Follow the [installation guide](../../en/Installation_guide.html "Installation guide") up to the `mkinitcpio` step but do not do it yet, and skip the partitioning, formatting, and mounting steps as they have already been done.
In order to get the encrypted setup to work, you need to build your own hook, which is thankfully easy to do and here is the code you need. You will have to follow [Persistent block device naming#by-id and by-path](../../en/Persistent_block_device_naming.html#by-id_and_by-path "Persistent block device naming") to figure out your own `by-id` values for the usb and main hard drive (they are linked -> to `sda` or `sdb`).
You should be using the `by-id` instead of just `sda` or `sdb` because `sdX` can change and this ensures it is the correct device.
You can name `customencrypthook` anything you want, and custom build hooks can be placed in the `hooks` and `install` folders of `/etc/initcpio`. Keep a backup of both files (`cp` them over to the `/home` partition or your user's `/home` directory after you make one). `/usr/bin/ash` is not a typo.
```
/etc/initcpio/hooks/customencrypthook
```
```
#!/usr/bin/ash
run_hook() {
modprobe -a -q dm-crypt >/dev/null 2>&1
modprobe loop
[ "${quiet}" = "y" ] && CSQUIET=">/dev/null"
while [ ! -L '/dev/disk/by-id/usbdrive-part2' ]; do
echo 'Waiting for USB'
sleep 1
done
cryptsetup open /dev/disk/by-id/usbdrive-part2 cryptboot
mount --mkdir /dev/mapper/cryptboot /mnt
cryptsetup open /mnt/key.img lukskey
cryptsetup --header /mnt/header.img --key-file=/dev/mapper/lukskey --keyfile-offset=''offset'' --keyfile-size=''size'' open /dev/disk/by-id/harddrive enc
cryptsetup close lukskey
umount /mnt
}
```
`usbdrive` is your USB drive `by-id`, and `harddrive` is your main hard drive `by-id`.
**Tip:** You could also close `cryptboot` using `cryptsetup close`, but having it open makes it easier to mount for system updates using [Pacman](../../en/Pacman.html "Pacman") and regenerating the initramfs with [mkinitcpio](../../en/Mkinitcpio.html "Mkinitcpio"). The `/boot` partition must be mounted for updates that affect the [kernel](../../en/Kernel.html "Kernel") or [Initramfs](../../en/Arch_boot_process.html#initramfs "Initramfs"), and the initramfs will be automatically regenerated after these updates.
```
# cp /usr/lib/initcpio/install/encrypt /etc/initcpio/install/customencrypthook
```
Now edit the copied file and remove the `help()` section as it is not necessary.
```
/etc/mkinitcpio.conf (edit this only do not replace it, these are just excerpts of the necessary parts)
```
```
MODULES=(loop)
...
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block customencrypthook lvm2 filesystems fsck)
```
The `files=()` and `binaries=()` arrays are empty, and you should not have to replace `HOOKS=(...)` array entirely just edit in `customencrypthook lvm2` after `block` and before `filesystems`, and make sure `systemd` and `encrypt` are removed.
#### Boot loader
Finish the [Installation Guide](../../en/Installation_guide.html#Initramfs "Installation guide") from the `mkinitcpio` step. To boot you would need either [GRUB](../../en/GRUB.html "GRUB") or [efibootmgr](../../en/Unified_Extensible_Firmware_Interface.html#efibootmgr "Efibootmgr"). Note you can use [GRUB](../../en/GRUB.html "GRUB") to support the encrypted disks by [Configuring the boot loader](../../en/Dm-crypt/Encrypting_an_entire_system.html#Configuring_the_boot_loader "Dm-crypt/Encrypting an entire system") but editing the `GRUB_CMDLINE_LINUX` is not necessary for this set up.
Or use direct UEFI Secure Boot by generating keys with [cryptboot](https://aur.archlinux.org/packages/cryptboot/)AUR then signing the initramfs and kernel and creating a bootable *.efi* file for your EFI system partition with [sbupdate-git](https://aur.archlinux.org/packages/sbupdate-git/)AUR. Before using cryptboot or sbupdate note this excerpt from [Secure Boot#Using your own keys](../../en/Unified_Extensible_Firmware_Interface/Secure_Boot.html#Using_your_own_keys "Secure Boot"):
**Tip:** Note that [cryptboot](https://aur.archlinux.org/packages/cryptboot/)AUR requires the encrypted boot partition to be specified in `/etc/crypttab` before it runs, and if you are using it in combination with [sbupdate-git](https://aur.archlinux.org/packages/sbupdate-git/)AUR, sbupdate expects the `/boot/efikeys/db.*` files created by cryptboot to be capitalized like `DB.*` unless otherwise configured in `/etc/default/sbupdate`. Users who do not use systemd to handle encryption may not have anything in their `/etc/crypttab` file and would need to create an entry.
```
# efibootmgr --create --disk /dev/device --part partition_number --label "Arch Linux Signed" --loader "EFI\Arch\linux-signed.efi" --unicode
```
See [efibootmgr(8)](https://man.archlinux.org/man/efibootmgr.8) for an explanation of the options.
Make sure the boot order puts `Arch Linux Signed` first. If not change it with `efibootmgr --bootorder XXXX,YYYY,ZZZZ --unicode`.
### Changing the LUKS keyfile
**This article or section is a candidate for merging with [dm-crypt/Device encryption#Keyfiles](../../en/Dm-crypt/Device_encryption.html#Keyfiles "Dm-crypt/Device encryption").**
**Notes:** Changing the keyfile is not a required action in this setup. (Discuss in [Talk:Dm-crypt/Specialties](../../en/Talk:Dm-crypt/Specialties.html))
```
# cryptsetup --header /boot/header.img --key-file=/dev/mapper/lukskey --keyfile-offset=offset --keyfile-size=size luksChangeKey /dev/mapper/enc /dev/mapper/lukskey2 --new-keyfile-size=newsize --new-keyfile-offset=newoffset
```
Afterwards, `cryptsetup close lukskey` and [shred](../../en/Securely_wipe_disk.html#shred "Shred") or [dd](../../en/Securely_wipe_disk.html#dd "Securely wipe disk") the old keyfile with random data before deleting it, then make sure that the new keyfile is renamed to the same name of the old one: `key.img` or other name.
[Category](../../Special:Categories.html "Special:Categories"):
* [Data-at-rest encryption](../../en/Category:Data-at-rest_encryption.html "Category:Data-at-rest encryption")
Hidden categories:
* [Pages or sections flagged with Template:Accuracy](../../en/Category:Pages_or_sections_flagged_with_Template:Accuracy.html "Category:Pages or sections flagged with Template:Accuracy")
* [Pages or sections flagged with Template:Out of date](../../en/Category:Pages_or_sections_flagged_with_Template:Out_of_date.html "Category:Pages or sections flagged with Template:Out of date")
* [Pages or sections flagged with Template:Merge](../../en/Category:Pages_or_sections_flagged_with_Template:Merge.html "Category:Pages or sections flagged with Template:Merge")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Dm-crypt/Specialties&oldid=803829>"
- This page was last edited on 18 March 2024, at 08:18.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
dm-crypt/Swap encryption | Intro |
# dm-crypt/Swap encryption
\[ ] 5 languages
* [Español](../../es/Dm-crypt/Swap_encryption.html "Dm-crypt (Español)/Swap encryption – español")
* [日本語](https://wiki.archlinux.jp/index.php/Dm-crypt/%E3%82%B9%E3%83%AF%E3%83%83%E3%83%97%E3%81%AE%E6%9A%97%E5%8F%B7%E5%8C%96 "Dm-crypt/スワップの暗号化 – 日本語")
* [Polski](../../pl/Dm-crypt/Swap_encryption.html "Dm-crypt (Polski)/Swap encryption – polski")
* [Português](../../pt/Dm-crypt/Swap_encryption.html "Dm-crypt (Português)/Swap encryption – português")
* [Українська](../../uk/Dm-crypt/Swap_encryption.html "Dm-crypt (Українська)/Swap encryption – українська")
From ArchWiki
< [Dm-crypt](../../en/Dm-crypt.html "Dm-crypt")
Depending on requirements, different methods may be used to encrypt the [swap](../../en/Swap.html "Swap") partition which are described in the following. A setup where the swap encryption is re-initialised on reboot (with a new encryption) provides higher data protection, because it avoids sensitive file fragments which may have been swapped out a long time ago without being overwritten. However, re-encrypting swap also forbids using a suspend-to-disk feature generally.
|
dm-crypt/Swap encryption | Without suspend-to-disk support |
## Without suspend-to-disk support
In systems where suspend-to-disk (hibernation) is not a desired feature, `/etc/crypttab` can be set up to decrypt the swap partition with a random password with plain dm-crypt at boot-time. The random password is discarded on shutdown, leaving behind only encrypted, inaccessible data in the swap device.
To enable this feature, simply uncomment the line beginning with `swap` in `/etc/crypttab`. Change the `<device>` parameter to the name of your swap device. For example, it will look something like this:
```
/etc/crypttab
```
```
# <name> <device> <password> <options>
swap /dev/sdX# /dev/urandom swap,cipher=aes-xts-plain64,size=512
```
This will map `/dev/sdX#` to `/dev/mapper/swap` as a swap partition that can be added in `/etc/fstab` like a normal swap. If you had a non-encrypted swap partition before, do not forget to disable it - or re-use its [fstab](../../en/Fstab.html "Fstab") entry by changing the device to `/dev/mapper/swap`. The default options should be sufficient for most usage. For other options and an explanation of each column, see [crypttab(5)](https://man.archlinux.org/man/crypttab.5) as well as [point cryptsetup FAQ 2.3](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions#2-setup).
**Warning:** All contents of the named device will be permanently **deleted**. It is dangerous to use the kernel's simple naming for a swap device, since their naming order (*e.g.* `/dev/sda`, `/dev/sdb`) changes upon each boot. Options are:
* Use `by-id` and `by-path` paths. However, these are both are susceptible to hardware changes. See [Persistent block device naming#by-id and by-path](../../en/Persistent_block_device_naming.html#by-id_and_by-path "Persistent block device naming").
* Use [PARTLABEL](../../en/Persistent_block_device_naming.html#by-partlabel "PARTLABEL").
* Use an [LVM](../../en/LVM.html "LVM") logical volume's name.
* Use the method described in [#UUID and LABEL](#UUID_and_LABEL). Labels and [UUIDS](../../en/Persistent_block_device_naming.html#by-uuid "Persistent block device naming") **cannot** be used directly because of the recreation and re-encryption of the swap device on every boot with `mkswap`, see [cryptsetup FAQ](https://gitlab.com/cryptsetup/cryptsetup/wikis/FrequentlyAskedQuestions#2-setup).
**Note:** Swap partition setup can sometimes fail, see [systemd issue 10179](https://github.com/systemd/systemd/issues/10179).
To use a `by-id` persistent device naming instead of kernel simple naming, first identify the swap device:
```
# find -L /dev/disk -samefile /dev/sdaX
```
```
/dev/disk/by-id/ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470-partX
/dev/disk/by-id/wwn-0x60015ee0000b237f-partX
```
Then use as a persistent reference for the `/dev/sdX#` example partition (if two results are returned as above, choose either one of them):
```
/etc/crypttab
```
```
# <name> <device> <password> <options>
swap /dev/disk/by-id/ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470-partX /dev/urandom swap,cipher=aes-xts-plain64,size=512
```
After a reboot to activate the encrypted swap, you will note that running `swapon -s` shows an arbitrary device mapper entry (e.g. `/dev/dm-1`) for it, while the `lsblk` command shows **crypt** in the `FSTYPE` column. Due to fresh encryption each boot, the UUID for `/dev/mapper/swap` will change every time.
**Note:** If the partition chosen for swap was previously a LUKS partition, crypttab will not overwrite the partition to create a swap partition. This is a safety measure to prevent data loss from accidental mis-identification of the swap partition in crypttab. In order to use such a partition the [LUKS header must be overwritten](../../en/Dm-crypt/Drive_preparation.html#Wipe_LUKS_header "Dm-crypt/Drive preparation") once.
### UUID and LABEL
It is dangerous to use crypttab swap with simple kernel device names like `/dev/sdX#` or even `/dev/disk/by-id/ata-SERIAL-partX`. A small change in your device names or partitioning layout and `/etc/crypttab` will see your valuable data formatted on the next boot. Same if you use PARTUUID and then decide to use that partition for something else without removing the crypttab entry first.
It is more reliable to identify the correct partition by giving it a genuine UUID or LABEL. By default that does not work because dm-crypt and `mkswap` would simply overwrite any content on that partition which would remove the UUID and LABEL too; however, it is possible to specify a swap offset. This allows you to create a very small, empty, bogus filesystem with no other purpose than providing a persistent UUID or LABEL for the swap encryption.
Create a [filesystem](../../en/File_systems.html "Filesystem") with label of your choice:
```
# mkfs.ext2 -L cryptswap /dev/sdX# 1M
```
The unusual parameter after the device name limits the filesystem size to 1 MiB, leaving room for encrypted swap behind it.
```
# blkid /dev/sdX#
```
```
/dev/sdX#: LABEL="cryptswap" UUID="b72c384e-bd3c-49aa-b7a7-a28ea81a2605" TYPE="ext2"
```
With this, `/dev/sdX#` now can easily be identified either by UUID or LABEL, regardless of how its device name or even partition number might change in the future. All that is left are the `/etc/crypttab` and `/etc/fstab` entries. For example, using different encryption options:
```
/etc/crypttab
```
```
# <name> <device> <password> <options>
swap LABEL=cryptswap /dev/urandom swap,offset=2048,cipher=aes-xts-plain64,size=512
```
Note the offset: it is 2048 sectors of 512 bytes, thus 1 MiB. This way the encrypted swap will not affect the filesystem LABEL/UUID, and data alignment works out as well.
```
/etc/fstab
```
```
# <filesystem> <dir> <type> <options> <dump> <pass>
/dev/mapper/swap none swap defaults 0 0
```
Using this setup, the cryptswap will only try to use the partition with the corresponding LABEL, regardless of what its device name may be. Should you decide to use the partition for something else, by formatting it the cryptswap LABEL would also be gone, so `/etc/crypttab` will not overwrite it on your next boot.
### Disabling hibernation in desktop environments
Desktop environments may not automatically detect that a swap partition is randomly encrypted and cannot be used for suspend-to-disk.
[Xfce](../../en/Xfce.html "Xfce") can be configured to hide its *Hibernate* button by running this command:
```
$ xfconf-query -c xfce4-session -np /shutdown/ShowHibernate -t bool -s false
```
|
dm-crypt/Swap encryption | With suspend-to-disk support |
## With suspend-to-disk support
To be able to resume after suspending the computer to disk (hibernate), it is required to keep the swap space intact. Therefore, it is required to have a pre-existent LUKS swap partition or file, which can be stored on the disk or input manually at startup.
The following three methods are alternatives for setting up an encrypted swap for suspend-to-disk. If you apply any of them, be aware that critical data swapped out by the system may potentially stay in the swap over a long period (i.e. until it is overwritten). To reduce this risk consider setting up a system job which re-encrypts swap, e.g. each time the system is going into a regular shut-down, along with the method of your choice.
### LVM on LUKS
If the swap volume is in a volume group that gets activated in initramfs, simply follow the instructions in [Power management/Suspend and hibernate#Hibernation](../../en/Power_management/Suspend_and_hibernate.html#Hibernation "Power management/Suspend and hibernate").
### Using a swap partition
If you want to use a partition which is currently used by the system, you have to disable it first:
```
# swapoff /dev/<device>
```
Also make sure you remove any line in `/etc/crypttab` pointing to this device.
If you are reusing an existing swap [partition](../../en/Partitioning.html "Partition"), and if the partition is on a GPT partition table, you will need use [gdisk](../../en/GPT_fdisk.html "Gdisk") to set the [partition attribute 63 "do not automount"](../../en/GPT_fdisk.html#Prevent_GPT_partition_automounting "Gdisk") on it. This will prevent systemd-gpt-auto-generator from discovering and enabling the partition at boot.
The following setup has the disadvantage of having to insert an additional passphrase for the swap partition manually on every boot.
**Warning:** Do not use this setup with a key file if `/boot` is unencrypted. Please read about the issue reported [here](https://wiki.archlinux.org/index.php?title=Talk:Dm-crypt\&oldid=255742#Suspend_to_disk_instructions_are_insecure). Alternatively, use a gnupg-encrypted keyfile as per <https://bbs.archlinux.org/viewtopic.php?id=120181>
To format the encrypted container for the swap partition, create a keyslot for a user-memorizable passphrase.
```
# cryptsetup luksFormat /dev/<device>
```
Open the partition in `/dev/mapper`:
```
# cryptsetup open /dev/<device> swapDevice
```
Create a swap filesystem inside the mapped partition:
```
# mkswap /dev/mapper/swapDevice
```
Add the mapped partition to `/etc/fstab` by adding the following line:
```
/dev/mapper/swapDevice swap swap defaults 0 0
```
Set up your system to resume from `/dev/mapper/swapDevice`. For example, if you use [GRUB](../../en/GRUB.html "GRUB") with kernel hibernation support, add the kernel parameter `resume=/dev/mapper/swapDevice` to GRUB by appending it to the `GRUB_CMDLINE_LINUX_DEFAULT` variable in `/etc/default/grub`. A kernel line with encrypted root and swap partitions can look like this:
```
kernel /vmlinuz-linux cryptdevice=/dev/sda2:rootDevice root=/dev/mapper/rootDevice resume=/dev/mapper/swapDevice ro
```
#### mkinitcpio hook
To resume from an encrypted swap partition, the encrypted partition must be unlocked in the initramfs.
* When using the default busybox-based initramfs with the [encrypt](../../en/Dm-crypt/System_configuration.html#Using_encrypt_hook "Dm-crypt/System configuration") hook, follow the instructions in [#mkinitcpio hook](#mkinitcpio_hook).
* When using the systemd-based initramfs with the [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") mkinitcpio hook, simply specify additional `rd.luks` kernel parameters to unlock the swap partition.
If the swap device is on a different device from that of the root file system, it will not be opened by the `encrypt` hook, i.e. the resume will take place before `/etc/crypttab` can be used, therefore it is required to create a hook in `/etc/mkinitcpio.conf` to open the swap LUKS device before resuming.
**This article or section is a candidate for merging with [dm-crypt/Specialties#Multiple non-root partitions](../../en/Dm-crypt/Specialties.html#Multiple_non-root_partitions "Dm-crypt/Specialties").**
**Notes:** Same use case. (Discuss in [Talk:Dm-crypt/Swap encryption](../../en/Talk:Dm-crypt/Swap_encryption.html))
**Note:** This section is only applicable when using the `encrypt` hook, which can only unlock a single device ([FS#23182](https://bugs.archlinux.org/task/23182)). With `sd-encrypt` multiple devices may be unlocked, see [dm-crypt/System configuration#Using systemd-cryptsetup-generator](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Dm-crypt/System configuration").
Now you have to create a hook to open the swap at boot time. You can either [install](../../en/Help:Reading.html#Installation_of_packages "Install") and configure [mkinitcpio-openswap](https://aur.archlinux.org/packages/mkinitcpio-openswap/)AUR, or follow the following instructions. Create a hook file containing the open command:
```
/etc/initcpio/hooks/openswap
```
```
run_hook ()
{
cryptsetup open /dev/<device> swapDevice
}
```
**Warning:** Mounting the file system [is dangerous and destructive](https://docs.kernel.org/power/swsusp.html). The keyfile should not be read from a file system that was mounted when the system was suspended.
**This article or section needs expansion.**
**Reason:** Add instructions that would not lead to data loss. (Discuss in [Talk:Dm-crypt/Swap encryption](../../en/Talk:Dm-crypt/Swap_encryption.html))
for opening the swap device by typing your password or
```
/etc/initcpio/hooks/openswap
```
```
run_hook ()
{
## Optional: To avoid race conditions
x=0;
while [ ! -b /dev/mapper/<root-device> ] && [ $x -le 10 ]; do
x=$((x+1))
sleep .2
done
## End of optional
mkdir crypto_key_device
mount /dev/mapper/<root-device> crypto_key_device
cryptsetup open --key-file crypto_key_device/<path-to-the-key> /dev/<device> swapDevice
umount crypto_key_device
}
```
for opening the swap device by loading a keyfile from a crypted root device.
On some computers race conditions may occur when mkinitcpio tries to mount the device before the decryption process and device enumeration is completed. The commented *Optional* block will delay the boot process up to 2 seconds until the root device is ready to mount.
**Note:** If swap is on a Solid State Disk (SSD) and Discard/TRIM is desired the option `--allow-discards` has to get added to the cryptsetup line in the openswap hook above. See [Dm-crypt/Specialties#Discard/TRIM support for solid state drives (SSD)](../../en/Dm-crypt/Specialties.html#Discard/TRIM_support_for_solid_state_drives_\(SSD\) "Dm-crypt/Specialties") or [SSD](../../en/Solid_state_drive.html "SSD") for more information on discard. Additionally you have to add the mount option 'discard' to your fstab entry for the swap device.
Then create and edit the hook setup file:
```
/etc/initcpio/install/openswap
```
```
build ()
{
add_runscript
}
help ()
{
cat<<HELPEOF
This opens the swap encrypted partition /dev/<device> in /dev/mapper/swapDevice
HELPEOF
}
```
Add the hook `openswap` in the `HOOKS` array in `/etc/mkinitcpio.conf`, before `filesystem` but after `encrypt`. Do not forget to add the `resume` hook after `openswap`.
```
HOOKS=(... encrypt openswap resume filesystems ...)
```
[Regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs").
At boot time, the `openswap` hook will open the swap partition so the kernel resume may use it. If you use special hooks for resuming from hibernation, make sure they are placed **after** `openswap` in the `HOOKS` array. Please note that because of initrd opening swap, there is no entry for swapDevice in `/etc/crypttab` needed in this case.
#### dracut
Create a keyfile:
```
# dd bs=512 count=4 if=/dev/random of=/etc/cryptsetup-keys.d/swap.key iflag=fullblock
```
Unset permissions:
```
# chmod 0 /etc/cryptsetup-keys.d/swap.key
```
Add the keyfile to LUKS:
```
# cryptsetup luksAddKey /dev/<device> /etc/cryptsetup-keys.d/swap.key
```
Configure dracut to include the `resume` module and add the `swap.key` file to the initramfs (See also [dracut#Hibernation](../../en/Dracut.html#Hibernation "Dracut")):
```
/etc/dracut.conf.d/resume-from-hibernate.conf
```
```
add_dracutmodules+=" resume "
install_items+=" /etc/cryptsetup-keys.d/swap.key "
```
[Regenerate the initramfs](../../en/Dracut.html#Usage "Dracut").
Add the `rd.luks.name` and `rd.luks.key` (replace the swap's partition UUID) entries to your kernel command line. Your kernel command might look like this now:
```
kernel /vmlinuz-linux cryptdevice=/dev/sda2:rootDevice root=/dev/mapper/rootDevice resume=/dev/mapper/swapDevice rd.luks.name=fd839505-3213-4603-9a70-c5a96a24768f=swapDevice rd.luks.key=/etc/cryptsetup-keys.d/swap.key ro
```
### Using a swap file
A swap file can be used to reserve swap-space within an existing partition and may also be setup inside an encrypted blockdevice's partition.
Follow swap file creation instructions in [Swap#Swap file](../../en/Swap.html#Swap_file "Swap") and set up hibernation according to [Power management/Suspend and hibernate#Acquire swap file offset](../../en/Power_management/Suspend_and_hibernate.html#Acquire_swap_file_offset "Power management/Suspend and hibernate").
**Note:**
* When resuming from a swapfile the `resume` parameter must point to the unlocked/mapped device that contains the file system with the swap file.
* Ensure that the resume hook of mkinitcpio is ran after the device the swap partition lives on is unlocked by placing `resume` after `encrypt` in the `HOOKS` array.
|
dm-crypt/Swap encryption | Known issues |
## Known issues
* `Stopped (with error) /dev/dm-1` in logs. See [systemd issue 1620](https://github.com/systemd/systemd/issues/1620).
[Category](../../Special:Categories.html "Special:Categories"):
* [Data-at-rest encryption](../../en/Category:Data-at-rest_encryption.html "Category:Data-at-rest encryption")
Hidden categories:
* [Pages or sections flagged with Template:Merge](../../en/Category:Pages_or_sections_flagged_with_Template:Merge.html "Category:Pages or sections flagged with Template:Merge")
* [Pages or sections flagged with Template:Expansion](../../en/Category:Pages_or_sections_flagged_with_Template:Expansion.html "Category:Pages or sections flagged with Template:Expansion")
- Retrieved from "<https://wiki.archlinux.org/index.php?title=Dm-crypt/Swap_encryption&oldid=805540>"
- This page was last edited on 8 April 2024, at 15:22.
- Content is available under [GNU Free Documentation License 1.3 or later](https://www.gnu.org/copyleft/fdl.html) unless otherwise noted.
* [Privacy policy](https://terms.archlinux.org/docs/privacy-policy/)
* [About ArchWiki](../../en/ArchWiki:About.html)
* [Disclaimers](../../en/ArchWiki:General_disclaimer.html)
* [Code of conduct](https://terms.archlinux.org/docs/code-of-conduct/ "archlinux-service-agreements:code-of-conduct")
* [Terms of service](https://terms.archlinux.org/docs/terms-of-service/ "archlinux-service-agreements:terms-of-service")
- [](https://www.gnu.org/copyleft/fdl.html)
- 
* Toggle limited content width
|
dm-crypt/System configuration | Intro |
# dm-crypt/System configuration
\[ ] 3 languages
* [Español](../../es/Dm-crypt/System_configuration.html "Dm-crypt (Español)/System configuration – español")
* [日本語](https://wiki.archlinux.jp/index.php/dm-crypt/%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E8%A8%AD%E5%AE%9A "dm-crypt/システム設定 – 日本語")
* [Português](../../pt/Dm-crypt/System_configuration.html "Dm-crypt (Português)/System configuration – português")
From ArchWiki
< [Dm-crypt](../../en/Dm-crypt.html "Dm-crypt")
**This article or section needs expansion.**
**Reason:** Aggregate here all the generic information on system configuration from the other sub-articles of [dm-crypt](../../en/Dm-crypt.html "Dm-crypt"). (Discuss in [Talk:Dm-crypt/System configuration](../../en/Talk:Dm-crypt/System_configuration.html))
**Tip:**
* If in need to remotely unlock root or other early-boot filesystems (headless machine, distant servers...), follow the specific instructions from [dm-crypt/Specialties#Remote unlocking of root (or other) partition](../../en/Dm-crypt/Specialties.html#Remote_unlocking_of_root_\(or_other\)_partition "Dm-crypt/Specialties").
* To ease inputting UUIDs, PARTUUIDs, etc. in configuration files, you can install and use a [text editor](../../en/List_of_applications/Documents.html#Text_editors "Text editor") that supports inserting command output (e.g. [nano](../../en/Nano.html "Nano") with `Ctrl+t`, [Vim](../../en/Vim.html "Vim") or [Neovim](../../en/Neovim.html "Neovim") with `:read` or [mcedit](../../en/Midnight_Commander.html#Modules "Mcedit") with `Alt+u`) and pass it [the apropriate lsblk or blkid command](../../en/Persistent_block_device_naming.html#Persistent_naming_methods "Persistent block device naming"). Alternatively, you can install a [terminal multiplexer](../../en/List_of_applications/Utilities.html#Terminal_multiplexers "List of applications/Utilities") and use its copy and paste functionality.
|
dm-crypt/System configuration | Unlocking in early userspace |
## Unlocking in early userspace
Booting an encrypted root volume requires that the [initramfs](../../en/Arch_boot_process.html#initramfs "Initramfs") contains the necessary tools for early userspace to unlock the volume. The instructions on what to unlock are typically passed via [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters").
The following sections describe how to configure mkinitcpio and list which kernel parameters are required.
### mkinitcpio
Depending on the particular scenarios, a subset of the following [mkinitcpio hooks](../../en/Mkinitcpio.html#HOOKS "Mkinitcpio") will have to be enabled:
| busybox | systemd | Use case |
| ------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `encrypt` | `sd-encrypt` | Needed when the root partition is encrypted or when an encrypted partition needs to be mounted *before* the root partition. Not needed in other cases as system initialization scripts like `/etc/crypttab` already take care of unlocking other non-root partitions. This hook must be placed *after* the `udev` or `systemd` hook. |
| `keyboard` | | Needed to make keyboards work in early userspace.**Tip:** For systems that are booted with different hardware configurations (e.g. laptops with external keyboard vs. internal keyboard or [headless systems](https://en.wikipedia.org/wiki/Headless_computer "wikipedia:Headless computer")), it is helpful to place this hook before `autodetect` in order to always include all keyboard drivers. Otherwise the external keyboard only works in early userspace if it was connected when creating the image. |
| `keymap` | `sd-vconsole` | Provides support for non-US keymaps for typing encryption passwords; it must come *before* the `encrypt` hook, otherwise you will need to enter your encryption password using the default US keymap. Set your keymap in `/etc/vconsole.conf`, see [Keyboard configuration in console#Persistent configuration](../../en/Linux_console/Keyboard_configuration.html#Persistent_configuration "Keyboard configuration in console"). |
| `consolefont` | | Loads an alternative console font in early userspace. Set your font in `/etc/vconsole.conf`, see [Linux console#Persistent configuration](../../en/Linux_console.html#Persistent_configuration "Linux console"). |
[Other hooks](../../en/Mkinitcpio.html#Common_hooks "Mkinitcpio") needed should be clear from other manual steps followed during the installation of the system.
**Note:** Remember to [regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs") after making any changes to `/etc/mkinitcpio.conf`.
#### Examples
A typical `/etc/mkinitcpio.conf` configuration using `encrypt` hook:
```
/etc/mkinitcpio.conf
```
```
...
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block encrypt lvm2 filesystems fsck)
...
```
A configuration with systemd-based initramfs using `sd-encrypt` hook:
```
/etc/mkinitcpio.conf
```
```
...
HOOKS=(base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt lvm2 filesystems fsck)
...
```
### Kernel parameters
The [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters") you need to specify depend on whether the `encrypt` hook or the `sd-encrypt` hook is being used. `root` and `resume` are specified the same way for both.
**Tip:** The specification of these parameters can be omitted when using the `sd-encrypt` hook and [GPT partition automounting](../../en/Systemd.html#GPT_partition_automounting "Systemd"). See [LUKS on a partition](../../en/Dm-crypt/Encrypting_an_entire_system.html#Configuring_the_boot_loader "Dm-crypt/Encrypting an entire system").
#### root
The `root=` parameter specifies the `device` of the actual (decrypted) root file system:
```
root=device
```
* If the file system is formatted directly on the decrypted device file this will be `/dev/mapper/dmname`.
* If a LVM gets activated first and contains an [encrypted logical rootvolume](../../en/Dm-crypt/Encrypting_an_entire_system.html#LUKS_on_LVM "Dm-crypt/Encrypting an entire system"), the above form applies as well.
* If the root file system is contained in a logical volume of a fully [encrypted LVM](../../en/Dm-crypt/Encrypting_an_entire_system.html#LVM_on_LUKS "Encrypted LVM"), the device mapper for it will be in the general form of `root=/dev/volumegroup/logicalvolume`.
**Tip:** When using [GRUB](../../en/GRUB.html "GRUB") and generating `grub.cfg` with *grub-mkconfig*, the `root=` parameter does not need to be specified manually. *grub-mkconfig* will determine the correct UUID of the decrypted root filesystem and add it to `grub.cfg` automatically.
#### resume
```
resume=device
```
* `device` is the device file of the decrypted (swap) filesystem used for [suspend to disk](../../en/Power_management/Suspend_and_hibernate.html#Hibernation "Power management/Suspend and hibernate"). If swap is on a separate partition, it will be in the form of `/dev/mapper/swap`. See also [dm-crypt/Swap encryption](../../en/Dm-crypt/Swap_encryption.html "Dm-crypt/Swap encryption").
#### Using encrypt hook
**Note:** Compared to the [sd-encrypt](../../en/Dm-crypt/System_configuration.html#Using_systemd-cryptsetup-generator "Sd-encrypt") hook, the `encrypt` hook does not support:
* Unlocking [multiple encrypted disks](../../en/Dm-crypt/Specialties.html#The_encrypt_hook_and_multiple_disks "Dm-crypt/Specialties") ([archlinux/mkinitcpio/mkinitcpio#231](https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio/-/issues/231)). Only **one** device can be unlocked in the initramfs.
* Using a [detached LUKS header](../../en/Dm-crypt/Specialties.html#Encrypted_system_using_a_detached_LUKS_header "Dm-crypt/Specialties") ([archlinux/mkinitcpio/mkinitcpio#234](https://gitlab.archlinux.org/archlinux/mkinitcpio/mkinitcpio/-/issues/234)).
* Setting additional options that are supported by [crypttab](#crypttab).
##### cryptdevice
This specifies the device containing the encrypted root on a cold boot. It is parsed by the `encrypt` hook to identify which device contains the encrypted system:
```
cryptdevice=device:dmname:options
```
* `device` is the path to the device backing the encrypted device. [Usage of persistent block device naming](../../en/Persistent_block_device_naming.html#Kernel_parameters "Persistent block device naming") is strongly recommended.
* `dmname` is the **d**evice-**m**apper name given to the device after decryption, which will be available as `/dev/mapper/dmname`.
* `options` (optional) are comma separated options, e.g. for TRIM support. If no options are required, omit this parameter (use `cryptdevice=device:dmname`).
* If a LVM contains the [encrypted root](../../en/Dm-crypt/Encrypting_an_entire_system.html#LUKS_on_LVM "Dm-crypt/Encrypting an entire system"), the LVM gets activated first and the volume group containing the logical volume of the encrypted root serves as *device*. It is then followed by the respective volume group to be mapped to root. The parameter follows the form of `cryptdevice=/dev/vgname/lvname:dmname`.
**Tip:** One may want to [enable Discard/TRIM support](../../en/Dm-crypt/Specialties.html#Discard/TRIM_support_for_solid_state_drives_\(SSD\) "Dm-crypt/Specialties") for solid state drives (SSD).
##### cryptkey
**Tip:** If a passphrase is to be used, the `cryptkey=` parameter does not need to be specified manually. You will then be prompted to enter the passphrase upon boot.
This parameter specifies the location of a keyfile and is required by the `encrypt` hook for reading such a keyfile to unlock the `cryptdevice` (unless a key is in the default location, see below). It can have three parameter sets, depending on whether the keyfile exists as a file in a particular device, a bitstream starting on a specific location, or a file in the initramfs.
For a file in a device the format is:
```
cryptkey=device:fstype:path
```
* `device` is the raw block device where the key exists. Usage of [persistent block device naming](../../en/Persistent_block_device_naming.html "Persistent block device naming") is strongly recommended.
* `fstype` is the filesystem type of `device` (or auto).
* `path` is the absolute path of the keyfile within the device.
Example: `cryptkey=LABEL=usbstick:vfat:/secretkey`
For a bitstream on a device the key's location is specified with the following:
```
cryptkey=device:offset:size
```
where the offset and size are in bytes. For example, `cryptkey=UUID=ZZZZZZZZ-ZZZZ-ZZZZ-ZZZZ-ZZZZZZZZZZZZ:0:512` reads a 512 byte keyfile starting at the beginning of the device.
**Tip:** If the device path you want to access contains the character `:`, you have to escape it with a backslash `\`. In that case the cryptkey parameter would be as follows: `cryptkey=/dev/disk/by-id/usb-123456-0\:0:0:512` for a USB key with the ID `usb-123456-0:0`.
For a file [included](../../en/Mkinitcpio.html#BINARIES_and_FILES "Mkinitcpio") in the initramfs the format is[\[1\]](https://gitlab.archlinux.org/archlinux/packaging/packages/cryptsetup/-/blob/main/hooks-encrypt#L14):
```
cryptkey=rootfs:path
```
Example: `cryptkey=rootfs:/secretkey`
Also note that if `cryptkey` is not specified, it defaults to `/crypto_keyfile.bin` (in the initramfs).[\[2\]](https://gitlab.archlinux.org/archlinux/packaging/packages/cryptsetup/-/blob/main/hooks-encrypt#L8)
See also [dm-crypt/Device encryption#Keyfiles](../../en/Dm-crypt/Device_encryption.html#Keyfiles "Dm-crypt/Device encryption").
##### crypto
This parameter is specific to pass *dm-crypt* plain mode options to the *encrypt* hook.
It takes the form
```
crypto=hash:cipher:keysize:offset:skip
```
The arguments relate directly to the *cryptsetup* options. See [dm-crypt/Device encryption#Encryption options for plain mode](../../en/Dm-crypt/Device_encryption.html#Encryption_options_for_plain_mode "Dm-crypt/Device encryption").
For a disk encrypted with just *plain* default options, the `crypto` arguments must be specified, but each entry can be left blank:
```
crypto=::::
```
A specific example of arguments is
```
crypto=sha512:twofish-xts-plain64:512:0:
```
#### Using systemd-cryptsetup-generator
*systemd-cryptsetup-generator* is a [systemd](../../en/Systemd.html "Systemd") unit generator that reads a subset of [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters"), and `/etc/crypttab`, for the purpose of unlocking encrypted devices. See the [systemd-cryptsetup-generator(8)](https://man.archlinux.org/man/systemd-cryptsetup-generator.8) man page for more details about it and all options it supports.
*systemd-cryptsetup-generator* is run during the [initramfs stage](../../en/Arch_boot_process.html#initramfs "Arch boot process") when using the `sd-encrypt` [mkinitcpio hook](../../en/Mkinitcpio.html#HOOKS "Mkinitcpio") or the `systemd` [dracut module](../../en/Dracut.html#dracut_modules "Dracut").
In what follows, we describe some of the [kernel parameters](../../en/Kernel_parameters.html "Kernel parameters") that *systemd-cryptsetup-generator* interprets.
**Tip:**
* If the file `/etc/crypttab.initramfs` exists, it will be added to the initramfs as `/etc/crypttab`, there you can specify devices that need to be unlocked at the initramfs phase. See [#crypttab](#crypttab) for the syntax. If `/etc/crypttab.initramfs` does not exist, there will be no `/etc/crypttab` in the initramfs and the unlockable devices will need to be specified via kernel parameters listed below.
* `/etc/crypttab.initramfs` is not limited to using only UUID like `rd.luks`. You can use any of the [persistent block device naming methods](../../en/Persistent_block_device_naming.html#Persistent_naming_methods "Persistent block device naming").
* Passwords entered during boot are cached in the kernel keyring by [systemd-cryptsetup(8)](https://man.archlinux.org/man/systemd-cryptsetup.8), so if multiple devices can be unlocked with the same password (this includes devices in [crypttab](#crypttab) that are unlocked after boot), then you will only need to input each password once.
**Note:**
* All of the `rd.luks` parameters can be specified multiple times to unlock multiple LUKS encrypted volumes.
* The `rd.luks` parameters only support unlocking LUKS devices. To unlock a plain dm-crypt device, you must specify it in `/etc/crypttab.initramfs`. See [#crypttab](#crypttab) for the syntax.
**Warning:** If you are using `/etc/crypttab` or `/etc/crypttab.initramfs` together with `luks.*` or `rd.luks.*` parameters, only those devices specified on the kernel command line will be activated and you will see `Not creating device 'devicename' because it was not specified on the kernel command line.`. This is because the `luks.*` or `rd.luks.*` parameters control which devices from the crypttab get activated. To activate all devices in `/etc/crypttab` do not specify any `luks.*` parameters and use `rd.luks.*`. To activate all devices in `/etc/crypttab.initramfs` do not specify any `luks.*` or `rd.luks.*` parameters.
##### rd.luks.uuid
**Tip:** `rd.luks.uuid` can be omitted when using `rd.luks.name`.
```
rd.luks.uuid=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
```
Specify the [UUID](../../en/Persistent_block_device_naming.html#by-uuid "UUID") of the device to be decrypted on boot with this flag.
By default, the mapped device will be located at `/dev/mapper/luks-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX` where *XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX* is the UUID of the LUKS partition.
##### rd.luks.name
**Tip:** When using this parameter you can omit `rd.luks.uuid`.
```
rd.luks.name=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=name
```
Specify the name of the mapped device after the LUKS partition is open, where *XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX* is the UUID of the LUKS partition. This is equivalent to the second parameter of `encrypt`'s `cryptdevice`.
For example, specifying `rd.luks.name=12345678-9abc-def0-1234-56789abcdef0=root` causes the unlocked LUKS device with UUID `12345678-9ABC-DEF0-1234-56789ABCDEF0` to be located at `/dev/mapper/root`.
##### rd.luks.key
Specify the location of a password file used to decrypt the device specified by its UUID. There is no default location like there is with the `encrypt` hook parameter `cryptkey`.
If the keyfile is [included in the initramfs](../../en/Mkinitcpio.html#BINARIES_and_FILES "Mkinitcpio"):
```
rd.luks.key=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=/path/to/keyfile
```
or
```
rd.luks.key=/path/to/keyfile
```
**Tip:** The whole `rd.luks.key` parameter can be omitted if the keyfile is included as `/etc/cryptsetup-keys.d/name.key`.
If the keyfile is on another device:
```
rd.luks.key=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=/path/to/keyfile:UUID=ZZZZZZZZ-ZZZZ-ZZZZ-ZZZZ-ZZZZZZZZZZZZ
```
Replace `UUID=ZZZZZZZZ-ZZZZ-ZZZZ-ZZZZ-ZZZZZZZZZZZZ` with the identifier of the device on which the keyfile is located.
**Warning:**
* If the type of file system is different than your root file system, you must [include the kernel module for it in the initramfs](../../en/Mkinitcpio.html#MODULES "Mkinitcpio").
* `rd.luks.key` with a keyfile on another device by default does not fallback to asking for a password if the device is not available. To fallback to a password prompt, specify the `keyfile-timeout=` option in `rd.luks.options`. E.g. for a 10 second timeout:
```
rd.luks.options=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=keyfile-timeout=10s
```
##### rd.luks.options
```
rd.luks.options=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=options
```
or
```
rd.luks.options=options
```
Set options for the device specified by it UUID or, if not specified, for all UUIDs not specified elsewhere (e.g., crypttab).
This parameter is the analogue of [crypttab's](#crypttab) options field. The format is the same—options are separated by commas, options with values are specified using `option=value`. This is roughly equivalent to the third parameter of `encrypt`'s `cryptdevice`.
For example:
```
rd.luks.options=timeout=10s,discard,password-echo=no,tries=1
```
###### Timeout
There are two options that affect the timeout for entering the password during boot:
* `rd.luks.options=timeout=mytimeout` specifies the timeout for querying for a password
* `rootflags=x-systemd.device-timeout=mytimeout` specifies how long systemd should wait for the rootfs device to show up before giving up (defaults to 90 seconds)
If you want to disable the timeout altogether, then set both timeouts to zero:
```
rd.luks.options=timeout=0 rootflags=x-systemd.device-timeout=0
```
###### Password echo
When the user is typing the password, *systemd-cryptsetup* by default outputs asterisks (`*`) for each typed character. This is unlike the `encrypt` hook, which does not output anything. To silence the output, set the `password-echo=no` option:
```
rd.luks.options=password-echo=no
```
###### Trusted Platform Module and FIDO2 keys
If a [TPM2](../../en/Trusted_Platform_Module.html "TPM") chip is available in your system, or you use FIDO2-compatible security key, you can use it to automatically unlock your volume instead of using a password or a keyfile.
Set
* for TPM2 chip: `rd.luks.options=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=tpm2-device=auto`
* for FIDO2 key: `rd.luks.options=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX=fido2-device=auto`
in addition to `rd.luks.uuid` or `rd.luks.name`
Alternatively, `/etc/crypttab.initramfs` can be used which avoids the need to specify any kernel options.
```
/etc/crypttab.initramfs
```
```
root UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX none tpm2-device=auto
```
**Note:** Remember to [regenerate the initramfs](../../en/Mkinitcpio.html#Image_creation_and_activation "Regenerate the initramfs") after making any changes to `/etc/crypttab.initramfs`.
Here the encrypted volume is mounted under the name `root` (appearing in `/dev/mapper/root`), mounted via the UUID of the storage device, with no password, and retrieving the key from the TPM2 device.
Note that `none` must be provided in the password field order for the TPM2 device to be used, otherwise the value given will be used as a password or key, and if it does not work it will ask you to type in the passkey during boot without attempting to load the key from the TPM2 device.
If specifying the device via UUID as shown above, ensure it is that of the underlying (encrypted) storage device, not the UUID of the decrypted volume that is specified elsewhere as the root filesystem.
##### rd.luks.data
When using a detached LUKS header, specify the block device with the encrypted data. Must be used together with `rd.luks.options` to specify the header file location.
See [dm-crypt/Specialties#Encrypted system using a detached LUKS header](../../en/Dm-crypt/Specialties.html#Encrypted_system_using_a_detached_LUKS_header "Dm-crypt/Specialties") for details and instructions.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.