Problem with serial-getty@ttyAMA0.service on an NTP server

After setting up an NTP server on an RPi 4 using a GPS module (serial), I have the following problem.

Under dietpi-config-4-Serial/UART, ttyAMA0 console and ttyS0 (mini UART) device must be set to ON for the whole thing to work.
So in the cmdline.txt it says console=ttyAMA0,115200.
After a restart, the output under cgps or gpsmon no longer works, as gpsd.service outputs ttyAMA0 is used elsewhere.
I have now found out that it is serial-getty@ttyAMA0.service that is causing the problem.
As a workaround I enter the following commands:

systemctl stop serial-getty@ttyAMA0.service

systemctl disable serial-getty@ttyAMA0.service

The whole system works fine until the next reboot and the game starts all over again.

Now to my actual question:
How can I permanently disable serial-getty@ttyAMA0.service?

Does systemctl mask serial-getty@ttyAMAO.service help?
or adding systemd.getty_auto=no to the cmdline.txt?

Before I try that, I would like to ask here what the best way is.

In various instructions for setting up an NTP server, it is often described to remove the entry console=ttyAMA0,115200 or similar from the cmdline.txt. However, if I do this, the whole thing does not work.

I would be very grateful for any information or tips!

You need to remove the console=ttyAMA0 entry from cmdline.txt, as it triggers a serial-getty as well, and furthermore spams the device with kernel logs. You can do this via dietpi-config advanced options > serial/UART as well, which also disables and masks the serial-getty unit.

In how far does it not work if you remove the console entry? Note there is a difference between disabling the serial console on ttyAMA0 and disabling the whole UART device itself. The UART device must exist, but no serial console/output must be done on it, so the GPS daemon can use it instead.

EDIT: Ah wait, in case of RPi 4, the ttyS0 device is used for GPS, at least when following the instructions and info from this issue: Add tools for easy GPS module configuration (and, ideally, setup with time servers as a timing source) · Issue #6385 · MichaIng/DietPi · GitHub
But it can be consigured either way. Important is that the device used by gpsd is not blocked by console I/O.

Thanks for the advice, but if I do what you say, it stops working.
All the instructions say as they confirm, but what should I do.

If I set the ttyAMA0 console to OFF, the entry in the cmdline.txt is no longer present and the GPS procedure no longer runs on the next restart.

Only when I use exactly the following settings, everything works:

Serial/UART

Toggle console
ttyS0 condole = OFF
ttyAMA0 console = ON

Toggle device
ttyS0 (mini UART) = ON

I’m a little confused about ttyS0 (mini UART), isn’t that the 3-pin connector that is only on the RPi 5?

I then have to stop and deactivate serial-getty@ttyAMA0.service, restart the gpsd.service and then cgps or gpsmon work perfectly.

As you can see, I can only explain everything in very layman’s terms, but it is what it is.

The GPS module used is a Waveshare LC29H(AA) Hat.

Here is some information about the system:

chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
#* PPS0                          0   4   377    24   -531ns[-1840ns] +/-   86ns
#? GPS                           0   4   377    24    +14ms[  +14ms] +/-  200ms
^- 130.162.222.153               2  10   377   725   +377us[ +271us] +/- 9521us
^- cloudrouter.1in1.net          2  10   377   798  +1466us[+1328us] +/-   52ms
^- where-you.at                  2  10   377   837  +1306us[+1151us] +/-   51ms
^- time1.uni-paderborn.de        2  10   377   592  -2254us[-2299us] +/-   25ms

chronyc sourcestats
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
PPS0                        6   3    79     -0.007      0.065     -4ns   501ns
GPS                         6   3    77     +7.313    154.208    +13ms  1158us
130.162.222.153            35  21  175m     -0.053      0.070    +35us   380us
cloudrouter.1in1.net       37  16  174m     -0.224      0.162    +56us   894us
where-you.at               37  22  173m     -0.210      0.177   +581us   971us
time1.uni-paderborn.de     23  14  125m     -0.134      0.109  -2967us   272us

chronyc tracking
Reference ID    : 50505330 (PPS0)
Stratum         : 1
Ref time (UTC)  : Thu May 08 18:37:43 2025
System time     : 0.000000000 seconds fast of NTP time
Last offset     : -0.000000710 seconds
RMS offset      : 0.000002546 seconds
Frequency       : 19.773 ppm fast
Residual freq   : -0.002 ppm
Skew            : 0.053 ppm
Root delay      : 0.000000001 seconds
Root dispersion : 0.000025561 seconds
Update interval : 16.0 seconds
Leap status     : Normal
| Time:        2025-05-08T18:53:18.000Z (0) ││GNSS   PRN  Elev   Azim   SNR Use│
│ Latitude:         XX.XXXXXXXX N           ││GP  3    3  27.0  111.0  39.0  Y │
│ Longitude:        XX.XXXXXXXX E           ││GP  4    4  67.0   69.0  33.0  Y │
│ Alt (HAE, MSL):     81.790,     36.818 m  ││GP  6    6  57.0  270.0  19.0  Y │
│ Speed:             0.31 km/h              ││GP  9    9  74.0  237.0  16.0  Y │
│ Track (true, var):   315.9,   4.0     deg ││GP 26   26  14.0   62.0  30.0  Y │
│ Climb:            -0.36 m/min             ││SB126   39  19.0   38.0  21.0  Y │
│ Status:         3D DGPS FIX (17 secs)     ││SB147   60   5.0  109.0  30.0  Y │
│ Long Err  (XDOP, EPX):  1.06, +/-  4.0 m  ││GL  9   73   6.0  141.0  16.0  Y │
│ Lat Err   (YDOP, EPY):  0.81, +/-  3.0 m  ││GL 16   80  30.0   91.0  17.0  Y │
│ Alt Err   (VDOP, EPV):  0.70, +/-  4.0 m  ││GL  7   71  60.0  286.0  20.0  N │
│ 2D Err    (HDOP, CEP):  0.72, +/-  3.4 m  ││GL  8   72  12.0  263.0  14.0  N │
│ 3D Err    (PDOP, SEP):  1.00, +/-  4.8 m  ││GL 21   85  17.0  194.0   0.0  N │
│ Time Err  (TDOP):       1.29              ││GA  2  302   7.0   12.0   0.0  N │
│ Geo Err   (GDOP):       2.49              ││GA  7  307  25.0   61.0  39.0  N │
│ ECEF X, VX:              n/a    n/a       ││GA  7  307  25.0   61.0  36.0  N │
│ ECEF Y, VY:              n/a    n/a       ││GA 10  310  29.0  314.0   0.0  N │
│ ECEF Z, VZ:              n/a    n/a       ││GA 11  311   5.0  325.0   0.0  N │
│ Speed Err (EPS):       +/- 28.5 km/h      ││GA 12  312  50.0  296.0  12.0  N │
│ Track Err (EPD):        n/a               ││GA 19  319  48.0  232.0  17.0  N │
│ Time offset:            0.222295040 s     ││GA 19  319  48.0  232.0  18.0  N │
│ Grid Square:            JO62nn14          ││GA 26  326  12.0  161.0   0.0  N |
|Time: 2025-05-08T18:54:37.000Z   Lat: XX XX.XXXXXX' N   Lon:  XX XX.XXXXXX' E │
└───────────────────────────────── Cooked TPV ─────────────────────────────────┘
┌──────────────────────────────────────────────────────────────────────────────┐
│ GNRMC GNVTG GNGGA GNGSA GPGSV GLGSV GAGSV GBGSV GNGLL                        │
└───────────────────────────────── Sentences ──────────────────────────────────┘
┌───────────────────────┌─────────────────────────┌────────────────────────────┐
│ SVID  PRN  Az El SN HU│Time:     185437.000     │Time:      185437.000       │
│GP  3    3 111 27 39  Y│Latitude:  XXXX.XXXXXX N │Latitude:  XXXX.XXXXXX      │
│GP  4    4  69 67 35  Y│Longitude: XXXX.XXXXXX E │Longitude: XXXX.XXXXXX      │
│GP  6    6 270 57 18  Y│Speed:    0.27           │Altitude:  36.705           │
│GP  9    9 237 74 18  Y│Course:   35.69          │Quality:   2   Sats: 42     │
│GP 26   26  62 14 34  Y│Status:   A        FAA:D │HDOP:      0.71             │
│SB126   39  38 19 18  Y│MagVar:                  │Geoid:     44.97            │
│SB147   60 109  5 30  Y└───────── RMC ───────────└─────────── GGA ────────────┘
│GL  9   73 140  7 17  Y┌─────────────────────────┌────────────────────────────┐
│GL 16   80  90 31 17  Y│Mode: A3 Sats: 3 4 6 9 + │UTC:           RMS:         │
│GL  6   70  52 59  0  N│DOP H=0.71 V=0.69 P=0.99 │MAJ:           MIN:         │
│GL  7   71 288 61 16  N│TOFF:  0.093029292       │ORI:           LAT:         │
│GL  8   72 264 13  0  N│PPS: -0.000000574        │LON:           ALT:         |     

You know your system inside out, could it possibly be a problem with the module, which has peculiarities?

As long as I don’t have to reboot, the world is fine for me. I could live with “my" workarount, but it would be nicer if there was a permanent solution.

Can I provide any further information?
If so, please with exact instructions on what I should do.

Thanks again for your time!

Edit: Since I was a little unsure about my statements, I set the ttyAMA0 console back to OFF, rebooted and lo and behold, no more output from cgps or gpsmon.
Then I set the ttyAMA0 console back to ON and rebooted. I had to run the workaround with serial-getty@ttyAMA0.service again, restart gpsd and everything works as it should.

Now I have installed DietPi on a completely new hardware (RPi 4 1GB).
Following the same instructions, I have created another NTP server with a GPS module (GT-U7).
The behavior regarding ttyAMA0 and agetty is exactly the same as on the other RPi 4, where the NTP server is also running.

In the meantime, I set up a dirty workaround by creating a new service:

sudo nano /etc/systemd/system/gps-setup.service

The following content is there:

[Unit]
Description=Stoppt serial-getty und startet gpsd neu
After=network.target

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'sleep 60 && systemctl stop serial-getty@ttyAMA0.service && systemctl disable serial-getty@ttyAMA0.service && systemctl restart gpsd.service'
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

I saved the file and activated the service.
Then executed the following:

sudo systemctl enable gps-setup.service
sudo systemctl start gps-setup.service

Now, after a restart, both systems work to my satisfaction.

What makes me wonder, however, is the following:

Following the same instructions, I set up the NTP server on the second hardware with PiOS Lite and none of the problems I described occurred.

Could it be that this behavior is caused by DietPi? It’s just a thought of mine, but admittedly I’m not passing judgment on it.

Because DietPi is and remains my favorite SBC OS!