Skip to content

Commit

Permalink
feat: enable decryption and mounting of luks volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
brdanin committed Feb 1, 2024
1 parent c049f36 commit a28de76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion builder/image.d/make_repart_partition
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ elif [ "$cryptsetup" = 1 ]; then
EOF_GENERATOR
chmod +x "$target/etc/systemd/system-generators/repart-$repart"
else
dev_path="/dev/disk/by-partuuid/$repart_uuid"

cat > "$target/etc/repart.d/1.$repart.conf" <<-EOF
[Partition]
UUID=$repart_uuid
Expand All @@ -240,13 +242,29 @@ else
Encrypt=$tpm2
EOF

dev_path="/dev/disk/by-partuuid/$repart_uuid"
if [[ "$tpm2" = "tpm2" ]]; then
cat > "$target/etc/crypttab" <<-EOF
luks-$repart_uuid $dev_path
EOF

dev_path="/dev/mapper/luks-$repart_uuid"
systemd_cryptsetup_dependency="systemd-cryptsetup@luks\x2d$(systemd-escape "${repart_uuid#/}").service"
fi

systemd_dev_dependency="blockdev-settle@$(systemd-escape "${dev_path#/}").service"
mkdir -p "$target/etc/systemd/system/"
cat > "$target/etc/systemd/system/$sysroot_mount_unit" <<-EOF
[Unit]
Before=initrd-root-fs.target
After=systemd-repart.service
EOF

if [[ "$tpm2" = "tpm2" ]]; then
echo "After=$systemd_cryptsetup_dependency" >> "$target/etc/systemd/system/$sysroot_mount_unit"
echo "Requires=$systemd_cryptsetup_dependency" >> "$target/etc/systemd/system/$sysroot_mount_unit"
fi

cat >> "$target/etc/systemd/system/$sysroot_mount_unit" <<-EOF
After=$systemd_dev_dependency
Requires=$systemd_dev_dependency
[Mount]
Expand Down
2 changes: 1 addition & 1 deletion builder/image.d/makesecureboot
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ chroot "$rootfs" env dracut \
--no-hostonly \
--force \
--kver "$kernel_version" \
--modules "bash dash systemd systemd-initrd systemd-veritysetup systemd-repart kernel-modules kernel-modules-extra terminfo udev-rules dracut-systemd base fs-lib shutdown $tpm2" \
--modules "bash dash systemd systemd-initrd systemd-veritysetup systemd-repart kernel-modules kernel-modules-extra terminfo udev-rules dracut-systemd base fs-lib shutdown crypt $tpm2" \
--install "/etc/veritytab cryptsetup head mkfs.ext4 systemd-escape lsblk" \
--include "$dracut_include" "/" \
--reproducible \
Expand Down

0 comments on commit a28de76

Please sign in to comment.