36

Now I can't remount anything and get access back. How can I fix it?

sudo returns

sudo: effective uid is not 0, is /usr/bin/sudo on a filesystem with the 'nosuid' option set or an NFS filesystem without root privileges?

mount returns

mount: failed to read mtab: No such file or directory

If I try to open anything new I get the message

Failed to execute child 
Failed to open PTY: No such file or directory 
guntbert
  • 12,914
  • 37
  • 45
  • 86
Randy Ssusage
  • 377
  • 1
  • 3
  • 5
  • The downside of the fall of /etc/mtab is /dev got unmounted. – Joshua Jun 22 '20 at 16:50
  • 1
    You're lucky. I once did `rm -rf *` in the `/` directory when I thought I was in a subdirectory. – O. Jones Jun 24 '20 at 19:46
  • No worries (in this case). The most important lesson: be very careful of what you do as the root user (i.e. when using `sudo`). As @O.Jones mentioned, there are worse things you could have done than this. – jrw32982 Jun 25 '20 at 22:36
  • How could you do that? On my newer system it outputted "/dev: target is busy." - same for many others inc. "/run" and the system is usable. – Alex Martian Feb 08 '23 at 08:22

3 Answers3

93

Just reboot the machine. It is just temporarily and the permanent configuration in /etc/fstab is restored upon reboot.

S.S. Anne
  • 103
  • 4
Fernando Mengel
  • 831
  • 5
  • 3
25

Whenever you are on a situation like this on Linux, if you want to do a safe reboot, there is the "Magic SysRq key" + REISUB:

https://en.wikipedia.org/wiki/Magic_SysRq_key

You need to press: Alt + SysRq and while keeping that pressed type:

  • r: The kernel takes raw control of the keyboard (from X or Wayland)
  • e: Terminate all running programs
  • i: Kill all programs left (except init)
  • s: Sync (flush data to disk)
  • u: unmount (remounts all filesystems readonly)
  • b: reboot

Keep a few seconds between each typed letter for each of the tasks to complete.

This is a clean way of directly telling the linux kernel to restart.

Since you had unmounted all the file systems, the sync and unmount do not make much sense to me, however it is easier to remember the whole sequence than to apply only the parts you need.

zeehio
  • 379
  • 3
  • 8
  • 1
    REISUB is easier to remember as BUSIER backwards. – cjm Jun 24 '20 at 05:02
  • 15
    Reboot Even If System's Utterly Broken – Nmath Jun 24 '20 at 06:13
  • 2
    @cjm I think the difficulty with getting it right has little to do with remembering the “REISUB” part, but the alt+SysRq one (or, what key SysRq even is, because it's by no means labelled on all keyboards). – leftaroundabout Jun 24 '20 at 08:31
  • In Spanish keyboards SysRq is labelled as PetSis (Petición Sistema). It's a rather unknown key to most users, so it may be difficult to find in some keyboards. – zeehio Jun 24 '20 at 12:50
  • 1
    How would you do it remotely over SSH? – Canadian Luke Jun 25 '20 at 03:07
  • `S` is renundant because `U` also does that (of course, you should still wait until the message "Emergency remount complete"). I also don't think `I` is necessary (the programs will get killed when the computer reboots anyway). – the default. Jun 25 '20 at 03:41
  • @CanadianLuke I'm not OP, but, as far as I remember, you can echo/cat the commands into `/proc/sysrq-trigger` (as root) – the default. Jun 25 '20 at 03:48
  • 1
    @CanadianLuke Is it even possible to be still connected to the machine if you do what OP has done remotely? – gerrit Jun 25 '20 at 06:43
  • @gerrit I was able to do it on another Linux machine over SSH.... Just saying... :P – Canadian Luke Jun 25 '20 at 16:26
-2

To avoid rebooting, I believe running sudo mount -a should fix it, as it will then run the mounts specified in /etc/fstab

Heigre
  • 21
  • 2
  • 2
    As per the question, `sudo` produces `sudo: effective uid is not 0, is /usr/bin/sudo on a filesystem with the 'nosuid' option set or an NFS filesystem without root privileges?` error. – Kulfy Jul 21 '20 at 15:27