Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: [Solved] shutting down with drives mounted (Read 987 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

[Solved] shutting down with drives mounted

I recall with systemd, that rebooting or powering off your machine will safely unmount your drives if you don’t prior to shutting off. Does s6 have this behavior as well?

Re: shutting down with drives mounted

Reply #1
Shutting down does not currently explicitly unmount drives in s6. This is a trivial change to add though. However, is there a benefit to doing this? I do not see why unmounting a drive before the enter system is powered off would be safer. It is not possible for anything to be written to any drive during the shutdown. Every single process is killed before PID 1 is finally brought down.

Re: shutting down with drives mounted

Reply #2
It’s moreso for a safe guard. It’s supposedly not good to for example, unplug your drive from the USB slot before unmounting it. I always thought shutting down without unmounting would have the same effect.

I’ve personally have unplugged drives from the USB slot before unmounting them and they are fine. I do try to unmount my drives before unplugging and shutting off my computer. Reboot or power off.

Re: shutting down with drives mounted

Reply #3
It’s moreso for a safe guard. It’s supposedly not good to for example, unplug your drive from the USB slot before unmounting it.


Right, that's because something could attempt to write to the usb before it's unmounted and thus cause data corruption. That isn't applicable during the shutdown process (nothing can be written during shutdown). Still, it's not like this is a hard change. I would literally just add a down script to mount-filesystems. I'm not sure if this would expose a race condition between lvm/encrypted volumes, but maybe it's worth doing anyway (the umount would just fail but it's not like the system would hang during shutdown).

Re: shutting down with drives mounted

Reply #4
After doing some testing on this, I don't think this is is solvable with the way s6-rc works. There's no good way to guarantee the filesystems aren't busy since any arbitrary number of daemons could be doing a number of different things. The umount will simply fail the vast majority of the time.

Re: shutting down with drives mounted

Reply #5
That isn't good - unmounting also syncs. Check the shutdown scripts for Runit and OpenRC (/etc/init.d/localmount), you will see they unmount all drives before shutting down. A drive might get flagged as not being unmounted correctly, in a worst case it could cause file system corruption. This can sometimes happen (on older hardware) if the shutdown happens too quickly, sending the sync signal to a drive doesn't guarantee it actually syncs to the disc instantly, it might only buffer it internally so you have to sync then sleep for a few seconds before the final umount (which also includes sync in it's execution) and halt. BTRFS will tend to protect against this but nothing's perfect.
Are you sure it doesn't do this somewhere though? Possibly it's compiled in, not in a script. I thought it was one of the fundamental functions of an init system to mount and unmount drives.

Re: shutting down with drives mounted

Reply #6
Looks like s6-linux-init does it. Not really explicitly mentioned, but in the description of s6-svscan it says the stage 3 init umounts. Later, it mentions that s6-linux-init is a implementation of all this stuff for linux.

Edit: Nevermind I found it. Of course it does. Reading documentation is good.

Quote
s6-linux-init-umountall is automatically called at the very end of the shutdown procedure, in "stage 4", i.e. after a SIGKILL has been sent to all the processes on the system, and right before the system reboots (or halts, or is powered off). By that point, there is no possible process that could prevent real file systems from being unmounted.

Source

Re: shutting down with drives mounted

Reply #7
Nice, I’m glad it does this. I didn’t see a message at shutdown about drives being unmounting, so it made me wonder.