shutdown busybox and start another PID1 process

Sam Liddicott sam at liddicott.com
Sun Aug 10 04:56:02 UTC 2014


You can replace /sbin/init with a bind mount; e.g.

mount /tmpfs/sbin/init.shutdown /sbin/init -o bind

that will replace init, but only till the next reboot.

When debugging the first couple of lines should be something like:

exec >/dev/ttyS0 2>&1 # if serial console
exec >/dev/tty1 2>&1 # if normal console
set -x # debug script output
and maybe:
trap "sleep 10" 0 # so that you can have time to read final error messages
before it reboots

On Sat, Aug 9, 2014 at 11:44 PM, James Bowlin <bitjam at gmail.com> wrote:

> On Sat, Aug 09, 2014 at 01:02 PM, Rieker Flaik said:
> > There I can exec busybox its normal init "/sbin/init". This is
> > what I want to use in this pre-OS, having a nice init system to
> > spawn all kinds of programs like udhcp and dropbear to do the
> > backup stuff.
>
> It is actually very easy to get control back from /sbin/init.
>
> Replace /sbin/init with the script you want to run.  Then run the
> command:
>
>     telinit u
>
> This tells the init process to shutdown and restart.  When it
> restarts, your script at /sbin/init is what will run.
>
> Before you start playing with this, do:
>
>     sudo ls -l /proc/1/fd
>
> and notice that most standard IO is turned off (at least on my
> systems).  If you want PID-1 to be a shell again then you will
> need to reconnect some IO.
>
> Some LiveCD/USB systems use this trick to get PID-1 to run from a
> small (RAM based) busybox system during shutdown.  The great
> thing about this is it gives you the ability to have shell access
> throughout the shutdown process even after all non-RAM file
> systems have been unmounted.
>
> IMO this is actually more stable and more robust than the
> conventional way Linux systems shut down.  The major cost
> is the 1-Meg or so of RAM needed the tmpfs for busybox.  I think
> the Linux distros should migrate to using busybox for the
> shutdown process even when not running live.
>
> Peace, James
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20140810/b073d5b1/attachment.html>


More information about the busybox mailing list