How can a computer shut down if a mount/service etc. cannot be unmounted?

0

Sometimes a hard reboot is required when a computer gets itself into a bad state, in any operating system. In linux say, if a drive cannot be unmounted, even by force, how does a shutdown command manage to do it? What has shutdown got access to for force unmounting etc. that is not accessible from the terminal?

J Collins

Posted 2017-11-30T17:34:08.683

Reputation: 412

What OS are we talking about? What will happen automatically depends on the OS. What requires a user to intervene will depend on the OS. – Ramhound – 2017-11-30T17:46:34.920

At the moment, Linux, but I am interested in both answers. The problem is I don't know how an OS can forcefully exit a process in, as the first answer, a 'too bad' case, to shut down, yet no user requested kill can kill it. It happens in windows and linux both that a file handle might lock things, and the only solution is a restart. – J Collins – 2017-11-30T17:48:09.130

In most cases commands only attempt to do something, after that period of time, specific or unknown behavior can happen. – Ramhound – 2017-11-30T17:49:36.913

keep in mind, a "mount point" is a memory structure within the kernel memory structure that is overseen by kernel and userspace software. regardless of what the rest of the software thinks about it, the kernel can always destroy that memory structure. it just won;t under most circumstances to protect the integrity of the filesystem from bad events caused by bad software or bad users. Its not like a process exists beyond the point where the kernel wants it to exist. its all just state management. – Frank Thomas – 2017-11-30T18:06:00.853

Answers

2

Shutdown will cause the system to try to gracefully close all the applications or services that are loaded. Applications will get notified that this is happening and given a short grace period to "make good their escape".

The next part of the shutdown process will trigger the operating system to tell the filesystem drivers to flush their stored data to the storage device. This should cause the filesystem driver to sanitize the filesystem prior to shutdown.

It will also then tell the drive that the filesystem is on to flush whatever hardware caches they have to disk.

If, after all that, there is still data locking the disk then it is tough luck as the system will simply shut down. If an application has refused to save its data or release it correctly then it is simply lost.

Mokubai

Posted 2017-11-30T17:34:08.683

Reputation: 64 434

So the question is in the final 'too bad' scenario, is it possible to do that on a process by process, service by service etc. case? – J Collins – 2017-11-30T17:44:10.860

Well you can manually go through every process in the list and ask them to terminate, but it wont help for a process that crashed or was badly written and left an orphan lock on something. In which case chances are letting everything tidy up properly and reboot is probably the best thing you can do. – Mokubai – 2017-11-30T17:47:17.633

@JCollins - Forcefully ending a process does clean up handles to files that might have opened up. So it depends on the processs. – Ramhound – 2017-11-30T17:48:43.437

IIRC all processes get killed after init exits. However, it is entirely possible for files to remain locked due to strange circumstances and/or kernel bugs. – Daniel B – 2017-11-30T17:49:25.990

Ignoring kernel bugs, I have seen cases where for instance smb processes did not end well and init (or systemd in my CentOS) became the process owner shown in pstree. When all variants of kill fail, what options are left before a reboot, noting that it is impossible to kill the parent process. – J Collins – 2017-12-12T17:31:04.243