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

**URL:** <https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292>\
**Category:** General Discussions\
**Tags:** yocto, raspberry-pi-3, warrior\
**Created:** [August 6, 2020, 6:55pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292 "2020-08-06T18:55:15Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 6, 2020, 6:55pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/1 "2020-08-06T18:55:15Z")

</div>

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
}
```

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [August 6, 2020, 10:54pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/2 "2020-08-06T22:54:12Z")

</div>

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.](https://github.com/mendersoftware/meta-mender/blob/master/meta-mender-core/recipes-mender/mender-client/mender-client.inc)

Drew

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [August 7, 2020, 6:24am UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/3 "2020-08-07T06:24:22Z")

</div>

Just removing the `_ontarget` should be enough:

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

```

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 10, 2020, 5:59pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/4 "2020-08-10T17:59:46Z")

</div>

> [@mirzak](#):
>
> `	ln -s /etc/systemd/system/autologin.service /etc/systemd/system/getty.target.wants/getty@tty1.service`

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

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [August 10, 2020, 6:24pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/5 "2020-08-10T18:24:43Z")

</div>

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

Drew

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 10, 2020, 6:39pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/6 "2020-08-10T18:39:56Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [August 10, 2020, 7:02pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/7 "2020-08-10T19:02:54Z")

</div>

> [@thesillywhat](#):
>
> @mirzak I tried doing that but now I keep getting permission denied.

Yeah. It should be something like this:

```auto
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
}

```

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [August 10, 2020, 7:07pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/8 "2020-08-10T19:07:14Z")

</div>

I believe that is the case.

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 10, 2020, 8:14pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/9 "2020-08-10T20:14:41Z")

</div>

Yes, That worked

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 14, 2020, 1:49pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/10 "2020-08-14T13:49:41Z")

</div>

> [@mirzak](#):
>
> `systemctl --root=${D} disable serial-getty@.service`

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

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [August 14, 2020, 2:59pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/11 "2020-08-14T14:59:26Z")

</div>

I guess you need to do

```auto
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

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 14, 2020, 3:09pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/12 "2020-08-14T15:09:32Z")

</div>

> [@drewmoseley](#):
>
> `systemctl disable serial-getty@ttyAMA0.service`

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.

> [@drewmoseley](#):
>
> running in the yocto build

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`

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [August 14, 2020, 3:27pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/13 "2020-08-14T15:27:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 14, 2020, 3:30pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/14 "2020-08-14T15:30:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 14, 2020, 5:52pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/15 "2020-08-14T17:52:14Z")

</div>

> [@drewmoseley](#):
>
> `systemctl disable serial-getty@ttyAMA0.service`

That solved the issue that I was facing.  
Thank you

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [August 14, 2020, 6:08pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/16 "2020-08-14T18:08:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![thesillywhat](https://avatars.discourse-cdn.com/v4/letter/t/57b2e6/32.png) [@thesillywhat](https://hub.mender.io/u/thesillywhat)\
**Post date:** [August 14, 2020, 6:12pm UTC](https://hub.mender.io/t/should-i-move-my-service-file-to-persistent-data-once-i-make-my-rootfs-read-only/2292/17 "2020-08-14T18:12:11Z")

</div>

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.
