Should I move my service file to persistent data. Once I make my rootfs read only

Hello,

To give a brief context of my issue. I wanted to enable local autologin in my raspberry-pi cm3.
In order to do that I had created a recipe which basically disable serial getty service and link my own service with tty1.

Once I make my Image rootfs as read-only I am unable to do that.
My question is,
Did anyone else face similar issue? How do I get over it?
Should I move my service file to persistent data location ?

Here is my recipe

DESCRIPITION = "Auto login Service"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI+= "\
	file://autologin.service \
	"
inherit systemd
S = "${WORKDIR}"

do_install () {
	install -d ${D}${sysconfdir}/systemd/system
	install -m 0644 ${WORKDIR}/autologin.service ${D}${sysconfdir}/systemd/system
}


pkg_postinst_ontarget_${PN} (){
	ln -s /etc/systemd/system/autologin.service /etc/systemd/system/getty.target.wants/getty@tty1.service
	systemctl disable serial-getty@.service
}

This error is because you are using an ontarget function to do it. You want to use SYSTEM_AUTO_ENABLE and SYSTEMD_SERVICE stuff instead to make sure it is setup at bitbake time. You can see how we do it for the mender client recipe here.

Drew

1 Like

Just removing the _ontarget should be enough:

pkg_postinst_${PN} (){
	ln -s /etc/systemd/system/autologin.service /etc/systemd/system/getty.target.wants/getty@tty1.service
	systemctl disable serial-getty@.service
}
1 Like

@mirzak I tried doing that but now I keep getting permission denied.

You shouldn’t need to manually make the symlink on the target. It should be happening when bitbake is run.

Drew

@drewmoseley okay. Please bear with me. So what you are saying is that it should be happening during the install phase and not during the package phase.

Is that right?

Yeah. It should be something like this:

pkg_postinst_${PN}() {
#!/bin/sh
if [ x"$D" != "x" ]; then # This guard is needed for it not to run on first boot
   ln -s /etc/systemd/system/autologin.service ${D}/etc/systemd/system/getty.target.wants/getty@tty1.service
   systemctl --root=${D} disable serial-getty@.service
fi
}

I believe that is the case.

1 Like

Yes, That worked

Yesterday I found out that even though I do this. The service is not getting disable.
I still see a serial-getty@ttyAMA0.service

I guess you need to do

systemctl disable serial-getty@ttyAMA0.service

Since the original command used --root=${D} I assume that is running in the yocto build. If so then you need that here as well.
Drew

I think I have done that. I will try that again. I have been trying various permutation and combination yesterday. I am starting over again today.

my apologies. But what do you mean by that?
Right now. I have a separate recipe called autologin which gets called in my local.conf

“running in the yocto build” as opposed to running the command on the target after it is booted.
Drew

so right now my recipe uses pkg_postinst_${PN}() And the if condition should make it run on the host

Edit: Corrected my comment. Added more info

That solved the issue that I was facing.
Thank you

Great.

I think postinst tasks will run on the build system during the bitbake run if they can. If they return an error, then I think they will run on first boot which obviously won’t work with a read-only root filesystem. Sounds like you have it being done at bitbake time.

Drew

I think that sums up all the issues that I am facing. Because some of my recipes ran commands on target which now is impossible to do on a read only file system.