kernfs.xml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % general-entities SYSTEM "../general.ent">
  5. %general-entities;
  6. ]>
  7. <sect1 id="ch-system-kernfs">
  8. <?dbhtml filename="kernfs.html"?>
  9. <title>Preparing Virtual Kernel File Systems</title>
  10. <indexterm zone="ch-system-kernfs">
  11. <primary sortas="e-/dev/">/dev/*</primary>
  12. </indexterm>
  13. <para>Various file systems exported by the kernel are used to communicate to
  14. and from the kernel itself. These file systems are virtual in that no disk
  15. space is used for them. The content of the file systems resides in
  16. memory.</para>
  17. <para>Begin by creating directories onto which the file systems will be
  18. mounted:</para>
  19. <screen><userinput>mkdir -v $LFS/{dev,proc,sys}</userinput></screen>
  20. <sect2>
  21. <title>Creating Initial Device Nodes</title>
  22. <para>When the kernel boots the system, it requires the presence of a few
  23. device nodes, in particular the <filename
  24. class="devicefile">console</filename> and <filename
  25. class="devicefile">null</filename> devices. The device nodes must be created
  26. on the hard disk so that they are available before <command>udevd</command>
  27. has been started, and additionally when Linux is started with
  28. <parameter>init=/bin/bash</parameter>. Create the devices by running the
  29. following commands:</para>
  30. <screen><userinput>mknod -m 600 $LFS/dev/console c 5 1
  31. mknod -m 666 $LFS/dev/null c 1 3</userinput></screen>
  32. </sect2>
  33. <sect2 id="ch-system-bindmount">
  34. <title>Mounting and Populating /dev</title>
  35. <para>The recommended method of populating the <filename
  36. class="directory">/dev</filename> directory with devices is to mount a
  37. virtual filesystem (such as <systemitem
  38. class="filesystem">tmpfs</systemitem>) on the <filename
  39. class="directory">/dev</filename> directory, and allow the devices to be
  40. created dynamically on that virtual filesystem as they are detected or
  41. accessed. Device creation is generally done during the boot process
  42. by Udev. Since this new system does not yet have Udev and has not yet
  43. been booted, it is necessary to mount and populate <filename
  44. class="directory">/dev</filename> manually. This is accomplished by bind
  45. mounting the host system's <filename class="directory">/dev</filename>
  46. directory. A bind mount is a special type of mount that allows you to
  47. create a mirror of a directory or mount point to some other location. Use
  48. the following command to achieve this:</para>
  49. <screen><userinput>mount -v --bind /dev $LFS/dev</userinput></screen>
  50. </sect2>
  51. <sect2 id="ch-system-kernfsmount">
  52. <title>Mounting Virtual Kernel File Systems</title>
  53. <para>Now mount the remaining virtual kernel filesystems:</para>
  54. <screen><userinput>mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
  55. mount -vt proc proc $LFS/proc
  56. mount -vt sysfs sysfs $LFS/sys</userinput></screen>
  57. <variablelist>
  58. <title>The meaning of the mount options for devpts:</title>
  59. <varlistentry>
  60. <term><parameter>gid=5</parameter></term>
  61. <listitem>
  62. <para>This ensures that all devpts-created device nodes are owned by
  63. group ID 5. This is the ID we will use later on for the <systemitem
  64. class="groupname">tty</systemitem> group. We use the group ID instead
  65. of a name, since the host system might use a different ID for its
  66. <systemitem class="groupname">tty</systemitem> group.</para>
  67. </listitem>
  68. </varlistentry>
  69. <varlistentry>
  70. <term><parameter>mode=0620</parameter></term>
  71. <listitem>
  72. <para>This ensures that all devpts-created device nodes have mode 0620
  73. (user readable and writable, group writable). Together with the
  74. option above, this ensures that devpts will create device nodes that
  75. meet the requirements of grantpt(), meaning the Glibc
  76. <command>pt_chown</command> helper binary (which is not installed by
  77. default) is not necessary.</para>
  78. </listitem>
  79. </varlistentry>
  80. </variablelist>
  81. <para>In some host systems, <filename>/dev/shm</filename> is a
  82. symbolic link to <filename class="directory">/run/shm</filename>.
  83. Inside a chroot environment, this temporary file system needs
  84. to be mounted separate from the host file system:</para>
  85. <screen><userinput>if [ -h $LFS/dev/shm ]; then
  86. link=$(readlink $LFS/dev/shm)
  87. mkdir -p $LFS/$link
  88. mount -vt tmpfs shm $LFS/$link
  89. unset link
  90. else
  91. mount -vt tmpfs shm $LFS/dev/shm
  92. fi</userinput></screen>
  93. </sect2>
  94. </sect1>