<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  <!ENTITY % general-entities SYSTEM "../../general.ent">
  %general-entities;
]>

<sect1 id="ch-chroot-kernfs">
  <?dbhtml filename="kernfs.html"?>

  <title>Mounting Virtual Kernel File Systems</title>

    <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
    href="../../boot/common/devices.xml"
    xpointer="xpointer(//*[@os='a'])"/>

  <para>Various file systems exported by the kernel are used to communicate
  to and from the kernel itself. These file systems are virtual in that no
  disk space is used for them. The content of the file systems resides in
  memory.</para>

  <para>Begin by creating directories onto which the file systems will
  be mounted:</para>

<screen><userinput>mkdir -pv ${CLFS}/{dev,proc,sys}</userinput></screen>

  <para>Now mount the file systems:</para>

<screen><userinput>mount -vt proc proc ${CLFS}/proc
mount -vt sysfs sysfs ${CLFS}/sys</userinput></screen>

  <para>Remember that if for any reason you stop working on the CLFS system
  and start again later, it is important to check that these file systems
  are mounted again before entering the chroot environment.</para>

  <para>Two device nodes, /dev/console and /dev/null, are required to be
  present on the filesystem.  These are needed by the kernel even before
  starting Eudev early in the boot process, so we create them here:</para>

<screen><userinput>mknod -m 600 ${CLFS}/dev/console c 5 1
mknod -m 666 ${CLFS}/dev/null c 1 3</userinput></screen>

  <para>Once the system is complete and booting, the rest of our device
  nodes are created by the Eudev package.  Since this package is not
  available to us right now, we must take other steps to provide device
  nodes under on the CLFS filesystem.  We will use the <quote>bind</quote>
  option in the mount command to make our host system's /dev structure
  appear in the new CLFS filesystem:</para>

<screen><userinput>mount -v -o bind /dev ${CLFS}/dev</userinput></screen>

  <para>Additional file systems will soon be mounted from within the chroot 
  environment. To keep the host up to date, perform a <quote>fake mount</quote>
  for each of these now:</para>

<screen><userinput>if [ -h ${CLFS}/dev/shm ]; then
  link=$(readlink ${CLFS}/dev/shm)
  mkdir -p ${CLFS}/$link
  mount -f -vt tmpfs shm ${CLFS}/$link
  unset link
else
  mount -f -vt tmpfs shm ${CLFS}/dev/shm
fi
mount -f -vt devpts -o gid=&gid-tty;,mode=620 devpts ${CLFS}/dev/pts</userinput></screen>

</sect1>
