Subject: chroot problem
To: None <current-users@netbsd.org>
From: Martti Kuparinen <martti.kuparinen@iki.fi>
List: current-users
Date: 09/14/2007 10:07:52
Hi,

I have a really weird problem with chroot in NetBSD 4.0_RC1. I extract all the 
distribution sets, create the device nodes etc. and start my chroot with "chroot 
/var/chroot/netbsd/rootdir /bin/sh". Everything is fine so far.

Next I run "make configure" in /usr/pkgsrc/net/p5-Socket6 and look at the 
created config.log file. Here it becomes interesting...

In NetBSD 3.1.1 I see this, everything is fine here:

========================================================================
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by configure, which was
generated by GNU Autoconf 2.59.  Invocation command line was

   $ ./configure --with-perl=/usr/pkg/bin/perl

## --------- ##
## Platform. ##
## --------- ##

hostname = inside.mydomain.com
uname -m = i386
uname -r = 3.1.1
uname -s = NetBSD
...
========================================================================

In NetBSD 4.0_RC1 I see this, look at the with-perl line:

========================================================================
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by configure, which was
generated by GNU Autoconf 2.59.  Invocation command line was

   $ ./configure --with-perl=/var/chroot/netbsd/rootdir/usr/pkg/bin/perl

## --------- ##
## Platform. ##
## --------- ##

hostname = p130.mydomain.com
uname -m = amd64
uname -r = 4.0_RC1
uname -s = NetBSD
========================================================================

How is it possible that the chroot'ed /bin/sh process is somehow able to see its 
chroot basedir (/var/chroot/netbsd/rootdir)? In both cases (3.1.1 and 4.0_RC1) 
I'm unable to e.g. see /home inside the chroot so this works as expected.

CHROOT p130:/> cd /home
bash: cd: /home: No such file or directory
CHROOT p130:/> exit
exit
ROOT p130:~> cd /home
ROOT p130:/home>


I can't find any refence to /var/chroot/netbsd inside the chroot:

ROOT p130:/var/chroot/netbsd/rootdir/usr/pkg> grep -rl /var/chroot *
ROOT p130:/var/chroot/netbsd/rootdir/usr/pkg>


Here's what I have mounted on the "host system":

ROOT p130:~> mount
...
/usr/pkgsrc on /var/chroot/netbsd/rootdir/usr/pkgsrc type null (local)
/var/tmp/distfiles on /var/chroot/netbsd/rootdir/var/tmp/distfiles type null (local)
/var/tmp/packages on /var/chroot/netbsd/rootdir/var/tmp/packages type null (local)
procfs on /var/chroot/netbsd/rootdir/proc type procfs (local)


And the "guest system" sees those null mounts as normal directories:

CHROOT p130:/usr/pkgsrc/net/p5-Socket6> df -h
Filesystem           Size      Used     Avail Capacity  Mounted on
/usr/pkgsrc           19G      5.9G       13G    31%    /usr/pkgsrc
/var/tmp/distfiles   9.7G      788M      8.4G     8%    /var/tmp/distfiles
/var/tmp/packages    9.7G      788M      8.4G     8%    /var/tmp/packages
procfs               4.0K      4.0K        0B   100%    /proc
/dev/sd0a             19G      5.9G       13G    31%    /

Any ideas what is going on here? Something weird with null mounts?

Martti