customize-rootfs.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. Post-build scripts (+BR2_ROOTFS_POST_BUILD_SCRIPT+)::
  21. +
  22. Post-build scripts are shell scripts called 'after' Buildroot builds
  23. all the selected software, but 'before' the rootfs images are
  24. assembled. To enable this feature, specify a space-separated list of
  25. post-build scripts in config option +BR2_ROOTFS_POST_BUILD_SCRIPT+ (in
  26. the +System configuration+ menu). If you specify a relative path, it
  27. will be relative to the root of the Buildroot tree.
  28. +
  29. Using post-build scripts, you can remove or modify any file in your
  30. target filesystem. You should, however, use this feature with care.
  31. Whenever you find that a certain package generates wrong or unneeded
  32. files, you should fix that package rather than work around it with some
  33. post-build cleanup scripts.
  34. +
  35. The post-build scripts are run with the main Buildroot tree as current
  36. working directory. The path to the target filesystem is passed as the
  37. first argument to each script. If the config option
  38. +BR2_ROOTFS_POST_SCRIPT_ARGS+ is not empty, these arguments will be
  39. passed to the script too. All the scripts will be passed the exact
  40. same set of arguments, it is not possible to pass different sets of
  41. arguments to each script.
  42. +
  43. In addition, you may also use these environment variables:
  44. - +BR2_CONFIG+: the path to the Buildroot .config file
  45. - +HOST_DIR+, +STAGING_DIR+, +TARGET_DIR+: see
  46. xref:generic-package-reference[]
  47. - +BUILD_DIR+: the directory where packages are extracted and built
  48. - +BINARIES_DIR+: the place where all binary files (aka images) are
  49. stored
  50. - +BASE_DIR+: the base output directory
  51. Below two more methods of customizing the target filesystem are
  52. described, but they are not recommended.
  53. Direct modification of the target filesystem::
  54. +
  55. For temporary modifications, you can modify the target filesystem
  56. directly and rebuild the image. The target filesystem is available
  57. under +output/target/+. After making your changes, run +make+ to
  58. rebuild the target filesystem image.
  59. +
  60. This method allows you to do anything to the target filesystem, but if
  61. you need to clean your Buildroot tree using +make clean+, these
  62. changes will be lost. Such cleaning is necessary in several cases,
  63. refer to xref:full-rebuild[] for details. This solution is therefore
  64. only useful for quick tests: _changes do not survive the +make clean+
  65. command_. Once you have validated your changes, you should make sure
  66. that they will persist after a +make clean+, using a root filesystem
  67. overlay or a post-build script.
  68. Custom target skeleton (+BR2_ROOTFS_SKELETON_CUSTOM+)::
  69. +
  70. The root filesystem image is created from a target skeleton, on top of
  71. which all packages install their files. The skeleton is copied to the
  72. target directory +output/target+ before any package is built and
  73. installed. The default target skeleton provides the standard Unix
  74. filesystem layout and some basic init scripts and configuration files.
  75. +
  76. If the default skeleton (available under +system/skeleton+) does not
  77. match your needs, you would typically use a root filesystem overlay or
  78. post-build script to adapt it. However, if the default skeleton is
  79. entirely different than what you need, using a custom skeleton may be
  80. more suitable.
  81. +
  82. To enable this feature, enable config option
  83. +BR2_ROOTFS_SKELETON_CUSTOM+ and set +BR2_ROOTFS_SKELETON_CUSTOM_PATH+
  84. to the path of your custom skeleton. Both options are available in the
  85. +System configuration+ menu. If you specify a relative path, it will
  86. be relative to the root of the Buildroot tree.
  87. +
  88. This method is not recommended because it duplicates the entire
  89. skeleton, which prevents taking advantage of the fixes or improvements
  90. brought to the default skeleton in later Buildroot releases.