Wednesday, June 1, 2022

[SOLVED] How to remove getty@tty1 link in yocto dunfell branch at time of compiliation

Issue

I am building linux system for raspberrypi4 but for some reason I need to remove getty@tty1 service in yocto.

I have created systemd_%.bbappend file for that.

Host PC is Ubuntu 18.04

this is working with warrior branch

Now, I am trying to compile with dunfell branch in yocto

but at the time of systemd compiling it gives an error like

"cannot remove /etc/systemd/system/getty.target.wants/getty@tty1, no such file or deirectory

But at the end, In final image there I can see [email protected]

Also I can't find any other receipe that creates this link.

systemd_%.bbappend looks like this

 DESCRIPTION = "Customization of systemD services."

 do_install_append() {

 rm ${D}${sysconfdir}/systemd/system/getty.target.wants/[email protected]

 }

 FILES_${PN} += "${sysconfdir}/systemd/system"

 REQUIRED_DISTRO_FEATURES= "systemd"

Thanks

Margish


Solution

On more recent versions of systemd (like the one in Yocto dunfell), the links to services are not created by the build system (ninja), but instead by running systemctl preset-all on the running system after installation (see here). This command reads the systemd preset files to determine which units to enable or disable by default.

In Yocto, what this means is that instead of the links being created as part of the systemd recipe, systemctl preset-all is run as part of the IMAGE_PREPROCESS_COMMAND during image creation in image.bbclass (see here). This is why the old method of deleting the symbolic links in /etc/systemd/system from the systemd recipe no longer works.

Instead, what you need to do is modify the 90-systemd.preset file to disable the getty@tty1 preset (or any other default system service) by changing the below line:

enable [email protected]

to this:

disable [email protected]

You can accomplish this using a bbappend file as follows*:

# systemd_%.bbappend
do_install_append() {
    # Disable getty@tty1 from starting at boot time.
    sed -i -e "s/enable [email protected]/disable [email protected]/g" ${D}${systemd_unitdir}/system-preset/90-systemd.preset
}

*https://stackoverflow.com/a/67505478/286701



Answered By - Amr Bekhit
Answer Checked By - Dawn Plyler (WPSolving Volunteer)