customize-rootfs.txt 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. As shown in xref:customize-dir-structure[], the recommended path for
  22. this overlay is +board/<company>/<boardname>/rootfs-overlay+.
  23. Post-build scripts (+BR2_ROOTFS_POST_BUILD_SCRIPT+)::
  24. +
  25. Post-build scripts are shell scripts called 'after' Buildroot builds
  26. all the selected software, but 'before' the rootfs images are
  27. assembled. To enable this feature, specify a space-separated list of
  28. post-build scripts in config option +BR2_ROOTFS_POST_BUILD_SCRIPT+ (in
  29. the +System configuration+ menu). If you specify a relative path, it
  30. will be relative to the root of the Buildroot tree.
  31. +
  32. Using post-build scripts, you can remove or modify any file in your
  33. target filesystem. You should, however, use this feature with care.
  34. Whenever you find that a certain package generates wrong or unneeded
  35. files, you should fix that package rather than work around it with some
  36. post-build cleanup scripts.
  37. +
  38. As shown in xref:customize-dir-structure[], the recommended path for
  39. this script is +board/<company>/<boardname>/post_build.sh+.
  40. +
  41. The post-build scripts are run with the main Buildroot tree as current
  42. working directory. The path to the target filesystem is passed as the
  43. first argument to each script. If the config option
  44. +BR2_ROOTFS_POST_SCRIPT_ARGS+ is not empty, these arguments will be
  45. passed to the script too. All the scripts will be passed the exact
  46. same set of arguments, it is not possible to pass different sets of
  47. arguments to each script.
  48. +
  49. In addition, you may also use these environment variables:
  50. - +BR2_CONFIG+: the path to the Buildroot .config file
  51. - +HOST_DIR+, +STAGING_DIR+, +TARGET_DIR+: see
  52. xref:generic-package-reference[]
  53. - +BUILD_DIR+: the directory where packages are extracted and built
  54. - +BINARIES_DIR+: the place where all binary files (aka images) are
  55. stored
  56. - +BASE_DIR+: the base output directory
  57. Below three more methods of customizing the target filesystem are
  58. described, but they are not recommended.
  59. Direct modification of the target filesystem::
  60. +
  61. For temporary modifications, you can modify the target filesystem
  62. directly and rebuild the image. The target filesystem is available
  63. under +output/target/+. After making your changes, run +make+ to
  64. rebuild the target filesystem image.
  65. +
  66. This method allows you to do anything to the target filesystem, but if
  67. you need to clean your Buildroot tree using +make clean+, these
  68. changes will be lost. Such cleaning is necessary in several cases,
  69. refer to xref:full-rebuild[] for details. This solution is therefore
  70. only useful for quick tests: _changes do not survive the +make clean+
  71. command_. Once you have validated your changes, you should make sure
  72. that they will persist after a +make clean+, using a root filesystem
  73. overlay or a post-build script.
  74. Custom target skeleton (+BR2_ROOTFS_SKELETON_CUSTOM+)::
  75. +
  76. The root filesystem image is created from a target skeleton, on top of
  77. which all packages install their files. The skeleton is copied to the
  78. target directory +output/target+ before any package is built and
  79. installed. The default target skeleton provides the standard Unix
  80. filesystem layout and some basic init scripts and configuration files.
  81. +
  82. If the default skeleton (available under +system/skeleton+) does not
  83. match your needs, you would typically use a root filesystem overlay or
  84. post-build script to adapt it. However, if the default skeleton is
  85. entirely different than what you need, using a custom skeleton may be
  86. more suitable.
  87. +
  88. To enable this feature, enable config option
  89. +BR2_ROOTFS_SKELETON_CUSTOM+ and set +BR2_ROOTFS_SKELETON_CUSTOM_PATH+
  90. to the path of your custom skeleton. Both options are available in the
  91. +System configuration+ menu. If you specify a relative path, it will
  92. be relative to the root of the Buildroot tree.
  93. +
  94. This method is not recommended because it duplicates the entire
  95. skeleton, which prevents taking advantage of the fixes or improvements
  96. brought to the default skeleton in later Buildroot releases.
  97. Post-fakeroot scripts (+BR2_ROOTFS_POST_FAKEROOT_SCRIPT+)::
  98. +
  99. When aggregating the final images, some parts of the process requires
  100. root rights: creating device nodes in `/dev`, setting permissions or
  101. ownership to files and directories... To avoid requiring actual root
  102. rights, Buildroot uses +fakeroot+ to simulate root rights. This is not
  103. a complete substitute for actually being root, but is enough for what
  104. Buildroot needs.
  105. +
  106. Post-fakeroot scripts are shell scripts that are called at the 'end' of
  107. the fakeroot phase, 'right before' the filesystem image generator is
  108. called. As such, they are called in the fakeroot context.
  109. +
  110. Post-fakeroot scripts can be useful in case you need to tweak the
  111. filesystem to do modifications that are usually only available to the
  112. root user.
  113. +
  114. .Note:
  115. It is recommended to use the existing mechanisms to set file permissions
  116. or create entries in `/dev` (see xref:customize-device-permission[]) or
  117. to create users (see xref:customize-users[])
  118. +
  119. .Note:
  120. The difference between post-build scripts (above) and fakeroot scripts,
  121. is that post-build scripts are not called in the fakeroot context.
  122. +
  123. .Note;
  124. Using `fakeroot` is not an absolute substitute for actually being root.
  125. `fakeroot` only ever fakes the file access rights and types (regular,
  126. block-or-char device...) and uid/gid; these are emulated in-memory.
  127. include::customize-device-permission-tables.txt[]