Skip to contentSkip to conversation

how to restart userland?

DISCUSSION Tomas Szepe 8 participants 13 messages Nov 3, 2003 – Nov 4, 2003

lore
Share & tools
lore
#0 lore raw

Hi,

Would anyone know of a proven way to completely restart the userland of a Linux system?

i.e. something like

# echo whatever-restart >/proc/wherever

Killing all processes.
Killing init.
Unmounting all filesystems.
VFS: Mounted root (ext2 filesystem).
INIT: v2.84 booting
...

Thanks for any pointers,

Signature · 1 line
Tomas Szepe <[email protected]>
#1 lore raw
Quoted 2 lines · Tomas Szepe

Would anyone know of a proven way to completely restart the userland of a Linux system?

This would be distinct from 'shutdown -r' how? Is there a reason you want to "completely" restart userland and *not* reboot (for instance, wanting to keep existing mounts, etc)?

A case could be made that for a "complete" restart, you need to trash those mounts too (if you're restarting to get a 'clean' setup, you want to actually be clean), and so forth.

#2 lore raw
Quoted 5 lines · On Nov-03 2003, Mon, 15:03 -0500 [email protected]…
Quoted 2 lines · Tomas Szepe

Would anyone know of a proven way to completely restart the userland of a Linux system?

This would be distinct from 'shutdown -r' how?

No reboot.

Quoted 2 lines

Is there a reason you want to "completely" restart userland and *not* reboot (for instance, wanting to keep existing mounts, etc)?

Extensive userland upgrades (glibc is a nice example I guess), etc.

Quoted 3 lines

A case could be made that for a "complete" restart, you need to trash those mounts too (if you're restarting to get a 'clean' setup, you want to actually be clean), and so forth.

Right.

Signature · 1 line
Tomas Szepe <[email protected]>
#3 lore raw
Quoted 7 lines · Tomas Szepe
Quoted 3 lines

Is there a reason you want to "completely" restart userland and *not* reboot (for instance, wanting to keep existing mounts, etc)?

Extensive userland upgrades (glibc is a nice example I guess), etc.

Consider using debian then - a glibc upgrade there is no problem as various services (including init) are restarted automatically mostly without disturbing running applications.

To make everything use the new library revision, do an "init 1". You'll get to single-user mode where you either log in and do an "init 2" or simply press ctrl+D for the same effect.

After that, nothing is holding onto deleted old libraries and /usr may be remounted read-only if you like.

Helge Hafting

#4 lore raw
Quoted 9 lines · Helge Hafting
Quoted 5 lines
Quoted 3 lines

Is there a reason you want to "completely" restart userland and *not* reboot (for instance, wanting to keep existing mounts, etc)?

Extensive userland upgrades (glibc is a nice example I guess), etc.

Consider using debian then - a glibc upgrade there is no problem as various services (including init) are restarted automatically mostly without disturbing running applications.

this should be mandatory in the packaging system.
mandrake too restart servers on glibc update.

this is definitively not a kernel problem, but a userland one.

#5 lore raw
In reply to [email protected]
Quoted 6 lines · [email protected] writes:
Quoted 2 lines

Would anyone know of a proven way to completely restart the userland of a Linux system?

This would be distinct from 'shutdown -r' how? Is there a reason you want to "completely" restart userland and *not* reboot (for instance, wanting to keep existing mounts, etc)?

Perhaps save some time. Some systems have notoriously slow BIOS.

Signature · 2 lines
Måns Rullgård
[email protected]
#7 lore raw
In reply to Tomas Szepe
Quoted 15 lines · Tomas Szepe

Hi,

Would anyone know of a proven way to completely restart the userland of a Linux system?

i.e. something like

# echo whatever-restart >/proc/wherever

Killing all processes.
Killing init.
Unmounting all filesystems.
VFS: Mounted root (ext2 filesystem).
INIT: v2.84 booting
...

Quoted 4 lines

Thanks for any pointers,
--
Tomas Szepe <[email protected]>
-

If you have an 'old' sys-V installation, you as root can execute init 0. Then, after everything has stopped, you can execute init 5 or init 6 to restart to the runlevel you had. More modern versions from (probably all) distributions won't allow this. But... you may be able to make a script. The problem is in fooling init to start all over again. You really need to modify init (perhaps runlevel 10) to, after everything is unmounted and all the gettys are killed, do:

	char *argv[3];
        argv[0] ="/sbin/init";
        argv[1] ="auto";
        argv[2] = NULL;
        execve(argv[0], argv, __environ);

That will overlay and restart init from scratch.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.

#8 lore raw
Quoted 7 lines · On Nov-03 2003, Mon, 15:32 -0500 Richard B. Johnson <[email protected]>…
	char *argv[3];
        argv[0] ="/sbin/init";
        argv[1] ="auto";
        argv[2] = NULL;
        execve(argv[0], argv, __environ);

That will overlay and restart init from scratch.

OK, that sounds like a plan. There's one problem, though -- I really need to do this in a single step (i.e. I won't have console access to issue any commands after all processes have been killed off and all the world's got is a root shell), so the script mustn't get killed while the system is coming down.

Thanks for help,

Signature · 1 line
Tomas Szepe <[email protected]>
#9 lore raw

Tomas Szepe <[email protected]> :
[...]

Quoted 5 lines

OK, that sounds like a plan. There's one problem, though -- I really need to do this in a single step (i.e. I won't have console access to issue any commands after all processes have been killed off and all the world's got is a root shell), so the script mustn't get killed while the system is coming down.

Hack sysvinit/shutdown.c so that it exec /sbin/telinit U and put the adequate command in /etc/inittab ?

--
Ueimor

#10 lore raw

Francois Romieu <[email protected]> :
[...]

Quoted 2 lines

Hack sysvinit/shutdown.c so that it exec /sbin/telinit U and put the adequate command in /etc/inittab ?

Won't work: init keeps "did_boot" in its state.

--
Ueimor

#11 lore raw
Quoted 6 lines · On Nov-03 2003, Mon, 22:03 +0100 Francois Romieu <[email protected]> wrote:

Francois Romieu <[email protected]> :
[...]

Quoted 2 lines

Hack sysvinit/shutdown.c so that it exec /sbin/telinit U and put the adequate command in /etc/inittab ?

Won't work: init keeps "did_boot" in its state.

Maybe also hack a new "telinit R" option that would clear the flag?

Signature · 1 line
Tomas Szepe <[email protected]>
#12 lore raw
In reply to Richard B. Johnson

In article <Pine.LNX.4.53.0311031519050.2654@chaos>,

Quoted 17 lines · Richard B. Johnson
Quoted 6 lines · Tomas Szepe

Hi,

Would anyone know of a proven way to completely restart the userland of a Linux system?

i.e. something like

Quoted 8 lines
# echo whatever-restart >/proc/wherever

Killing all processes.
Killing init.
Unmounting all filesystems.
VFS: Mounted root (ext2 filesystem).
INIT: v2.84 booting
...

Quoted 6 lines

If you have an 'old' sys-V installation, you as root can execute init 0.
Then, after everything has stopped, you can execute init 5 or init 6 to restart to the runlevel you had. More modern versions from (probably all) distributions won't allow this.

It's been a while since you used a real sysv right ? Or you've used different ones then I did.

The correct command for single user mode is:

# shutdown now (equivalent to "init 1")

Now the system will throw you into single user mode. Here, all processed are killed. It's just that all filesystems remain mounted

You can now login and enter 'init 2' or 'init 3' or whatever to go to that runlevel

Just exiting the shell (logout) will boot into the default runlevel

You can even just not login at all, press ^D and the system will boot to the default runlevel.

The command that is run at single user mode is "sulogin". It's invoked by init, as defined in /etc/inittab. If you just add a timeout to the sulogin invocation (-t 20 or so) then sulogin will exit after that timeout.

Now that is exactly what you want - add the timeout. Throw the system into single user mode with "shutdown now" or "init 1". After a while the system will be restarted from scratch without a reboot.

This will work on Debian. It most likely will works on other distributions too, and probably on most System Vs as well. Though on System V the shutdown command is "shutdown -i1 -y". Which, btw, will work just fine on Linux too ;)

Mike.