Managing rootfs at build time

How to write script that will remove, move and add some files?

I know about build_dir/target-mips_24kc_musl/root-ar71xx. So for now i build original openwrt, then modify root dir and repack again.

How to set install order to first / last to package?

Another issue: cant create /init . ie i created (via openwrt/files and pkg makefile) it but it removed in result rootfs.

https://openwrt.org/docs/guide-developer/build-system/use-buildsystem#custom_files should handle most use cases.

I don't know that you can set order of packages in a build. Since you can't have one package overwrite another (as far as I know), I'm not sure how ordering would help. What are you trying to achieve?

1 Like

I want to remove not needed files from some packages. For example remove /etc/chilli/www, remove init some scripts.

I would branch and patch the package(s) you wish to modify

It's not what I wanted.

https://www.gnu.org/software/make/manual/html_node/index.html


Should anyone else come across this thread in the future, the OP's objectives are likely easily and robustly met through modification of the package(s) in question, rather than post-processing an already assembled image.

As a specific example

is easily accomplished through the Makefile for the package, a can be seen below.

define Package/coova-chilli/conffiles
/etc/config/chilli
endef

define Package/coova-chilli/install
        $(INSTALL_DIR) $(1)/etc
        $(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/chilli.conf $(1)/etc/
        $(INSTALL_DIR) $(1)/etc/chilli
        $(CP) $(PKG_INSTALL_DIR)/etc/chilli/* $(1)/etc/chilli/
        $(INSTALL_DIR) $(1)/etc/hotplug.d/iface
        $(INSTALL_DATA) ./files/chilli.hotplug $(1)/etc/hotplug.d/iface/30-chilli
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/chilli* $(1)/usr/sbin/
        $(INSTALL_DIR) $(1)/usr/lib/
        $(CP) $(PKG_INSTALL_DIR)/usr/lib/lib*.so.* $(1)/usr/lib/
        $(if $(CONFIG_PACKAGE_kmod-ipt-coova), \
                $(INSTALL_DIR) $(1)/usr/lib/iptables; \
                $(CP) $(PKG_INSTALL_DIR)/usr/lib/iptables/lib*.so $(1)/usr/lib/iptables/ \
        )
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) files/chilli.init $(1)/etc/init.d/chilli
        $(INSTALL_DIR) $(1)/etc/config
        $(INSTALL_DATA) files/chilli.config $(1)/etc/config/chilli
        $(INSTALL_DIR) $(1)/lib/firewall
        $(CP) files/chilli.firewall $(1)/lib/firewall/chilli.sh
endef

I know how to modify packages. I want full control on rootfs.

Another issue: cant create /init. ie i created it but it removed in result rootfs.

[path/to]/openwrt$ fgrep -r init include/
include/kernel-defaults.mk:INITRAMFS_EXTRA_FILES ?= $(GENERIC_PLATFORM_DIR)/image/initramfs-base-files.txt
include/kernel-defaults.mk:	rm -f $(TARGET_DIR)/init
include/kernel-defaults.mk:	$(CP) $(GENERIC_PLATFORM_DIR)/other-files/init $(TARGET_DIR)/init
include/kernel-defaults.mk:	rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
include/kernel-defaults.mk:	$(call Kernel/CopyImage,-initramfs)
[...]