customize-rootfs.txt 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // -*- mode:doc; -*-
  2. // vim: set syntax=asciidoc:
  3. [[rootfs-custom]]
  4. === Customizing the generated target filesystem
  5. Besides changing one or another configuration through +make *config+,
  6. there are a few ways to customize the resulting target filesystem.
  7. * Customize the target filesystem directly and rebuild the image. The
  8. target filesystem is available under +output/target/+. You can
  9. simply make your changes here and run make afterwards - this will
  10. rebuild the target filesystem image. This method allows you to do
  11. anything to the target filesystem, but if you decide to completely
  12. rebuild your toolchain and tools, these changes will be lost. This
  13. solution is therefore only useful for quick tests only: _changes do
  14. not survive the +make clean+ command_. Once you have validated your
  15. changes, you should make sure that they will persist after a +make
  16. clean+ by using one of the following methods.
  17. * Create a filesystem overlay: a tree of files that are copied directly
  18. over the target filesystem after it has been built. Set
  19. +BR2_ROOTFS_OVERLAY+ to the top of the tree. +.git+, +.svn+, +.hg+
  20. directories, +.empty+ files and files ending with +~+ are excluded.
  21. _Among these first 3 methods, this one should be preferred_.
  22. * In the Buildroot configuration, you can specify the paths to one or
  23. more *post-build scripts*. These scripts are called in the given order,
  24. 'after' Buildroot builds all the selected software, but 'before' the
  25. rootfs images are assembled. The +BR2_ROOTFS_POST_BUILD_SCRIPT+ allows
  26. you to specify the location of your post-build scripts. This option can be
  27. found in the +System configuration+ menu. The destination root
  28. filesystem folder is given as the first argument to these scripts,
  29. and these scripts can then be used to 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. You may also use these variables in your post-build script:
  35. - +BR2_CONFIG+: the path to the Buildroot .config file
  36. - +HOST_DIR+, +STAGING_DIR+, +TARGET_DIR+: see
  37. xref:generic-package-reference[]
  38. - +BUILD_DIR+: the directory where packages are extracted and built
  39. - +BINARIES_DIR+: the place where all binary files (aka images) are
  40. stored
  41. - +BASE_DIR+: the base output directory
  42. * Create your own 'target skeleton'. You can start with the default
  43. skeleton available under +system/skeleton+ and then customize it to
  44. suit your needs. The +BR2_ROOTFS_SKELETON_CUSTOM+ and
  45. +BR2_ROOTFS_SKELETON_CUSTOM_PATH+ will allow you to specify the
  46. location of your custom skeleton. These options can be found in the
  47. +System configuration+ menu. At build time, the contents of the
  48. skeleton are copied to output/target before any package
  49. installation. Note that this method is *not recommended*, as it
  50. duplicates the entire skeleton, which prevents from taking advantage
  51. of the fixes or improvements brought to the default Buildroot
  52. skeleton. The recommended method is to use the _post-build scripts_
  53. mechanism described in the previous item.
  54. Note also that you can use the *post-image scripts*
  55. if you want to perform some specific actions 'after' all
  56. filesystem images have been created (for example to automatically
  57. extract your root filesystem tarball in a location exported by your
  58. NFS server, or to create a special firmware image that bundles your
  59. root filesystem and kernel image, or any other custom action), you can
  60. specify a space-separated list of scripts in the
  61. +BR2_ROOTFS_POST_IMAGE_SCRIPT+ configuration option. This option can be
  62. found in the +System configuration+ menu as well.
  63. Each of those scripts will be called with the path to the +images+
  64. output directory as first argument, and will be executed with the main
  65. Buildroot source directory as the current directory. Those scripts will
  66. be executed as the user that executes Buildroot, which should normally
  67. not be the root user. Therefore, any action requiring root permissions
  68. in one of these _post-image scripts_ will require special handling
  69. (usage of fakeroot or sudo), which is left to the script developer.
  70. Just like for the _post-build scripts_ mentioned above, you also have
  71. access to the following environment variables from your _post-image
  72. scripts_: +BR2_CONFIG+, +BUILD_DIR+, +HOST_DIR+, +STAGING_DIR+,
  73. +TARGET_DIR+, +BINARIES_DIR+ and +BASE_DIR+.
  74. Additionally, each of the +BR2_ROOTFS_POST_BUILD_SCRIPT+ and
  75. +BR2_ROOTFS_POST_IMAGE_SCRIPT+ scripts will be passed the arguments
  76. specified in +BR2_ROOTFS_POST_SCRIPT_ARGS+ (if that is not empty).
  77. All the scripts will be passed the exact same set of arguments, it
  78. is not possible to pass different sets of arguments to each script.