Support QRP CoA Everywhere

Saturday 9 October 2021

Panic.... "Cannot open access to console, the root account is locked."

Last weekend I built myself a nice Pi 4 system for the shack. Everything worked perfectly, but today as I rebooted the Pi would simply not boot up. Usually I run almost all my Pis in a headless configuration but as this is the desktop for the operating position I had monitors connected.
 Eek, there is was, there it was, The Pi would get stuck at boot with the following error message

"Cannot open access to console, the root account is locked."
The error message while not too descriptive, it asked me use sulogin and run journalctl -xb however there was no shell to run or list anything.

I thought oh no there goes the system will have to rebuild it. However, I thought I would investigate some more.

After some google work, I found the following workaround that worked for me. Note for those that try to do this themselves: You will need access to a display,keyboard and a laptop/desktop to do the following steps

Retrive your SD card from the Pi and using a adapter mount the card to your PC,Mac or Linux. I use a rocketek that takes either normal or small SD cards .You should be able to see the /boot partition of your SD card.
Locate the file fstab in the rootfs partition and edit out the usb drive I added in last time and left in place! You might need to sudo to root to write this file or the next one see later if that is the case....
Or find the bootfs and look for the cmdline.txt file and add the following at the end of the line init=/bin/sh Note: Do not create a new line, just add the above to end of the current line. This will make the system give you a prompt so you might be able to figure out what the problem is. A bit like one of the earlier linux installs.
Load the SD card back into the pi and boot up.
if you did the cmdline.txt change you should now get the a root shell prompt and I expect you will know how to fix it from there. You could undo the changes to /etc/fstab or whatever else that  might have caused an issue.
I found I could not make and save the changes to the files as the system will complain the SD card is read only file system. If you get that move to the next sections.

A raspberry pi SD card will has two main partitions, since we cannot read the partition table directly you must manually locate the device for your root and boot partitions. You can do this by going to the /dev directory and you should see something similar to mmcblk0p1 & mmcblk0p2. You could use ls -l to check.

Mine is:

brw-rw----  1 root disk    179,   0 Oct  8 18:28 mmcblk0

brw-rw----  1 root disk    179,   1 Oct  8 18:28 mmcblk0p1

brw-rw----  1 root disk    179,   2 Oct  8 18:28 mmcblk0p2

The second device mmcblk0p2 will be your root partition. You need to remount this with read write permissions

mount -o remount,rw /dev/mmcblk0p2 /
Once this is remounted, go ahead and edit your /etc/fstab and save it.

The offending line in mine was:

#/dev/sda1 /disk1 auto defaults 1 1

Before you exit, make sure you revert the change to the cmdline.txt in the /boot partition. You may need to mount that in read write mode as you did above for the /root partition before you can change it.

mount -o remount,rw /dev/mmcblk0p1 /boot

Alternatively you can revert back the change to cmdline.txt on your laptop as I did using the USB adapter.

If everything goes well, you should be able to boot back your Pi in a normal way.

Panic over

No comments: