I need some help with a Yocto project. I want to back up the /etc directory from the compiled rootfs, compress it into a .tgz file, and store it back in the recovery folder within the rootfs.
Currently, I have written an etc-image.bb file
DESCRIPTION = "Create a tarball of the /etc directory"
LICENSE = "CLOSED"
tarball_name="${IMAGE_NAME}-etc"
BACKUP_PATH ?= "/recovery"
FILES_${PN} += "${BACKUP_PATH}"
do_fetch[noexec] = "1"
do_configure[noexec] = "1"
do_install () {
echo "Running do_image_etc..."
core_image_rootfs="${TMPDIR}/work/${MACHINE_ARCH}-poky-linux/core-image-minimal/1.0-r0/rootfs"
etc_dir="${core_image_rootfs}/etc"
if [ ! -d "${etc_dir}" ]; then
echo "ERROR: /etc directory does not exist in rootfs."
exit 1
fi
mkdir -p ${WORKDIR}/${tarball_name}
echo "Copying /etc content..."
cp -a ${etc_dir}/* ${WORKDIR}/${tarball_name}/ || {
echo "ERROR: Failed to copy /etc content."
exit 1
}
echo "Creating etc tarball..."
tar -zcvf ${WORKDIR}/${tarball_name}.tgz -C ${WORKDIR}/${tarball_name} . || {
echo "ERROR: Failed to create tar file."
exit 1
}
echo "Tarball created successfully."
ln -sf ${tarball_name}.tgz ${WORKDIR}/etc_backup.tgz || {
echo "ERROR: Failed to create symbolic link."
exit 1
}
echo "Symbolic link created: etc_backup.tgz -> ${tarball_name}.tgz"
install -d ${D}${BACKUP_PATH}
install -m 644 ${WORKDIR}/${tarball_name}.tgz ${D}${BACKUP_PATH} || {
echo "ERROR: Failed to install tarball."
exit 1
}
install -m 644 ${WORKDIR}/etc_backup.tgz ${D}${BACKUP_PATH} || {
echo "ERROR: Failed to install symbolic link."
exit 1
}
echo "Installation completed successfully."
}
and declared it in the core-image-minimal.bb file as follows:
IMAGE_INSTALL_append = ”
etc-image
“
However, when I run bitbake core-image-minimal, it fails because the
ERROR: /var directory does not exist in rootfs.
I suspect that I need to ensure etc-image runs after the rootfs is built but before the image is packaged. How can I modify my setup to achieve this?
Thanks in advance for your help!