Sample Header Ad - 728x90

How to chainload another kernel with kexec inside a LUKS2 + LVM2 partition?

0 votes
1 answer
702 views
I have a Debian 11 installation with the following partition layout: | path | format | mount point | |------|--------|-------------| | /dev/nvme0n1p7 | ext4 (no encryption) | /boot (Debian 11) | | /dev/nvme0n1p8 | dm-crypt LUKS2 | LVM2 (named vg_main) | | /dev/mapper/vg_main-lv_swap | swap | - | | /dev/mapper/vg_main-lv_debian | ext4 | / (Debian 11) | | /dev/mapper/vg_main-lv_ubuntu | ext4 | / (Ubuntu 22.04) | The /boot for Ubuntu, lives inside its root file system (/dev/mapper/vg_main-lv_ubuntu). I'd like to kexec the Ubuntu kernel after booting the Debian kernel that lives in the unencrypted /boot partition that unlocks the LUKS2 partition. I'd like to use the [systemd kexec strategy described here](https://wiki.archlinux.org/title/kexec#Separate_/boot_partition) . Is there a way to pass any specific kernel parameter to Debian 11 (that I will do in a specially created GRUB2 entry for this) to tell systemd to simple kexec the Ubuntu 22.04 kernel? ----- **Solution:** Worked as per [@telcoM](https://unix.stackexchange.com/posts/704847#704888) suggestion, with just few adjustments: /etc/systemd/system/ubuntu-kexec.target
[Unit]
Description=Ubuntu kexec target
Requires=sysinit.target ubuntu-kexec.service
After=sysinit.target ubuntu-kexec.service
AllowIsolate=yes
/etc/systemd/system/ubuntu-kexec.service
[Unit]
Description=Ubuntu kexec service
DefaultDependencies=no
Requires=sysinit.target
After=sysinit.target
Before=shutdown.target umount.target final.target

[Service]
Type=oneshot
ExecStart=/usr/bin/mount -o defaults,ro /dev/mapper/vg_main-lv_ubuntu /mnt
ExecStart=/usr/sbin/kexec -l /mnt/boot/vmlinuz --initrd=/mnt/boot/initrd.img --command-line="root=/dev/mapper/vg_main-lv_ubuntu resume=UUID=[MY-UUID-HERE] ro quiet splash"
ExecStart=/usr/bin/systemctl kexec

[Install]
WantedBy=ubuntu-kexec.target
Asked by Eduardo (103 rep)
Jun 3, 2022, 08:57 AM
Last activity: Oct 22, 2022, 06:26 AM