3

If the root filesystem is unmounted, then how can init be accessed to run the last few steps that occur afterwards?

2 Answers 2

2

PID 1 can be run from a RAM-based filesystem. For example systemd + dracut can pivot_root into a tmpfs during shutdown. dracut-shutdown.service(8) has some more information about this.

Otherwise, you remount the remaining filesystems as read-only. After remounting read-only, the filesystem is clean. It is consistent on-disk; requires no repair operations; has no remaining writes cached or queued up in RAM.

umount / is even interpreted the same as mount / -o remount,ro. Although that does not happen on other unix-likes; it is a Linux-specific quirk :-).

1

init is the first process to be executed after the kernel was loaded and the last to "shut down the lights" - figuratively spoken.
The kernel does not need / to be mounted to run init, as it can be run completely from memory.
"Live" distributions are running almost completely from memory and there are even some, whose cd/dvd/usbstick/floppy you can even remove from the pc after the system was loaded into memory.

Now to the question in the title of your question: yes, it is unmounted on most distributions - other remount / read-only.

More information can be found in /etc/inittab (if the system is running with sysvinit) of your system and for example on http://wiki.linuxquestions.org/wiki/Run_Levels

On systemd you can view which objects are evaluated with systemctl list-dependencies --after systemd-halt.service.

6
  • And distribtions take care that none of the tasks they want to do after unmounting / require filesystem access. Jul 25, 2016 at 19:21
  • RedHat 6, for example, remounts / readonly (/etc/rc.d/rc0.d/S01halt). Jul 25, 2016 at 19:27
  • what I was trying to figure out right now: how can one tell what happens with systemd? at least on my ubuntu there is no /etc/inittab Jul 25, 2016 at 19:30
  • The systemd-shutdown manpage may provide guidance. In particular it mentions: It is necessary to have this code in a separate binary because otherwise rebooting after an upgrade might be broken -- the running PID 1 could still depend on libraries which are not available any more, thus keeping the file system busy, which then cannot be re-mounted read-only. Jul 25, 2016 at 19:41
  • 1
    The kernel does need / to be mounted to run init, of course. It can be run from memory, if / is in memory. And while init is running, the filesystem it was loaded from cannot be unmounted. Jul 25, 2016 at 21:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .