One of the ‘perks’ of spinning up a VM from a precompiled Ubuntu image in the catalog is that it may come with a pre-filled root password that needs changing to give us root access from QEMU when the instance is created in a private network without an elastic IP.
My personal approach to google it has derived in putting up a bunch of notes from different solutions and come up with my own way of doing it, so it gets saved here for future reference. Anyway, here we go.
1- Boot the VM into Grub:
When QEMU shows the console waiting for root login, and the root password is unknown, the only path left is to reboot the instance with the Ctrl+Alt+Del equivalent to your hypervisor of choice and then keep pressed the SHIFT
key (if you have two, like me, choose one. I go for the right one since it’s bigger and to not interfere with accessibility shortcuts) for the GRUB boot menu to show without a countdown.
![](https://i0.wp.com/keijo.it/wp-content/uploads/2024/12/image-1.png?resize=656%2C408&ssl=1)
2- DON’T PRESS ENTER! Edit the entry, with ‘e
‘
This is somehow tricky, because many times muscle memory makes me press Enter instinctively, thus booting into multiuser land, and having to redo from scratch. D-oh! So, pressing ‘e
‘ will enable me to edit the boot sequence.
![](https://i0.wp.com/keijo.it/wp-content/uploads/2024/12/image-2.png?resize=663%2C429&ssl=1)
3- Scroll down to the ‘linux
‘ line, make modifications:
From the screen above, Captain Obvious pointed out that linux
isn’t visible, so some scrolling down is needed , and lo and behold, the elusive line shows down there, so let’s get down on it. I need to edit this line a little, get to the ‘ro
‘ (meaning it will mount as read-only), and modify to ‘rw
‘, as well as appending the chain ‘init=/bin/bash
‘.
![](https://i0.wp.com/keijo.it/wp-content/uploads/2024/12/image-3.png?resize=651%2C409&ssl=1)
Caveat: QEMU comes with a US-English keyboard layout predefined in the console, and other hypervisors do the same, so I had to use the “guessed” keys, such as “¿
” for “=
” and “-
” to get “/
” instead. After allat, F10 will go to the boot sequence.
![](https://i0.wp.com/keijo.it/wp-content/uploads/2024/12/image-5.png?resize=635%2C434&ssl=1)
4- Console accessed, let’s get crazy:
At this point, the QEMU console shows a command prompt with the root user, meaning I can go ahead and change any password. Yay.
![](https://i0.wp.com/keijo.it/wp-content/uploads/2024/12/image-6.png?resize=852%2C616&ssl=1)
5- Change the password, get out.
So now, the keyboard layout is loaded with my own settings (as seen in keyboard-configuation-layout-code=latam
from the boot line); that gives me leeway to avoid making typos in the chosen password due to the keys being different to the ones actually being perceived by the operating system.
![](https://i0.wp.com/keijo.it/wp-content/uploads/2024/12/image-7.png?resize=847%2C631&ssl=1)
Here, issuing passwd root
allows me to actually give the root user a new password, and finish business with exec /sbin/init 6
to reboot into the re-passworded system. The end.
Leave a Reply