Linux shutdown/reboot process
Hi List I have a query about the linux shutdown or reboot process. Please can you let me know if the below sequence is correct: When reboot command is given on the shell: 1. all user-space process is frozen (by sending some signal ?? ) 2. all file-systems are remounted as read-only - (sysrq handler does this ?? ) 3. all drivers, whose shutdown handlers have been defined, are called in the reverse order in which these drivers were initialized. I am not sure what happens after this. TIA. -- Thanks & Regards ~/asd
Hi.... :) On Mon, May 14, 2012 at 6:31 PM, Asutosh Das <das.asutosh@gmail.com> wrote:
Hi List I have a query about the linux shutdown or reboot process.
I am not so keen about this issue. Actually, the whole sequence is combination of user space and kernel space.
Please can you let me know if the below sequence is correct:
When reboot command is given on the shell:
1. all user-space process is frozen (by sending some signal ?? )
I think it is done by simply sending kill -TERM to all processes, then followed by kill -KILL in case some of them are stubborn to die :)
2. all file-systems are remounted as read-only - (sysrq handler does this ?? )
IMHO it is done this way: mount -o remount, ro
3. all drivers, whose shutdown handlers have been defined, are called in the reverse order in which these drivers were initialized.
I am not sure, perhaps you mean it is part of unloading those drivers?
I am not sure what happens after this.
what I am quite sure, in the end it tries to shutdown the machine via ACPI commands (or APM?). And before that, it tries to park the hard disk head, again using some sort of ioctls I guess. Sorry if it doesn't help much... -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
Hi, On Mon, May 14, 2012 at 9:15 PM, Mulyadi Santosa <mulyadi.santosa@gmail.com> wrote:
Hi.... :)
On Mon, May 14, 2012 at 6:31 PM, Asutosh Das <das.asutosh@gmail.com> wrote:
Hi List I have a query about the linux shutdown or reboot process.
maybe have a look at $ls /etc/rc0.d/S* regards.
Hi Thanks for your replies. It was helpful. I would appreciate if you can please point me to the source code where the shutdown process begins. TIA On 14 May 2012 22:43, Prashant Shah <pshah.mumbai@gmail.com> wrote:
Hi,
On Mon, May 14, 2012 at 9:15 PM, Mulyadi Santosa <mulyadi.santosa@gmail.com> wrote:
Hi.... :)
On Mon, May 14, 2012 at 6:31 PM, Asutosh Das <das.asutosh@gmail.com> wrote:
Hi List I have a query about the linux shutdown or reboot process.
maybe have a look at
$ls /etc/rc0.d/S*
regards.
-- Thanks & Regards ~/asd # (91) 8297 00 1980
i think your question is distro-specific, or at least it differs between sysvinit and systemd - which is the two main technique of starting up. For Fedora Core 17 beta (my system), it is running systemd: http://lwn.net/Articles/458789/ and here it shows all the good points about systemd: http://0pointer.de/blog/projects/why.html (noting the shutdown features if u are focusing on the shutdown part). more info: https://fedoraproject.org/wiki/Systemd [PDF] Beyond Init: systemd - LinuxKongress 2010 www.linux-kongress.org/2010/slides/systemd-poettering.pdf But as mentioned in document above, /dev/initctl is still supported, which is the traditional means of shutting down. In Ubuntu (which uses sysvinit, and shutting down is via /dev/initctl), u can get the source code for poweroff via: "apt-get source upstart" and then start navigating through the source code. Within util/shutdown.c you can see following: * struct request: * * This is the structure passed across /dev/initctl. **/ struct request { int magic; int cmd; int runlevel; int sleeptime; char data[368]; }; /** * sysvinit_shutdown: * * Attempt to shutdown a running sysvinit /sbin/init using its /dev/initctl * socket. **/ static void sysvinit_shutdown (void) { struct sigaction act; struct request request; int fd; /* Fill in the magic values */ memset (&request, 0, sizeof (request)); request.magic = 0x03091969; request.sleeptime = 5; request.cmd = 1; /* Select a runlevel based on the event name */ There goes all the magic....or some part of it.... On Mon, May 14, 2012 at 7:31 PM, Asutosh Das <das.asutosh@gmail.com> wrote:
Hi List I have a query about the linux shutdown or reboot process.
Please can you let me know if the below sequence is correct:
When reboot command is given on the shell:
1. all user-space process is frozen (by sending some signal ?? ) 2. all file-systems are remounted as read-only - (sysrq handler does this ?? ) 3. all drivers, whose shutdown handlers have been defined, are called in the reverse order in which these drivers were initialized.
I am not sure what happens after this.
TIA.
-- Thanks & Regards ~/asd
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Regards, Peter Teoh
At the kernel, the file involved are kernel/sys.c (just a few functions): /** * kernel_halt - halt the system * * Shutdown everything and perform a clean system halt. */ void kernel_halt(void) { kernel_shutdown_prepare(SYSTEM_HALT); syscore_shutdown(); printk(KERN_EMERG "System halted.\n"); kmsg_dump(KMSG_DUMP_HALT); machine_halt(); } EXPORT_SYMBOL_GPL(kernel_halt); /** * kernel_power_off - power_off the system * * Shutdown everything and perform a clean system power_off. */ void kernel_power_off(void) { kernel_shutdown_prepare(SYSTEM_POWER_OFF); if (pm_power_off_prepare) pm_power_off_prepare(); disable_nonboot_cpus(); syscore_shutdown(); printk(KERN_EMERG "Power down.\n"); kmsg_dump(KMSG_DUMP_POWEROFF); machine_power_off(); } EXPORT_SYMBOL_GPL(kernel_power_off); since it is exported, the symbol can be called from many different places in the kernel, and thus many different ways of shutting down or hibernation are possible. On Tue, May 15, 2012 at 1:09 PM, Peter Teoh <htmldeveloper@gmail.com> wrote:
i think your question is distro-specific, or at least it differs between sysvinit and systemd - which is the two main technique of starting up.
For Fedora Core 17 beta (my system), it is running systemd:
http://lwn.net/Articles/458789/
and here it shows all the good points about systemd:
http://0pointer.de/blog/projects/why.html
(noting the shutdown features if u are focusing on the shutdown part).
more info:
https://fedoraproject.org/wiki/Systemd
[PDF]
Beyond Init: systemd - LinuxKongress 2010
www.linux-kongress.org/2010/slides/systemd-poettering.pdf
But as mentioned in document above, /dev/initctl is still supported, which is the traditional means of shutting down.
In Ubuntu (which uses sysvinit, and shutting down is via /dev/initctl), u can get the source code for poweroff via:
"apt-get source upstart"
and then start navigating through the source code.
Within util/shutdown.c you can see following:
* struct request: * * This is the structure passed across /dev/initctl. **/ struct request { int magic; int cmd; int runlevel; int sleeptime; char data[368]; };
/** * sysvinit_shutdown: * * Attempt to shutdown a running sysvinit /sbin/init using its /dev/initctl * socket. **/ static void sysvinit_shutdown (void) { struct sigaction act; struct request request; int fd;
/* Fill in the magic values */ memset (&request, 0, sizeof (request)); request.magic = 0x03091969; request.sleeptime = 5; request.cmd = 1;
/* Select a runlevel based on the event name */
There goes all the magic....or some part of it....
On Mon, May 14, 2012 at 7:31 PM, Asutosh Das <das.asutosh@gmail.com> wrote:
Hi List I have a query about the linux shutdown or reboot process.
Please can you let me know if the below sequence is correct:
When reboot command is given on the shell:
1. all user-space process is frozen (by sending some signal ?? ) 2. all file-systems are remounted as read-only - (sysrq handler does
this ?? )
3. all drivers, whose shutdown handlers have been defined, are called in the reverse order in which these drivers were initialized.
I am not sure what happens after this.
TIA.
-- Thanks & Regards ~/asd
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-- Regards, Peter Teoh
-- Regards, Peter Teoh
participants (4)
-
Asutosh Das -
Mulyadi Santosa -
Peter Teoh -
Prashant Shah