[Libguestfs] [PATCH 1/3] febootstrap/helper/init: make sure /proc is mounted into chroot.

Hilko Bengen bengen at hilluzination.de
Mon Jun 6 14:44:58 UTC 2011


* Richard W.M. Jones:

> Is the point here to mount /proc before printing the uptime (which is
> obviously going to fail)?  

Yeah, I just noticed that the second call to print_uptime() failed and
fixed that -- not thinking about why the uptime was printed at all.

> Do you think it's better to mount /proc in the init script?

Good question. The init script that Debian's initramfs-tools put into
the initrd do mount /proc and a number of other filesystems, so I think
makes sense to do something similar in the init script that is installed
by febootstrap -- at least on Debian systems.

This is the initialization code from initramfs-tools version 0.98.8 from
squeeze (stable):

,----
| [ -d /dev ] || mkdir -m 0755 /dev
| [ -d /root ] || mkdir -m 0700 /root
| [ -d /sys ] || mkdir /sys
| [ -d /proc ] || mkdir /proc
| [ -d /tmp ] || mkdir /tmp
| mkdir -p /var/lock
| mount -t sysfs -o nodev,noexec,nosuid none /sys
| mount -t proc -o nodev,noexec,nosuid none /proc
| 
| # Note that this only becomes /dev on the real filesystem if udev's scripts
| # are used; which they will be, but it's worth pointing out
| tmpfs_size="10M"
| if [ -e /etc/udev/udev.conf ]; then
| 	. /etc/udev/udev.conf
| fi
| if ! mount -t devtmpfs -o mode=0755 none /dev; then
| 	echo "W: devtmpfs not available, falling back to tmpfs for /dev"
| 	mount -t tmpfs -o size=$tmpfs_size,mode=0755 udev /dev
| 	[ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1
| 	[ -e /dev/null ] || mknod /dev/null c 1 3
| fi
| mkdir /dev/pts
| mount -t devpts -o noexec,nosuid,gid=5,mode=0620 none /dev/pts || true
| > /dev/.initramfs-tools
| mkdir /dev/.initramfs
`----

After that, the command line parameters are parsed, some
package-provided scripts are sourced, and finally the root filesystem is
mounted. Just before the init script on the root fs is called, existing
mounts are moved:

,----
| mount -n -o move /sys ${rootmnt}/sys
| mount -n -o move /proc ${rootmnt}/proc
`----

(I wonder why /dev isn't moved, though.)

The most notable change introduced in initramfs-tools 0.99 (current
unstable) is that init also puts a tmpfs under /run which is later moved
into the root filesystem:

,----
| mount -t tmpfs -o "nosuid,size=20%,mode=0755" tmpfs /run
`----

I haven't looked at how RedHat and Fedora systems behave before mounting
the root fs but having all the mounts set up by the init that lives in
the initrd does make sense to me.

> libguestfs already mounts /proc in the init script:
>
> http://git.annexia.org/?p=libguestfs.git;a=blob;f=appliance/init;hb=HEAD

This is the init script that is execl()'d by febootstrap's init,
correct?

-Hilko




More information about the Libguestfs mailing list