5

Imagine you accidentally use mount --bind to hide /bin so that umount (and most other binaries) is not visible any more.

How would you get out of this situation?

Is there any way except a hard reboot?

nh2
  • 818
  • 3
  • 11
  • 21
  • There is at least one way out of that as long as you can still compile programs. With /bin/ gone that might be *interesting* but not impossible. – Hennes Aug 24 '13 at 13:51
  • 2
    Hypothetical situation only, right? :) – EEAA Aug 24 '13 at 13:52
  • 1
    Just copy umount from any available server to the root folder and execute /root/umount ... – ALex_hha Aug 24 '13 at 13:58
  • @ALex_hha With the assumption that the `/bin` folders are shadowed (one to be gone is enough since [Arch Linux users only have one](https://www.archlinux.org/news/binaries-move-to-usrbin-requiring-update-intervention/)), things like `cp` and `scp` won't be available. – nh2 Aug 24 '13 at 19:29
  • My guess is that the fastest way would be a perl one-liner. – ott-- Aug 24 '13 at 22:58
  • @ott Do you have an idea what it would look like? And how do you run it? – nh2 Aug 25 '13 at 05:24
  • 1
    I've got it working with this: `perl -e 'require "syscall.ph"; $fil = "/media/sdc2"; syscall(&SYS_umount, $fil);'`. It's not updating /etc/mtab tho. – ott-- Aug 25 '13 at 15:43

4 Answers4

2

Fortunately /bin is actually rather small, it's only very basic utilities and shells. As long as you have a root shell still open, you should be able to use the tools in /usr/bin to download the package that would have had mount in your distribution (eg apt-get install -d mount on Debian), then extract the file from the downloaded package manually (dpkg-deb -x mount.whatever.deb /some/temp/folder) and then use ./umount in that folder.

DerfK
  • 19,493
  • 2
  • 38
  • 54
1

Hah, a reboot may not even work, as that may need tools from /bin too :)

I'm guessing these will not work:

  • scp'ing to the machine (your shell does not exist, login will be denied)
  • dpkg -x / dpkg -i / rpm -i as these are very likely to need things from /bin

I'd simply reboot. There's nothing wrong with that :)

If you don't want to reboot, I would try to scp/wget a copy of /bin/umount from another machine with the same os and run that.

Dennis Kaarsemaker
  • 19,277
  • 2
  • 44
  • 70
  • Dammit I didn't think of the fact that the shell dosn't exist either, so far I thought `scp`ing from outside would work in case you have an ssh server running. – nh2 Aug 24 '13 at 19:31
1

Actually, you could probably go back to those fine backups you are keeping and restoring the appropriate areas you are missing if you do not want to reboot. (personally, I'd reboot to keep things clean).

mdpc
  • 11,856
  • 28
  • 53
  • 67
0

if you root filesystem supports snapshot, you can take a snapshot, and copy the /bin files from the snapshot which should be copied to a partition (forgot you cannot mount it).

otherwise, if you have a spare partition, you can use dd to copy the root partition there and get /bin files back that way. likely with an external usb drive.

last, if you network works, you can just copy the command back from a similar system.

johnshen64
  • 5,865
  • 24
  • 17