0

This question is different from the possible candidate since here I am asking how to remove the service at startup

I am using a Seeed ReSpeaker Core v2.0 board. I would like to use the UART interface to make this board communicate with another one. But the UART port /dev/ttyS2 is linked to the console. I have identified a service linked to the board and I would like to disable it in order to prevent it from starting at boot:

userk@glutamate:~$ sudo systemctl status | grep ttyS2
           │ │ ├─serial-getty@ttyS2.service
           │ │ │ └─1078 /sbin/agetty --keep-baud 115200,38400,9600 ttyS2 vt220
               │ ├─1093 grep ttyS2

There is no information related to the bootloader on the official page. I already asked a question on their forum.

EDIT 0

the service is statically enabled

userk@glutamate:~$ systemctl list-dependencies --reverse serial-getty@ttyS2
serial-getty@ttyS2.service
● └─getty.target
●   └─multi-user.target
●     └─graphical.target

When I stop and disable it, the situation seems fine:

userk@glutamate:~$ sudo systemctl stop serial-getty@ttyS2.service 
userk@glutamate:~$ sudo systemctl disable serial-getty@ttyS2.service 
userk@glutamate:~$ sudo systemctl status | grep ttyS2
               │ ├─1135 grep ttyS2

But when I reboot the system, it appears again.

EDIT 1

  • I am working with Debian 9 (stretch). I used an image made by SeedStudio.
  • I asked another question related to this service here. As @JdeBP stated in his answer

The fundamental configuration item that drives this is the console setting that one gives on the command line to the kernel via the boot loader. It's that that tells the generator what serial console services to start. It is that that tells the kernel where to send kernel console output. It is that that tells the kernel where to send /dev/console output. If you do not want your serial device to be a console, it is that that you need to adjust.

EDIT 2

I cannot find the serial-getty@ttyS2.service in /lib/systemd/system folder. I am using grep -rl serial-getty@ttyS2.service /lib/systemd/system.

sourcejedi
  • 50,249
UserK
  • 2,424
  • Thanks, I am working with debian 9, and apparently the service is statically enabled. The output of the command is in the EDIT section of the question – UserK Nov 06 '18 at 14:33
  • 2
    In https://unix.stackexchange.com/a/475043/5132 I mentioned the console setting. This question could be improved by telling answerers what that setting now is. – JdeBP Nov 06 '18 at 14:48
  • 1
    If you are not sure what bootloader the board uses and how to configure it, you can start by ruling this in or out by checking cat /proc/cmdline, i.e. seeing if it contains console=ttyS2 – sourcejedi Nov 06 '18 at 15:09
  • Yes @sourcejedi the file contains console=ttyS2,115200n8 rw coherent_pool=1M quiet init=/lib/systemd/systemd root=PARTUUID=0fb4d56f-02 rootfstype=ext4 earlycon=uart8250,mmio32,0x11030000 – UserK Nov 06 '18 at 15:19
  • 3
  • 1
    @UserK then you are asking about how to change the options passed by the bootloader, but this question has no information about which bootloader software is being used, this question doesn't even tell us what the hardware is so we can guess what the bootloader is :-). I would have taken the original question to imply that you would also want to disable it on startup, since that is what systemctl disable does for most services. – sourcejedi Nov 06 '18 at 16:05
  • I just would like to to disable it on startup. I have tried creating a service that runs the stop and disable commands at startup but it didn't work. I also tried with a bash script placed in /etc/init.d and nothing changed. – UserK Nov 06 '18 at 16:12
  • @UserK If you want to do this without changing the bootloader options, please edit the question to say so (and also say something about why you have such an unusual requirement). – sourcejedi Nov 06 '18 at 16:14
  • 1
    it is possible - "A symlink to /dev/null or an empty file can be used to mask a generator, thereby preventing it from running." - so you can mask systemd-getty-generator – sourcejedi Nov 06 '18 at 16:17
  • the linked question says "Is it possible to completely remove the serial console linked to ttyS2? And if yes, how do I set this "rule" at the startup?". I don't read that as asking how to remove it temporarily for the current boot, if you want it to be that then it needs editing... – sourcejedi Nov 06 '18 at 16:18
  • Could you please explain how to mask systemd-getty-generator. It sounds like a solution to me – UserK Nov 06 '18 at 16:42
  • Searching the phrase in quotes will find the reference documentation. I agree your system documentation does not appear to show the bootloader... you also don't get any bootloader hint (e.g. "press a key within 2 seconds to get a prompt") on the UART. Thank you. You will also have to avoid interpreting all the kernel messages, that this board will send on the UART during boot (and disable kernel messages before you start communicating - run dmesg --console-off). Let me know if you think you can do that. – sourcejedi Nov 06 '18 at 18:28
  • Your command under EDIT2 may not give the results you seem to expect. grep -rl something.service /some/directory will show you files containing the text "something.service", it won't match on filenames themselves. – JigglyNaga Nov 08 '18 at 13:20

2 Answers2

3

Following EDIT2, this answer is obsolete.


Note that you're not supposed to write configuration like that to /lib/. I hope you (or another admin) simply created it there by mistake, and there is not a more complex problem. In that case you can just revert it, i.e.

rm /lib/systemd/system/getty.target.wants/serial-getty@ttyS2.service

Then you can reboot. (Or run systemctl daemon-reload, and check again to see that the service has been disabled properly).

Before deleting the file, I might double-check that the unwanted link is not provided by a package

dpkg-query -S /lib/systemd/system/getty.target.wants/serial-getty@ttyS2.service

and that it is indeed a symlink

ls -l /lib/systemd/system/getty.target.wants/serial-getty@ttyS2.service

You can also check for other files which were placed inappropriately by an admin. Install the Debian package cruft, and run cruft -d "/lib/systemd/system".

sourcejedi
  • 50,249
  • I am sorry @sourcejedi but I was wrong about the symlink. As I wrote in the EDIT2 section, I cannot find any serial-getty@ttyS2.service in /lib/systemd/system folder. – UserK Nov 06 '18 at 15:06
  • I upvoted your answer for the content you have provided – UserK Nov 06 '18 at 15:34
1

0. about serial-getty@ttyS0.service

$ sudo systemctl status serial-getty@ttyS0.service 
● serial-getty@ttyS0.service - Serial Getty on ttyS0
     Loaded: loaded (/lib/systemd/system/serial-getty@.service; enabled-runtime; vendor preset: enabled)
     Active: active (running) since Wed 2022-06-08 02:20:07 CST; 2min 7s ago
       Docs: man:agetty(8)
             man:systemd-getty-generator(8)
             http://0pointer.de/blog/projects/serial-console.html
   Main PID: 420 (agetty)
      Tasks: 1 (limit: 4336)
        CPU: 12ms
     CGroup: /system.slice/system-serial\x2dgetty.slice/serial-getty@ttyS0.service
             └─420 /sbin/agetty -o -p -- \u --keep-baud 115200,57600,38400,9600 ttyS0 vt220

1. about systemd-getty-generator

man systemd-getty-generator
https://man.archlinux.org/man/systemd-getty-generator.8.en

This stuff parse console= from /proc/cmdline, and
 generator (and enable) serial-getty@ instance serial-getty@ttyS0.service
at each system boot.


2. stop haunted

A. disable systemd-getty-generator

sudo chmod -x /lib/systemd/system-generators/systemd-getty-generator

to stop this haunted stuff



OR

B. change kernel cmdline in bootloader

remove console=ttyS0 stuff

cat /proc/cmdline to verify

yurenchen
  • 266