M. Warner Losh wrote:
 > BTW, here's a patch to test.  Since FreeBSD has kenv(2), the patch is
 > actually very small.

OK, I tried it.  The patch applied cleanly to RELENG_6.
The following line triggered a warning and caused the
compilation to be aborted:

 > +    kenv(KENV_GET, "init_chroot", init_chroot, sizeof(init_chroot));

I get:

   /usr/src/sbin/init/init.c: In function `main':
   /usr/src/sbin/init/init.c:245: warning: passing arg 2 of `kenv' discards 
qualifiers from pointer target type

I modified your patch slightly, now also checking the
return value from kenv():

--- init.orig/init.c    Sat Jul 15 13:12:44 2006
+++ init/init.c Fri Dec 29 14:52:59 2006
@@ -55,6 +55,7 @@
 #include <db.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <kenv.h>
 #include <libutil.h>
 #include <paths.h>
 #include <signal.h>
@@ -187,6 +188,8 @@
 int
 main(int argc, char *argv[])
 {
+       char init_chroot[PATH_MAX];
+       char init_chroot_name[] = "init_chroot";
        int c;
        struct sigaction sa;
        sigset_t mask;
@@ -238,6 +241,13 @@
         * Does 'init' deserve its own facility number?
         */
        openlog("init", LOG_CONS|LOG_ODELAY, LOG_AUTH);
+
+       *init_chroot = '\0';
+       if (kenv(KENV_GET, init_chroot_name, init_chroot, sizeof(init_chroot))
+           && *init_chroot != '\0') {
+               if (chdir(init_chroot) != 0 || chroot(".") != 0)
+                       warning("Can't chroot to %s: %m", init_chroot);
+       }
 
        /*
         * Create an initial session.

It compiles without problems.  For testing I prepared an
ISO image and put everything into a subdirectory called
/chroot, except for /boot.  /boot/loader.conf contains
these lines:

   init_path="/ochroot/sbin/init"
   init_chroot="/ochroot"

When I boot the CD (with -v), it freezes after printing
these lines:

   cd9660: RockRidge Extension
   Lookup of /dev for devfs, error: 2
   start_init: trying /ochroot/sbin/init

It seems that the kernel looks for /dev before starting
init, hence before the chroot.  So I created /dev in the
ISO image and tried again.  Now the "devfs error 2" line
doesn't appear anymore, but it still freezes after the
"start_init" line.

I suspect that init expects devfs to be mounted on /dev
_inside_ the chroot (i.e. on /ochroot/dev in my case),
but I'm not sure if that's really causing the freeze.
Unfortunately I haven't been able to analyse the problem
further.  Do you have an idea or hint?

(I can put my ISO online for testing if someone wants
to look at it.  It's 27 MB compressed.)

Best regards
   Oliver

PS:  The init_chroot feature would also be useful for
making a shared CD/DVD that contains a standard FreeBSD
installation (with sysinstall and "fixit") and a bootable
live FS such as FreeSBIE at the same time.

-- 
Oliver Fromme,  secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

Perl is worse than Python because people wanted it worse.
        -- Larry Wall
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to