README 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 -c")
  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 it's 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 arugemnt 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, but this may change early in
  69. the 2.7 era (it missed the boat for 2.5).
  70. You can obtain somewhat infrequent snapshots of klibc from
  71. ftp://ftp.kernel.org/pub/linux/libs/klibc/
  72. For active users, you are better off using the klibc BitKeeper
  73. repositories, at http://klibc.bkbits.net/
  74. The standalone klibc distribution currently provides three components,
  75. in addition to the klibc library:
  76. - ipconfig, a program that configures network interfaces. It can
  77. configure them statically, or use DHCP to obtain information
  78. dynamically (aka "IP autoconfiguration").
  79. - nfsmount, a program that can mount an NFS filesystem.
  80. - kinit, the "glue" that uses ipconfig and nfsmount to replace the old
  81. support for IP autoconfig, mount a filesystem over NFS, and continue
  82. system boot using that filesystem as root.
  83. kinit is built as a single statically linked binary to save space.
  84. Eventually, several more chunks of kernel functionality will hopefully
  85. move to early userspace:
  86. - Almost all of init/do_mounts* (the beginning of this is already in
  87. place)
  88. - ACPI table parsing
  89. - Insert unwieldy subsystem that doesn't really need to be in kernel
  90. space here
  91. If kinit doesn't meet your current needs and you've got bytes to burn,
  92. the klibc distribution includes a small Bourne-compatible shell (ash)
  93. and a number of other utilities, so you can replace kinit and build
  94. custom initramfs images that meet your needs exactly.
  95. For questions and help, you can sign up for the early userspace
  96. mailing list at http://www.zytor.com/mailman/listinfo/klibc
  97. How does it work?
  98. =================
  99. The kernel has currently 3 ways to mount the root filesystem:
  100. a) all required device and filesystem drivers compiled into the kernel, no
  101. initrd. init/main.c:init() will call prepare_namespace() to mount the
  102. final root filesystem, based on the root= option and optional init= to run
  103. some other init binary than listed at the end of init/main.c:init().
  104. b) some device and filesystem drivers built as modules and stored in an
  105. initrd. The initrd must contain a binary '/linuxrc' which is supposed to
  106. load these driver modules. It is also possible to mount the final root
  107. filesystem via linuxrc and use the pivot_root syscall. The initrd is
  108. mounted and executed via prepare_namespace().
  109. c) using initramfs. The call to prepare_namespace() must be skipped.
  110. This means that a binary must do all the work. Said binary can be stored
  111. into initramfs either via modifying usr/gen_init_cpio.c or via the new
  112. initrd format, an cpio archive. It must be called "/init". This binary
  113. is responsible to do all the things prepare_namespace() would do.
  114. To remain backwards compatibility, the /init binary will only run if it
  115. comes via an initramfs cpio archive. If this is not the case,
  116. init/main.c:init() will run prepare_namespace() to mount the final root
  117. and exec one of the predefined init binaries.
  118. Bryan O'Sullivan <bos@serpentine.com>