-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
decrypt-root: add service to decrypt the ROOT partition
- Loading branch information
Simon Campion
committed
Mar 24, 2024
1 parent
8d5495e
commit b9f3b12
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
# Check if there is a partition labeled ROOT and, if so, determine its UUID. | ||
match=$(lsblk -o UUID,PARTLABEL | grep -w ROOT) | ||
if [[ $? -ne 0 ]]; then | ||
exit 0 | ||
fi | ||
uuid="${match%% *}" | ||
|
||
# Check if the partition labeled ROOT is a LUKS device. | ||
IFS= read -r -n "4" header < /dev/disk/by-uuid/$uuid | ||
if [[ "$header" != "LUKS" ]]; then | ||
exit 0 | ||
fi | ||
|
||
# Generate a systemd-cryptsetup unit to decrypt the root partition. | ||
# We call the LUKS device `rootencrypted`, no matter what it was called in the Ignition configuration. | ||
echo "rootencrypted UUID=$uuid none luks" > /tmp/crypttab | ||
SYSTEMD_CRYPTTAB=/tmp/crypttab /usr/lib/systemd/system-generators/systemd-cryptsetup-generator /etc/systemd/system/ | ||
|
||
# Start the generated systemd service to decrypt the root partition. | ||
systemctl start systemd-cryptsetup@rootencrypted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[Unit] | ||
Description=Generate and execute a systemd-cryptsetup service to decrypt the ROOT partition | ||
|
||
DefaultDependencies=no | ||
# If systemd-networkd.service is used in the initramfs, then we should run after it, since the ROOT partition | ||
# might use network-bound encryption. | ||
After=systemd-networkd.service dev-disk-by\x2dpartlabel-ROOT.device | ||
Wants=dev-disk-by\x2dpartlabel-ROOT.device | ||
Before=dracut-initqueue.service | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/sbin/decrypt-root | ||
|
||
[Install] | ||
WantedBy=ignition-subsequent.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
install() { | ||
inst_script "$moddir/decrypt-root" \ | ||
"/usr/sbin/decrypt-root" | ||
|
||
inst_simple "$moddir/decrypt-root.service" \ | ||
"$systemdsystemunitdir/decrypt-root.service" | ||
|
||
systemctl --root "$initdir" enable decrypt-root.service | ||
} |