customize-rootfs.txt 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // -*- mode:doc; -*-
  2. // vim: set syntax=asciidoc:
  3. [[rootfs-custom]]
  4. Customizing the generated target filesystem
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. Besides changing one or another configuration through +make *config+,
  7. there are a few ways to customize the resulting target filesystem.
  8. * Customize the target filesystem directly and rebuild the image. The
  9. target filesystem is available under +output/target/+. You can
  10. simply make your changes here and run make afterwards - this will
  11. rebuild the target filesystem image. This method allows you to do
  12. anything to the target filesystem, but if you decide to completely
  13. rebuild your toolchain and tools, these changes will be lost. This
  14. solution is therefore only useful for quick tests only: _changes do
  15. not survive the +make clean+ command_. Once you have validated your
  16. changes, you should make sure that they will persist after a +make
  17. clean+ by using one of the following methods.
  18. * Create a filesystem overlay: a tree of files that are copied directly
  19. over the target filesystem after it has been built. Set
  20. +BR2_ROOTFS_OVERLAY+ to the top of the tree. +.git+, +.svn+, +.hg+
  21. directories, +.empty+ files and files ending with +~+ are excluded.
  22. _Among these first 3 methods, this one should be preferred_.
  23. * In the Buildroot configuration, you can specify the paths to one or
  24. more *post-build scripts*. These scripts are called in the given order,
  25. 'after' Buildroot builds all the selected software, but 'before' the
  26. rootfs images are assembled. The +BR2_ROOTFS_POST_BUILD_SCRIPT+ allows
  27. you to specify the location of your post-build scripts. This option can be
  28. found in the +System configuration+ menu. The destination root
  29. filesystem folder is given as the first argument to these scripts,
  30. and these scripts can then be used to remove or modify any file in your
  31. target filesystem. You should, however, use this feature with care.
  32. Whenever you find that a certain package generates wrong or unneeded
  33. files, you should fix that package rather than work around it with some
  34. post-build cleanup scripts.
  35. You may also use these variables in your post-build script:
  36. - +BUILDROOT_CONFIG+: the path to the Buildroot .config file
  37. - +HOST_DIR+, +STAGING_DIR+, +TARGET_DIR+: see
  38. xref:generic-package-reference[]
  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_: +BUILDROOT_CONFIG+, +HOST_DIR+, +STAGING_DIR+, +TARGET_DIR+,
  73. +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.