Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

© Copyright The Linux Foundation 2023: DO NOT COPY OR DISTRIBUTE

31.5. LABS 1

Exercise 31.1: Modify an Existing Service with systemd


Often we want to modify the behavior of an existing service rather than creating a new one. systemd can handle this by
completely replacing or disabling a built-in service, but also by only modifying certain parameters of an existing service, called
a drop-in via an .override file or .config directory. An added advantage of using this method – package upgrades won’t
revert your changes.

We are going to modify the Description for the unit responsible for login (getty) on the first console (tty1) and then change
it back.

We are assuming you are logged-in to your workstation either via the graphical interface or ssh. But a safety precaution, verify
that you are not logged in on this terminal:

$ tty

Very Important
If you see the result of this command as /dev/tty1, it’s probably best to skip this lab.

1. First, check the status of the getty@tty1.service:


$ systemctl status getty@tty1.service

$ systemctl status getty@tty1.service


* getty@tty1.service - Getty on tty1
Loaded: loaded (/lib/systemd/system/getty@.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2023-03-09 12:58:42 EST; 2 months 7 days ago
Docs: man:agetty(8)
man:systemd-getty-generator(8)
http://0pointer.de/blog/projects/serial-console.html
Main PID: 621 (agetty)
Tasks: 1 (limit: 4656)
Memory: 200.0K
CPU: 2ms
CGroup: /system.slice/system-getty.slice/getty@tty1.service
`-621 /sbin/agetty -o -p -- \u --noclear tty1 linux

Warning: some journal files were not opened due to insufficient permissions.

2. Next, let’s change the description of the service. Copy the Description= line and make it say something different. In the
example, we are changing the dynamic output to first terminal.

$ sudo systemctl edit getty@tty1.service

### Editing /etc/systemd/system/getty@tty1.service.d/override.conf


### Anything between here and the comment below will become the new contents of the file

[Unit]
Description=Getty on the first terminal

### Lines below this comment will be discarded

### /lib/systemd/system/getty@.service
# # SPDX-License-Identifier: LGPL-2.1-or-later
# #
# # This file is part of systemd.

V 2023-06-30 © Copyright The Linux Foundation 2023 All rights reserved.


© Copyright The Linux Foundation 2023: DO NOT COPY OR DISTRIBUTE
2 CHAPTER 31. SYSTEM INIT: SYSTEMD HISTORY AND CUSTOMIZATION

# #
# # systemd is free software; you can redistribute it and/or modify it
# # under the terms of the GNU Lesser General Public License as published by
# # the Free Software Foundation; either version 2.1 of the License, or
# # (at your option) any later version.

3. Now, verify the contents of /etc/systemd/system/getty@tty1.service.d/override.conf


This should represent the change that you just made - just two lines with no newline at the end.
$ cat /etc/systemd/system/getty@tty1.service.d/override.conf

[Unit]
Description=Getty on the first terminal<YOUR PROMPT HERE>

4. Reload the daemon to pick up our changes, and the check the results:

$ sudo systemctl daemon-reload


$ systemctl status getty@tty1.service

* getty@tty1.service - Getty on the first terminal


Loaded: loaded (/lib/systemd/system/getty@.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/getty@tty1.service.d
`-override.conf
Active: active (running) since Thu 2023-03-09 12:58:42 EST; 2 months 7 days ago
Docs: man:agetty(8)
man:systemd-getty-generator(8)
http://0pointer.de/blog/projects/serial-console.html
Main PID: 621 (agetty)
Tasks: 1 (limit: 4656)
Memory: 200.0K
CPU: 2ms
CGroup: /system.slice/system-getty.slice/getty@tty1.service
`-621 /sbin/agetty -o -p -- \u --noclear tty1 linux

Warning: some journal files were not opened due to insufficient permissions.

5. Finally, remove the file we created to bring things back to normal.

$ sudo rm /etc/systemd/system/getty@tty1.service.d/override.conf
$ systemctl status getty@tty1.service

* getty@tty1.service - Getty on tty1


Loaded: loaded (/lib/systemd/system/getty@.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2023-03-09 12:58:42 EST; 2 months 7 days ago
Docs: man:agetty(8)
man:systemd-getty-generator(8)
http://0pointer.de/blog/projects/serial-console.html
Main PID: 621 (agetty)
Tasks: 1 (limit: 4656)
Memory: 200.0K
CPU: 2ms
CGroup: /system.slice/system-getty.slice/getty@tty1.service
`-621 /sbin/agetty -o -p -- \u --noclear tty1 linux

Warning: some journal files were not opened due to insufficient permissions.

V 2023-06-30 © Copyright The Linux Foundation 2023 All rights reserved.

You might also like