2003-11-03 19:39:44

by Tomas Szepe

[permalink] [raw]
Subject: how to restart userland?

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,
--
Tomas Szepe <[email protected]>


2003-11-03 20:04:23

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: how to restart userland?

On Mon, 03 Nov 2003 20:39:40 +0100, Tomas Szepe <[email protected]> said:
> 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.


Attachments:
(No filename) (226.00 B)

2003-11-03 20:12:26

by Tomas Szepe

[permalink] [raw]
Subject: Re: how to restart userland?

On Nov-03 2003, Mon, 15:03 -0500
[email protected] <[email protected]> wrote:

> On Mon, 03 Nov 2003 20:39:40 +0100, Tomas Szepe <[email protected]> said:
> > 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.

> 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.

> 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.

--
Tomas Szepe <[email protected]>

2003-11-03 20:21:36

by Måns Rullgård

[permalink] [raw]
Subject: Re: how to restart userland?

[email protected] writes:

>> 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.

--
M?ns Rullg?rd
[email protected]

2003-11-03 20:31:28

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: how to restart userland?

On Mon, 03 Nov 2003 21:21:30 +0100, [email protected] (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=) said:

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

kexec patch?


Attachments:
(No filename) (226.00 B)

2003-11-03 20:32:49

by Richard B. Johnson

[permalink] [raw]
Subject: Re: how to restart userland?

On Mon, 3 Nov 2003, Tomas Szepe wrote:

> 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,
> --
> 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.


2003-11-03 20:41:29

by Tomas Szepe

[permalink] [raw]
Subject: Re: how to restart userland?

On Nov-03 2003, Mon, 15:32 -0500
Richard B. Johnson <[email protected]> wrote:

> 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,
--
Tomas Szepe <[email protected]>

2003-11-03 21:09:24

by Francois Romieu

[permalink] [raw]
Subject: Re: how to restart userland?

Tomas Szepe <[email protected]> :
[...]
> 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

2003-11-03 21:08:54

by Francois Romieu

[permalink] [raw]
Subject: Re: how to restart userland?

Francois Romieu <[email protected]> :
[...]
> 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

2003-11-03 21:12:47

by Tomas Szepe

[permalink] [raw]
Subject: Re: how to restart userland?

On Nov-03 2003, Mon, 22:03 +0100
Francois Romieu <[email protected]> wrote:

> Francois Romieu <[email protected]> :
> [...]
> > 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?

--
Tomas Szepe <[email protected]>

2003-11-03 23:32:38

by Miquel van Smoorenburg

[permalink] [raw]
Subject: Re: how to restart userland?

In article <Pine.LNX.4.53.0311031519050.2654@chaos>,
Richard B. Johnson <[email protected]> wrote:
>On Mon, 3 Nov 2003, Tomas Szepe wrote:
>
>> 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
>> ...
>
>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.

2003-11-04 09:55:47

by Helge Hafting

[permalink] [raw]
Subject: Re: how to restart userland?

Tomas Szepe wrote:

>
>>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

2003-11-04 16:23:47

by Thierry Vignaud

[permalink] [raw]
Subject: Re: how to restart userland?

Helge Hafting <[email protected]> writes:

> > > 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.