Question I broke Ubuntu 24.04 boot with bad startup script ?

anvoice

Honorable
Jan 12, 2018
147
11
10,615
I placed a startup script into /bin/scriptname on ubuntu 24.04 server in order to unlock my LUKS encrypted OS drive using a usb key. Unfortunately I made a typo in the script, and the unlock fails. The messages of the failed unlock are interleaved with messages about the syntax error in the script and continue indefinitely, not allowing me to type the unlock passphrase with an attached keyboard. Also, I cannot ssh into the machine with dropbear while this is all going on so that option to unlock is also out.

I tried getting into single-user mode by pressing escape rapidly (also tried holding the shift key) to no avail, and I booted from a ubuntu 24.04 usb to try to mount the OS drive and examine it for the startup script. I can't find it on the unencrypted partitions of the drive, and the larger partition is encrypted and will not mount. Any ideas where I might find this script to edit it, or another way to salvage the system?
 

anvoice

Honorable
Jan 12, 2018
147
11
10,615
Is this a computer you have local access to and able to boot via usb stick ?
Indeed. I managed to boot from a ubuntu live usb. From there, I could not locate the script I made to edit it. However, I did manage to unpack, edit, and repack the initrd.img file. Unfortunately I believe it's now malformed as it only allowed me to boot into busybox (initramfs), but at least it's a start. I used the unmkinitramfs command to unpack and the mkinitramfs command to pack the image.

The way I see it I have either the option of creating a proper initrd.img file or finding the script I created from the busybox prompt, which I was not able to do so far.

Edit: tried to pack the initrd.img file unedited with mkinitramfs, still not bootable. Thus I am certain I am packing it wrong, just not sure how.
 
Last edited: