You are not logged in.

#1 2010-03-10 11:37:52

chakra-user
Member
Registered: 2010-03-07
Posts: 74

Why is root remounted on shutdown/reboot?

Hi,
         I am running chakra arch updated. Whenever I shutdown or reboot my system, the last line before switching the PC off is "Remounting root as read-only". Why? When the system is anyways not going to be used now, what the point in remounting the partition. that too in the end? Please enlighten.

Offline

#2 2010-03-10 11:58:07

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: Why is root remounted on shutdown/reboot?

"Remounting" is the only way to change a filesystem from read-write to read-only mode. This ensures that the filesystem is in a consistent state when the hd is powered off.

If you look at the end of /etc/rc.shutdown you'll see that the root filesystem still needs to be mounted and readable to do the actual reboot or poweroff after the root filesystem has been put in a safe state (to execute, and thus read /sbin/poweroff or /sbin/reboot).

BTW, the last line printed is actually "REBOOTING" or "POWER OFF"...

Last edited by hbekel (2010-03-10 12:00:25)

Offline

#3 2010-03-10 13:58:12

chakra-user
Member
Registered: 2010-03-07
Posts: 74

Re: Why is root remounted on shutdown/reboot?

I have never seen that in other OS. Ofcourse my last OS Kubuntu showed a nice "Kubuntu" GUI screen with reverse progress bar when shutting down so..but I am sure even they won't be doing that. I mean abt ur point
hbekel: ""Remounting" is the only way to change a filesystem from read-write to read-only mode."

Why do u want to change it to read-only mode in the first place, u have the shutdown/reboot prog in memory and the last command might possibly be to invoke some CPU instruction to soft restart/shutdown it. where is the need to run programs? /sbin/reboot and /sbin/poweroff is the command I ran when in KDE why are they needed now in the end? to do what? weren't they the ones who started it all(i.e shutdown/reboot).

Sorry if I sound naive, but this is something new I am seeing in many yrs of linux use and I faintly remember same question asked many years ago when some other OS was doing it and they had(I think) changed their code or as it was leading to superblock and modified in future errors....

Last edited by chakra-user (2010-03-10 13:59:50)

Offline

#4 2010-03-10 14:25:25

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: Why is root remounted on shutdown/reboot?

Just read /etc/rc.shutdown and the relevant manual pages (halt(8), shutdown(8)). Especially note the -f option to the halt commands. This should clear your confusion about the purpose of the reboot/poweroff commands, their relation to shutdown(8) and the difference between invoking them manually or them being used at the last stage of the shutdown procedure.

Note that rc.shutdown is a bash script. It explicitly calls /sbin/poweroff or /sbin/reboot (or kexec). There's no "programs in memory" at that point, neither is there any way to "invoke cpu instructions" from the shell other than executing a program which in turn does so.

Every Linux distro I've seen does it this way. And you certainly won't want your system to power off while your root fs is still mounted read-write.

Last edited by hbekel (2010-03-10 14:30:31)

Offline

#5 2010-03-10 15:43:17

chakra-user
Member
Registered: 2010-03-07
Posts: 74

Re: Why is root remounted on shutdown/reboot?

When u unmount the root FS the first time, the current script i.e /etc/rc.shutdown also gets closed as it is also under / so how is then that the rest of the instructions on remounting ro work? That small gap when all partitions are unmounted, where does mount command run from?

Doesn't the kernel close all file and process handles when partitions are unmounted? If it works inspite of unmount then,  my contention is why the need to remount in that case /sbin/reboot-shutdown must also come just the way magically mount to load / ro came.
Are you saying that becoz rc.shutdown is not a prog but a script and thus inherently dependent on external progs to do stuff, if we don't remount ro then
After complete unmount, the script cannot call reboot or shutdown as it cannot find /sbin now.(Contradicts how mount is still executable currently but not reboot or shutdown).

Offline

#6 2010-03-10 19:34:49

Misfit138
Misfit Emeritus
From: USA
Registered: 2006-11-27
Posts: 4,189

Re: Why is root remounted on shutdown/reboot?

chakra-user wrote:

When u unmount the root FS the first time, the current script i.e /etc/rc.shutdown also gets closed as it is also under / so how is then that the rest of the instructions on remounting ro work? That small gap when all partitions are unmounted, where does mount command run from?

You don't need to write to a filesystem to execute any code. Think; How else would a livecd work? Remember, the kernel and many interprocess communications can fit nicely in RAM.

Offline

#7 2010-03-10 21:02:36

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: Why is root remounted on shutdown/reboot?

Note that it is not 'physically' umounted and then remounted - the process goes something like this:

mount -o ro,remount /

This ensures that _all_ pending write-buffers are flushed to disk and leaves the filesystem in an ordered and safe state.

[edit]
And btw - every other linux/unix I have ever seen does this - though for many of them you will never see it ...
Think:

mount -o ro,remount / >/dev/null 2>/dev/null

Last edited by perbh (2010-03-10 21:04:06)

Offline

#8 2010-03-11 00:24:45

chakra-user
Member
Registered: 2010-03-07
Posts: 74

Re: Why is root remounted on shutdown/reboot?

hmmm so u r saying that mount -o ro,remount / quickly unmounts/mounts ro(actually flushing takes place plus some flag is now set in internal datastructures to prevent any writes) and then the next command shutdown/reboot is executed. Since none of the file handles are closed in this virtual umount/mount, all things work as if nothing happened and system happily goes in for a reboot/halt.

Last edited by chakra-user (2010-03-11 00:25:52)

Offline

#9 2010-03-11 01:41:12

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: Why is root remounted on shutdown/reboot?

*lol* Something like that ...

Offline

Board footer

Powered by FluxBB