README 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. Early userspace support
  2. =======================
  3. Last update: 2004-12-20 tlh
  4. "Early userspace" is a set of libraries and programs that provide
  5. various pieces of functionality that are important enough to be
  6. available while a Linux kernel is coming up, but that don't need to be
  7. run inside the kernel itself.
  8. It consists of several major infrastructure components:
  9. - gen_init_cpio, a program that builds a cpio-format archive
  10. containing a root filesystem image. This archive is compressed, and
  11. the compressed image is linked into the kernel image.
  12. - initramfs, a chunk of code that unpacks the compressed cpio image
  13. midway through the kernel boot process.
  14. - klibc, a userspace C library, currently packaged separately, that is
  15. optimized for correctness and small size.
  16. The cpio file format used by initramfs is the "newc" (aka "cpio -H newc")
  17. format, and is documented in the file "buffer-format.txt". There are
  18. two ways to add an early userspace image: specify an existing cpio
  19. archive to be used as the image or have the kernel build process build
  20. the image from specifications.
  21. CPIO ARCHIVE method
  22. You can create a cpio archive that contains the early userspace image.
  23. Your cpio archive should be specified in CONFIG_INITRAMFS_SOURCE and it
  24. will be used directly. Only a single cpio file may be specified in
  25. CONFIG_INITRAMFS_SOURCE and directory and file names are not allowed in
  26. combination with a cpio archive.
  27. IMAGE BUILDING method
  28. The kernel build process can also build an early userspace image from
  29. source parts rather than supplying a cpio archive. This method provides
  30. a way to create images with root-owned files even though the image was
  31. built by an unprivileged user.
  32. The image is specified as one or more sources in
  33. CONFIG_INITRAMFS_SOURCE. Sources can be either directories or files -
  34. cpio archives are *not* allowed when building from sources.
  35. A source directory will have it and all of its contents packaged. The
  36. specified directory name will be mapped to '/'. When packaging a
  37. directory, limited user and group ID translation can be performed.
  38. INITRAMFS_ROOT_UID can be set to a user ID that needs to be mapped to
  39. user root (0). INITRAMFS_ROOT_GID can be set to a group ID that needs
  40. to be mapped to group root (0).
  41. A source file must be directives in the format required by the
  42. usr/gen_init_cpio utility (run 'usr/gen_init_cpio --help' to get the
  43. file format). The directives in the file will be passed directly to
  44. usr/gen_init_cpio.
  45. When a combination of directories and files are specified then the
  46. initramfs image will be an aggregate of all of them. In this way a user
  47. can create a 'root-image' directory and install all files into it.
  48. Because device-special files cannot be created by a unprivileged user,
  49. special files can be listed in a 'root-files' file. Both 'root-image'
  50. and 'root-files' can be listed in CONFIG_INITRAMFS_SOURCE and a complete
  51. early userspace image can be built by an unprivileged user.
  52. As a technical note, when directories and files are specified, the
  53. entire CONFIG_INITRAMFS_SOURCE is passed to
  54. scripts/gen_initramfs_list.sh. This means that CONFIG_INITRAMFS_SOURCE
  55. can really be interpreted as any legal argument to
  56. gen_initramfs_list.sh. If a directory is specified as an argument then
  57. the contents are scanned, uid/gid translation is performed, and
  58. usr/gen_init_cpio file directives are output. If a directory is
  59. specified as an argument to scripts/gen_initramfs_list.sh then the
  60. contents of the file are simply copied to the output. All of the output
  61. directives from directory scanning and file contents copying are
  62. processed by usr/gen_init_cpio.
  63. See also 'scripts/gen_initramfs_list.sh -h'.
  64. Where's this all leading?
  65. =========================
  66. The klibc distribution contains some of the necessary software to make
  67. early userspace useful. The klibc distribution is currently
  68. maintained separately from the kernel.
  69. You can obtain somewhat infrequent snapshots of klibc from
  70. ftp://ftp.kernel.org/pub/linux/libs/klibc/
  71. For active users, you are better off using the klibc git
  72. repository, at http://git.kernel.org/?p=libs/klibc/klibc.git
  73. The standalone klibc distribution currently provides three components,
  74. in addition to the klibc library:
  75. - ipconfig, a program that configures network interfaces. It can
  76. configure them statically, or use DHCP to obtain information
  77. dynamically (aka "IP autoconfiguration").
  78. - nfsmount, a program that can mount an NFS filesystem.
  79. - kinit, the "glue" that uses ipconfig and nfsmount to replace the old
  80. support for IP autoconfig, mount a filesystem over NFS, and continue
  81. system boot using that filesystem as root.
  82. kinit is built as a single statically linked binary to save space.
  83. Eventually, several more chunks of kernel functionality will hopefully
  84. move to early userspace:
  85. - Almost all of init/do_mounts* (the beginning of this is already in
  86. place)
  87. - ACPI table parsing
  88. - Insert unwieldy subsystem that doesn't really need to be in kernel
  89. space here
  90. If kinit doesn't meet your current needs and you've got bytes to burn,
  91. the klibc distribution includes a small Bourne-compatible shell (ash)
  92. and a number of other utilities, so you can replace kinit and build
  93. custom initramfs images that meet your needs exactly.
  94. For questions and help, you can sign up for the early userspace
  95. mailing list at http://www.zytor.com/mailman/listinfo/klibc
  96. How does it work?
  97. =================
  98. The kernel has currently 3 ways to mount the root filesystem:
  99. a) all required device and filesystem drivers compiled into the kernel, no
  100. initrd. init/main.c:init() will call prepare_namespace() to mount the
  101. final root filesystem, based on the root= option and optional init= to run
  102. some other init binary than listed at the end of init/main.c:init().
  103. b) some device and filesystem drivers built as modules and stored in an
  104. initrd. The initrd must contain a binary '/linuxrc' which is supposed to
  105. load these driver modules. It is also possible to mount the final root
  106. filesystem via linuxrc and use the pivot_root syscall. The initrd is
  107. mounted and executed via prepare_namespace().
  108. c) using initramfs. The call to prepare_namespace() must be skipped.
  109. This means that a binary must do all the work. Said binary can be stored
  110. into initramfs either via modifying usr/gen_init_cpio.c or via the new
  111. initrd format, an cpio archive. It must be called "/init". This binary
  112. is responsible to do all the things prepare_namespace() would do.
  113. To maintain backwards compatibility, the /init binary will only run if it
  114. comes via an initramfs cpio archive. If this is not the case,
  115. init/main.c:init() will run prepare_namespace() to mount the final root
  116. and exec one of the predefined init binaries.
  117. Bryan O'Sullivan <bos@serpentine.com>