From owner-freebsd-hackers@FreeBSD.ORG Fri Dec 29 17:36:18 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 831DE16A40F for ; Fri, 29 Dec 2006 17:36:18 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [83.120.8.8]) by mx1.freebsd.org (Postfix) with ESMTP id 042D413C486 for ; Fri, 29 Dec 2006 17:36:17 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (ahsrqx@localhost [127.0.0.1]) by lurza.secnetix.de (8.13.4/8.13.4) with ESMTP id kBTHaAlX021369; Fri, 29 Dec 2006 18:36:15 +0100 (CET) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.13.4/8.13.1/Submit) id kBTHa9kj021368; Fri, 29 Dec 2006 18:36:09 +0100 (CET) (envelope-from olli) From: Oliver Fromme Message-Id: <200612291736.kBTHa9kj021368@lurza.secnetix.de> To: imp@bsdimp.com (M. Warner Losh) Date: Fri, 29 Dec 2006 18:36:09 +0100 (CET) In-Reply-To: <20061228.134053.-1548238884.imp@bsdimp.com> X-Mailer: ELM [version 2.5 PL8] MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Fri, 29 Dec 2006 18:36:15 +0100 (CET) X-Mailman-Approved-At: Fri, 29 Dec 2006 19:45:07 +0000 Cc: erik.udo@gmail.com, freebsd-hackers@freebsd.org Subject: Re: Init.c, making it chroot X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Dec 2006 17:36:18 -0000 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 #include #include +#include #include #include #include @@ -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