Run Commands only on first boot in Yocto

If you have a requirement of executing a particular command only when the system is booting first time, you can use 'pkg_postinst_ontarget_${PN} ()' function and add your commands in this. This will create a script file with the commands you given in the above function and that script will be executed by init subsystem and after execution, script will be deleted.

I have used this to provide POSIX capabilities to my particular binary.

To add POSIX Capabilities, I added the following in my recipe:

RDEPENDS_${PN} = "libcap libcap-bin"

pkg_postinst_ontarget_${PN}() {
setcap cap_dac_override,cap_sys_admin,cap_sys_boot,cap_fowner+ep $D/${bindir}/<mybinary>
}


The above changes will make the init system to execute the setcap command only once.

Comments

Post a Comment

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig