customize-rootfs.txt 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. - +BR2_CONFIG+: the path to the Buildroot .config file
  37. - +HOST_DIR+, +STAGING_DIR+, +TARGET_DIR+: see
  38. xref:generic-package-reference[]
  39. - +BUILD_DIR+: the directory where packages are extracted and built
  40. - +BINARIES_DIR+: the place where all binary files (aka images) are
  41. stored
  42. - +BASE_DIR+: the base output directory
  43. * Create your own 'target skeleton'. You can start with the default
  44. skeleton available under +system/skeleton+ and then customize it to
  45. suit your needs. The +BR2_ROOTFS_SKELETON_CUSTOM+ and
  46. +BR2_ROOTFS_SKELETON_CUSTOM_PATH+ will allow you to specify the
  47. location of your custom skeleton. These options can be found in the
  48. +System configuration+ menu. At build time, the contents of the
  49. skeleton are copied to output/target before any package
  50. installation. Note that this method is *not recommended*, as it
  51. duplicates the entire skeleton, which prevents from taking advantage
  52. of the fixes or improvements brought to the default Buildroot
  53. skeleton. The recommended method is to use the _post-build scripts_
  54. mechanism described in the previous item.
  55. Note also that you can use the *post-image scripts*
  56. if you want to perform some specific actions 'after' all
  57. filesystem images have been created (for example to automatically
  58. extract your root filesystem tarball in a location exported by your
  59. NFS server, or to create a special firmware image that bundles your
  60. root filesystem and kernel image, or any other custom action), you can
  61. specify a space-separated list of scripts in the
  62. +BR2_ROOTFS_POST_IMAGE_SCRIPT+ configuration option. This option can be
  63. found in the +System configuration+ menu as well.
  64. Each of those scripts will be called with the path to the +images+
  65. output directory as first argument, and will be executed with the main
  66. Buildroot source directory as the current directory. Those scripts will
  67. be executed as the user that executes Buildroot, which should normally
  68. not be the root user. Therefore, any action requiring root permissions
  69. in one of these _post-image scripts_ will require special handling
  70. (usage of fakeroot or sudo), which is left to the script developer.
  71. Just like for the _post-build scripts_ mentioned above, you also have
  72. access to the following environment variables from your _post-image
  73. scripts_: +BR2_CONFIG+, +BUILD_DIR+, +HOST_DIR+, +STAGING_DIR+,
  74. +TARGET_DIR+, +BINARIES_DIR+ and +BASE_DIR+.
  75. Additionally, each of the +BR2_ROOTFS_POST_BUILD_SCRIPT+ and
  76. +BR2_ROOTFS_POST_IMAGE_SCRIPT+ scripts will be passed the arguments
  77. specified in +BR2_ROOTFS_POST_SCRIPT_ARGS+ (if that is not empty).
  78. All the scripts will be passed the exact same set of arguments, it
  79. is not possible to pass different sets of arguments to each script.