2

I used kexec to successfully load my kernel, but it's just printing dmesg lines. How do I get out of this to drop into the initramfs prompt? Ctrl-Alt-F2 just loads a black screen and ctrl-c does nothing.

Here is my kexec commandline:

kexec -l $kernel --initrd=$initrd --command-line="root=UUID=... acpi=off ro text earlyshell debug showerr debuginitrd"

earlyshell should provide me access to a shell, but it doesn't. Without that commandline, I just end up in a scripting loop that I can't break out of even with ctrl-c.

  • think this post might help you askubuntu.com/questions/587934/… as well as reddit thread reddit.com/r/linuxquestions/comments/8w9p11/… TL;TR, live USB stick with luks might help you here. – Bart Jun 30 at 7:47
  • @Bart Unlocking the data with a live cd is easy, but that's not the point here. I'm trying to chainload one kernel to the next so that kernel-1 creates a custom initrd image with the key data and a custom script to unlock kernel-2 – Benjamin Jun 30 at 14:35
  • Please don't add "solved" etc to the title. Marking an answer as accepted (when you can) is enough. – muru Jun 30 at 15:26
  • @muru I cant accept my own answer for 2 full days. – Benjamin Jun 30 at 15:29
  • (when you can...) – muru Jun 30 at 15:36
1

Solved:

The kernel argument:

earlyshell

didn't actually launch a shell??? But running the kernel with the argument:

break=premount

gave me the initramfs shell.

This resource was very helpful: https://wiki.debian.org/InitramfsDebug

0

Did you give the correct --initrd= to kexec?

I just installed and tried kexec. It works if I go

kexec -l /boot/vmlinuz --initrd=/boot/initrd.img --append=root=/dev/sda3 

And then kexec -e. (i have no ecryption...)

I first tried to follow the hint "use /proc/cmdline" but that did not work. To me it looks like you have to give the --initrd= option extra.

You need the "initramfs prompt" to give the password (so you can mount the encrypted device) ?

Normally my /proc/cmdline looks like this

vmlinuz initrd=initrd.cpio.gz root=/dev/sda3

After above kexec (and reboot) /proc/cmdline looks like this

root=/dev/sda3

The name of kernel and initrd are gone! Only the --append part is left. This does not even confuse me too much: just adds a new facette to the question: are kernel image and initrd image kernel options? Are they part of the (kernel) command line ?

I use uefi shell to boot. I know how important this "initrd=" is. With a boot loader (grub) it should work the same. It is just a different way (indirect) to choose a kernel, a initrd (if needed/wanted), a root, a init and all the normal "kernel options"

A standard initrd does this:

  • load modules to access root (my case: sata, ahci for my SIMPLE SSD drive)

  • mount that device (given by root=/dev/xxx)

  • "switch_root" to it (includes running /sbin/init)

In your case you need a password prompt (?), and not a sata-module. But the result is the same: root cannot be mounted.

Find out how your boot loader successfully boots, and then try to imitate that with kexec.


added:

the initrd (names don't matter...) is started by default with the /init script (check out the rdinit= boot option). This is "early userspace", corresponding to earlyshell. It looks like with this initramfs-tool you got enough breakpoints to control /init and the scripts that get called.

Otherwise one could extract that initrd (with gzip and cpio), change /init (or add /init_new and go rdinit=/init_new as boot option), and archive the folders again. This cpio command I had never used before, but it is actually simpler than tar. Just a bit different.

mkinitcpio is a tool for that. It mentions both early userspace and encryption right at the start. It is, I just read, a archlinux thing and also has late and early "hooks". Same function as initramfs-tools, I guess.

  • Okay that's all great, but how do I access the initramfs prompt? – Benjamin Jun 30 at 15:03
  • I added at the end. Putting "exit" in your /init script in the initrd would "drop" you to the early shell / initramfs prompt. – user359065 Jun 30 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.