customize-rootfs.adoc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // -*- mode:doc; -*-
  2. // vim: set syntax=asciidoc:
  3. [[rootfs-custom]]
  4. === Customizing the generated target filesystem
  5. Besides changing the configuration through +make *config+,
  6. there are a few other ways to customize the resulting target filesystem.
  7. The two recommended methods, which can co-exist, are root filesystem
  8. overlay(s) and post build script(s).
  9. Root filesystem overlays (+BR2_ROOTFS_OVERLAY+)::
  10. +
  11. A filesystem overlay is a tree of files that is copied directly
  12. over the target filesystem after it has been built. To enable this
  13. feature, set config option +BR2_ROOTFS_OVERLAY+ (in the +System
  14. configuration+ menu) to the root of the overlay. You can even specify
  15. multiple overlays, space-separated. If you specify a relative path,
  16. it will be relative to the root of the Buildroot tree. Hidden
  17. directories of version control systems, like +.git+, +.svn+, +.hg+,
  18. etc., files called +.empty+ and files ending in +~+ are excluded from
  19. the copy.
  20. +
  21. When +BR2_ROOTFS_MERGED_USR+ is enabled, then the overlay must not
  22. contain the '/bin', '/lib' or '/sbin' directories, as Buildroot will
  23. create them as symbolic links to the relevant folders in '/usr'. In
  24. such a situation, should the overlay have any programs or libraries,
  25. they should be placed in '/usr/bin', '/usr/sbin' and '/usr/lib'.
  26. +
  27. As shown in xref:customize-dir-structure[], the recommended path for
  28. this overlay is +board/<company>/<boardname>/rootfs-overlay+.
  29. Post-build scripts (+BR2_ROOTFS_POST_BUILD_SCRIPT+)::
  30. +
  31. Post-build scripts are shell scripts called 'after' Buildroot builds
  32. all the selected software, but 'before' the rootfs images are
  33. assembled. To enable this feature, specify a space-separated list of
  34. post-build scripts in config option +BR2_ROOTFS_POST_BUILD_SCRIPT+ (in
  35. the +System configuration+ menu). If you specify a relative path, it
  36. will be relative to the root of the Buildroot tree.
  37. +
  38. Using post-build scripts, you can remove or modify any file in your
  39. target filesystem. You should, however, use this feature with care.
  40. Whenever you find that a certain package generates wrong or unneeded
  41. files, you should fix that package rather than work around it with some
  42. post-build cleanup scripts.
  43. +
  44. As shown in xref:customize-dir-structure[], the recommended path for
  45. this script is +board/<company>/<boardname>/post_build.sh+.
  46. +
  47. The post-build scripts are run with the main Buildroot tree as current
  48. working directory. The path to the target filesystem is passed as the
  49. first argument to each script. If the config option
  50. +BR2_ROOTFS_POST_SCRIPT_ARGS+ is not empty, these arguments will be
  51. passed to the script too. All the scripts will be passed the exact
  52. same set of arguments, it is not possible to pass different sets of
  53. arguments to each script.
  54. Note that the arguments from +BR2_ROOTFS_POST_SCRIPT_ARGS+ will also be
  55. passed to post-image and post-fakeroot scripts. If you want to use
  56. arguments that are only used for the post-build scripts you can use
  57. +BR2_ROOTFS_POST_BUILD_SCRIPT_ARGS+.
  58. +
  59. In addition, you may also use these environment variables:
  60. - +BR2_CONFIG+: the path to the Buildroot .config file
  61. - +CONFIG_DIR+: the directory containing the .config file, and
  62. therefore the top-level Buildroot Makefile to use (which is
  63. correct for both in-tree and out-of-tree builds)
  64. - +HOST_DIR+, +STAGING_DIR+, +TARGET_DIR+: see
  65. xref:generic-package-reference[]
  66. - +BUILD_DIR+: the directory where packages are extracted and built
  67. - +BINARIES_DIR+: the place where all binary files (aka images) are
  68. stored
  69. - +BASE_DIR+: the base output directory
  70. - +PARALLEL_JOBS+: the number of jobs to use when running parallel processes.
  71. Below three more methods of customizing the target filesystem are
  72. described, but they are not recommended.
  73. Direct modification of the target filesystem::
  74. +
  75. For temporary modifications, you can modify the target filesystem
  76. directly and rebuild the image. The target filesystem is available
  77. under +output/target/+. After making your changes, run +make+ to
  78. rebuild the target filesystem image.
  79. +
  80. This method allows you to do anything to the target filesystem, but if
  81. you need to clean your Buildroot tree using +make clean+, these
  82. changes will be lost. Such cleaning is necessary in several cases,
  83. refer to xref:full-rebuild[] for details. This solution is therefore
  84. only useful for quick tests: _changes do not survive the +make clean+
  85. command_. Once you have validated your changes, you should make sure
  86. that they will persist after a +make clean+, using a root filesystem
  87. overlay or a post-build script.
  88. Custom target skeleton (+BR2_ROOTFS_SKELETON_CUSTOM+)::
  89. +
  90. The root filesystem image is created from a target skeleton, on top of
  91. which all packages install their files. The skeleton is copied to the
  92. target directory +output/target+ before any package is built and
  93. installed. The default target skeleton provides the standard Unix
  94. filesystem layout and some basic init scripts and configuration files.
  95. +
  96. If the default skeleton (available under +system/skeleton+) does not
  97. match your needs, you would typically use a root filesystem overlay or
  98. post-build script to adapt it. However, if the default skeleton is
  99. entirely different than what you need, using a custom skeleton may be
  100. more suitable.
  101. +
  102. To enable this feature, enable config option
  103. +BR2_ROOTFS_SKELETON_CUSTOM+ and set +BR2_ROOTFS_SKELETON_CUSTOM_PATH+
  104. to the path of your custom skeleton. Both options are available in the
  105. +System configuration+ menu. If you specify a relative path, it will
  106. be relative to the root of the Buildroot tree.
  107. +
  108. Custom skeletons don't need to contain the '/bin', '/lib' or '/sbin'
  109. directories, since they are created automatically during the build.
  110. When +BR2_ROOTFS_MERGED_USR+ is enabled, then the custom skeleton must
  111. not contain the '/bin', '/lib' or '/sbin' directories, as Buildroot
  112. will create them as symbolic links to the relevant folders in '/usr'.
  113. In such a situation, should the skeleton have any programs or
  114. libraries, they should be placed in '/usr/bin', '/usr/sbin' and
  115. '/usr/lib'.
  116. +
  117. This method is not recommended because it duplicates the entire
  118. skeleton, which prevents taking advantage of the fixes or improvements
  119. brought to the default skeleton in later Buildroot releases.
  120. Post-fakeroot scripts (+BR2_ROOTFS_POST_FAKEROOT_SCRIPT+)::
  121. +
  122. When aggregating the final images, some parts of the process requires
  123. root rights: creating device nodes in `/dev`, setting permissions or
  124. ownership to files and directories... To avoid requiring actual root
  125. rights, Buildroot uses +fakeroot+ to simulate root rights. This is not
  126. a complete substitute for actually being root, but is enough for what
  127. Buildroot needs.
  128. +
  129. Post-fakeroot scripts are shell scripts that are called at the 'end' of
  130. the fakeroot phase, 'right before' the filesystem image generator is
  131. called. As such, they are called in the fakeroot context.
  132. +
  133. Post-fakeroot scripts can be useful in case you need to tweak the
  134. filesystem to do modifications that are usually only available to the
  135. root user.
  136. +
  137. .Note:
  138. It is recommended to use the existing mechanisms to set file permissions
  139. or create entries in `/dev` (see xref:customize-device-permission[]) or
  140. to create users (see xref:customize-users[])
  141. +
  142. .Note:
  143. The difference between post-build scripts (above) and fakeroot scripts,
  144. is that post-build scripts are not called in the fakeroot context.
  145. +
  146. .Note:
  147. Using `fakeroot` is not an absolute substitute for actually being root.
  148. `fakeroot` only ever fakes the file access rights and types (regular,
  149. block-or-char device...) and uid/gid; these are emulated in-memory.
  150. include::customize-device-permission-tables.adoc[]