lojoe
lojoe

Reputation: 521

Cannot disable systemd serial-getty service

On Raspberry Pi with Arch Linux there is a service active called serial-getty@AMA0.

The unit file is: /usr/lib/systemd/system/[email protected]

As root I can invoke

systemctl stop serial-getty@ttyAMA0
systemctl disable serial-getty@ttyAMA0

But after reboot the service is enabled and running again.

Why is the service enabled after disabling it? How can I disable it permanent?

UPDATE

systemd uses generators at /usr/lib/systemd/system-generators/ is a binary called systemd-getty-generator. This binary runs at system start and adds the symlink [email protected] to /run/systemd/generator/getty.target.wants.

I eventually found a dirty solution. I commented out all actions in /usr/lib/systemd/system/[email protected]. The service did appear to start anyway, but without blocking ttyAMA0.

Upvotes: 22

Views: 27214

Answers (3)

Franck Barbenoire
Franck Barbenoire

Reputation: 11

I found a way to prevent the kernel from running the generator thus not starting services at all. The following kernel parameter has to be added :

systemd.getty_auto=no

Found this answer here.

As I'm using a Raspberry Pi 4, I added this parameter to the /boot/cmdline.txt file.

Upvotes: 0

m-tech
m-tech

Reputation: 338

Try this code:

system("systemctl stop [email protected]");
system("systemctl disable [email protected]");

I use it, and it works well.

Upvotes: -5

Rob Meades
Rob Meades

Reputation: 466

The correct way to stop a service ever being enabled again is to use:

systemctl mask [email protected]

(using ttyAMA0 as the example in this case). This will add a link to null to the entry for that service.

Upvotes: 45

Related Questions