Resetting root password in Ubuntu 22.04 from those pesky openstack images

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.

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.

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‘.

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.

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.

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.

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.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.