'YOCTO - Build partial image for application
I want to create a small application image. That image installed at a separate partition shall be mounted to /usr/local. I created a recipe like this:
inherit image
IMAGE_BASENAME = "appfs"
IMAGE_NAME_SUFFIX = ".appfs"
IMAGE_INSTALL_append = " app_lib "
IMAGE_INSTALL_append = " app_prog1 "
IMAGE_INSTALL_append = " app_prog2 "
IMAGE_INSTALL_append = " app_prog3 "
The result looks not bad, I can control the installation of the files by the prefix-Variable in the recipes of the application programms. So the will be installed in /bin, which means /usr/local/bin in the device.
But the image contains the whole directory structure of a root filesystem. Is there any comfortable way to generate the reduced directory structure of the /usr/local directory? Or do I need to clean it up by myself in a IMAGE_POSTPROCESS_COMMAND?
Kind regards
Solution 1:[1]
It sounds like what you want is a package or package group and not an image.
An image is a full distribution installation, usually using the poky distro. This is built-in to yocto and unavoidable, as all dependencies of your app will need to be in the image. (runtimes, supporting libs, basic linux env, etc.)
In your tmp/deploy/rpm
or tmp/deploy/deb
directory you should have packages related to your apps.
Something that may help organize is to create a package group to aggregate your applications.
Solution 2:[2]
If you look at your tmp/deploy/images/<machine>/<imagename>.manifest
file you will notice that in addition to the packages you specified, some additional ones such as libc6
and base-files
are included.
You can remove them by naming the packages in ROOTFS_RO_UNNEEDED
. This variable is used to remove recipes such as shadow
and run-postinsts
which are processed when creating a read-only image. You can add the other undesirable recipes to this list until your manifest matches exactly the packages you want included.
For example:
# tested with Yocto 2.6
IMAGE_FSTYPES = "ext4"
IMAGE_INSTALL = "my-go-app"
inherit image
# Don't run ldconfig on the rootfs
LDCONFIGDEPEND = ""
# If not building an RO filesystem, you can force use of ROOTFS_RO_UNNEEDED
# but be aware of the other packages included in the variable by image.bbclass
FORCE_RO_REMOVE = "1"
# Use _append because image.bbclass includes other packages
ROOTFS_RO_UNNEEDED_append = "base-files base-files-lic \
bash bash-lic \
libc6 libc6-lic \
ncurses-libtinfo libtinfo5 \
opkg-utils-lic \
ncurses-terminfo-base ncurses-lic \
run-postinsts-lic \
"
The resulting filesystem I get looks like this:
tmp
??? etc
? ??? shells.rpmsave
? ??? timestamp
? ??? version
??? lost+found [error opening dir]
??? usr
? ??? bin
? ? ??? my-go-app
? ??? lib
? ? ??? go
? ? ??? pkg
? ? ??? linux_arm64_dynlink
? ? ??? libstd.so
? ??? share
? ??? common-licenses
? ? ??? license.manifest
? ??? licenses
? ??? go-runtime
? ? ??? generic_BSD-3-Clause
? ? ??? LICENSE
? ??? my-go-app
??? var
??? cache
??? lib
There may still be a few files left to clean up using a postprocess function:
postprocess_partial_image() {
rm -f ${IMAGE_ROOTFS}/etc/shells.rpmsave
rm -rf ${IMAGE_ROOTFS}/var
}
ROOTFS_POSTPROCESS_COMMAND += "postprocess_partial_image; "
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mascoj |
Solution 2 | benf |