initramfs, job control and a cttyhack hack

Richard Hoyle hoyle.richard at googlemail.com
Wed Nov 28 16:05:18 UTC 2007


Hi,

It doesn't seem easy to get a controlling terminal on an
initramfs/initrd disk.  There may be a number of ways around
this, and I'd be very grateful if somebody could show me the
light.  In the meantime, here's something that works for me.

If you want a controlling terminal, all the docs, and postings
seem to tell you to start a proper init process with the proper
bb init app.  You create an /etc/inittab, and shove in an entry
like this:

::respawn:/bin/cttyhack -/bin/sh

If you do that, you can't then run 'exec switch_root ...' (as
/sbin/init is still running).

I patched the cttyhack.c applet with the attached two line change
(patch below, inline).

Then I put this in the first line of my /init script:

#!/bin/cttyhack /bin/ash

Now the /init script can shell out with full job control.  You
can then 'exit' from the shell and have the script carry on,
finally exec'ing switch_root to boot up your distro.

If there is a better way without touching the bb code or the
kernel file kernel file drivers/char/tty_io.c, can somebody let
me know, please.

Thank you for BusyBox, and making it available under the GPL.

All the best,

===Rich

Patch against bb 1.8.1.


--- ./shell/cttyhack.c.org      2007-11-10 01:40:50.000000000
+0000
+++ ./shell/cttyhack.c  2007-11-28 05:24:25.000000000 +0000
@@ -66,6 +66,8 @@
                dup2(fd, 1);
                dup2(fd, 2);
                while (fd > 2) close(fd--);
+               setsid();
+               ioctl(0, TIOCSCTTY, 1);
        }

        execvp(argv[0], argv);



More information about the busybox mailing list