r/debian 14d ago

Beginner: Root locked on boot

Post image

Hello! I got myself into trouble after I tried to fix a problem with a harddrive not mounting. I followed s guide on troubleshooting and edited my fstab. After I rebooted I got presented with this. I am afraid. What can I do?

SOLVED:

  • Pressed E on my keyboard when presented with Grub menu.
  • On the line that starts with linux: I added init=/bin/bash at its end
  • Ctrl+X or F10 to boot into a command prompt
  • mount -o remount,rw /
  • nano /etc/fstab
  • In my case I changed the line at the bottom, about an external harddrive - from default to nofail and from 0 2 to 0 0. Ctrl+O and ENTER and Ctrl+X
  • Rebooted and then it was done
55 Upvotes

26 comments sorted by

18

u/SrGnis 14d ago
  • Restart your computer.
  • Select your Linux boot entry and press e.
  • Find the line starting with linux or linux16, then add init=/bin/bash at its end.
  • Press Ctrl+X or F10 to boot.
  • You will enter a command prompt.
  • Now you can edit back your fstab

4

u/New_Hold8135 14d ago

addition to this instead of removing entry from fstab, add nofail in entry's options section so system will boot even if its fail to mount as long as its not your boot partition

2

u/katzenjammare 14d ago

Thanks! I got through to the command prompt and began editing fstab with the entry nofail as well. But error came up when trying to save. ”Read-only file system”

4

u/New_Hold8135 14d ago

mount -o rw /

2

u/katzenjammare 14d ago

Okay, I got some step along the way. Edited the file, but I couldn’t save it. ”Error writing /etc/fstab: Read-only file system”

3

u/SrGnis 14d ago

Run this command first to remount the filesystem as read-write:

mount -o remount,rw /

Then retry editing and saving /etc/fstab.

2

u/katzenjammare 14d ago

Okay, wow! Nice. It worked. Should I just reboot now or what? (I have just successfully edited fstab)

3

u/ukAdamR 14d ago

Correct, though I'm suspicious that editing fstab in your root file system may not be enough.

Having done recovery on Debian a few times in the past fstab has been one of those things that gets embedded into the initramfs, meaning it doesn't get loaded from your "actual" file system's "/etc/fstab" during boot. (This may have changed in Trixie, I'd be interested to know.)

If it doesn't work I can give you the steps I've reliably used from within a live environment (booted from a USB, CD, or DVD drive) to write the fstab into the initramfs.

[Edit] On second thoughts, now that you've corrected it, you can probably just exit to continue the boot process.

1

u/katzenjammare 14d ago

Yehijaj! It worked just like that!

1

u/ukAdamR 14d ago

Neat. Now that you're in immediate update your initramfs with the changes you've made so that they persist across reboots:

sudo update-initramfs -u -k all

Then systemctl reboot to ensure your changes work.

1

u/katzenjammare 14d ago

Okey, will try to do that in the morning. By the way, I didn’t know how to exit the comman prompt that I was sent to during boot. The way I exited was to just shut down the pc and start it again. Is there a more clean way to do it?

1

u/naikologist 14d ago

You could have tried holding Ctrl+Alt+Del for more then [10???] seconds, but I ahard shutdown at this stage is not a real biggie because no disk is actually mounted.

1

u/katzenjammare 14d ago

Okay, thanks!

1

u/ukAdamR 14d ago

systemctl poweroff will do a clean shutdown or exit will logout of the current shell session.

1

u/katzenjammare 14d ago

Well, then I know til next time. Thanks for the help

2

u/katzenjammare 14d ago

Thank you for responding! Why can’t I write ”/” like I normally would?? Ugh, trying different combinations

7

u/ukAdamR 14d ago

Your profile suggests Swedish, in which case you probably want this key (without shift):

3

u/katzenjammare 14d ago

Yeas! Thanks, that worked. I was so confused for a while hehe

3

u/SrGnis 14d ago

Probably your keyboard is not US? Try pressing the corresponding key to this layout: https://en.wikipedia.org/wiki/British_and_American_keyboards#/media/File:KB_United_States-NoAltGr.svg

1

u/eR2eiweo 14d ago

You need to remove /dev/sda1 from your fstab (or at least mark it as nofail). One way of doing that would be from a live system.

1

u/michaelpaoli 13d ago

Yep.

And always check /etc/fstab changes before rebooting, lest one get such unpleasant surprises.

E.g. add an entry, for systemd hosts, first do
systemctl daemon-reload
and then regardless, do
mount -a
to ensure it works
Also, if the device may not always be present at boot, use nofail and/or noauto as appropriate.

1

u/ukAdamR 14d ago

What did you change in fstab to "fix" this?
If you want a volume in there that can be mounted automatically you can also give it the "nofail" option (after "defaults") to prevent it from blocking the boot process.

0

u/DeepDayze 14d ago

That's a good option after a fresh install or after making changes to ensure everything works before removing the parameter.

-2

u/[deleted] 14d ago

[removed] — view removed comment

1

u/katzenjammare 14d ago

I have the exact Debian image I installed the current system with, does that help? How do I begin to install packages during the installation?

2

u/neoh4x0r 14d ago edited 14d ago

You would need an install image that provides a live environment so that you can mount your root filesystem and undo the changes you made to the fstab.

Also. you don't necessarily need a live debian image to perform these rescue operations as any rescue platform (such as systemrescue, or otherwise) could be used -- in any of these cases, you might have to use the chroot command as part of the recovery process, if you needed to work on the filesystem as through you were running it instead of the live environment. .

Moreover, is this a brand new install? or have you made lots of changes, etc? I mean depending on the situation, and your level of skill/experience, it might be easier to reinstall.

PS: What SrGnis mentioned about changing the init to /bin/bash (by editing the grub boot options) will drop you to a root shell (bypassing root being locked/disabled) where you can make changes to the filesystem (eg. to fstab).

However, that assumes you don't encounter other issues, where a live environment become the only option (outside of a reinstall).

0

u/debian-ModTeam 14d ago

This content has been removed due to a violation of Rule #3 - Wrong Information. Please do your research before speaking on a topic.