I installed KDE Plasma and LightDM on Arch Linux. Then, when shutting down, the message display was disrupted. Apparently, this occurs in Linux distributions that employ Systemd.
How can I fix this phenomenon?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI installed KDE Plasma and LightDM on Arch Linux. Then, when shutting down, the message display was disrupted. Apparently, this occurs in Linux distributions that employ Systemd.
How can I fix this phenomenon?
When systemd prints its output, it justifies the lines acording to the current screen resolution.
When lightdm shuts down, the screen resolution reverts to some default. systemd already printed those previous lines so it makes sense that it doesn't go backwards and try to clear the screen then reprint things with the new resolution every time the resolution changes.
To solve this you could figure out, you would need to set the default TTY resolution to match the resolution of your X (or wayland) server.
I'll also point out that spending effort to improve the look of shutdown text is pretty pedantic. These messages aren't intended to be on the screen for much longer, and if a service shutdown is hanging, it'll get printed in your current resolution, meaning anything important should be readable. If your journal is persistent (is stored in /var/
and isn't deleted between boots), then you'll be relieved to know that the journal is not stored in the same way it was displayed. In a case where you've configured the journal to be persistent, you can journalctl -b 1
to see the messages properly justified from the previous boot. That may be important to you if you feel it is essential to read these messages and decided they were unreadable.
DISCLAIMER: This solution is intended for users running systemd and LightDM. If your setup is different, you might have to modify the following instructions to suit your system. Skip to the SOLUTION section if you don't feel like reading all the background information regarding the misaligned shutdown messages.
OVERVIEW: I spent a long time trying to solve this problem and was only able to fix it a few days ago. It most likely HAS NOTHING TO DO WITH YOUR SCREEN RESOLUTION, but instead is caused by one of your applications (possibly LightDM) formatting your terminal/tty incorrectly. At some point during startup/shutdown, something changes your tty so that new lines (NL) don't receive an automatic carriage return (CR) as they normally do. In English, this means that if you pressed Enter on your keyboard, your text cursor would move down one line, BUT NOT REALIGN ITSELF TO THE LEFT SIDE OF THE TERMINAL WINDOW (you can see this in the picture you provided, https://i.stack.imgur.com/oARSo.jpg). This is known as a "staircase effect" and, from what I've read, is a fairly common issue on Linux. The core code to resolve said problem is stty opost onlcr
, but using it can be a major pain if you don't know exactly where to put it in systemd. If you apply the command too early or too late, you'll just be formatting text that is already correctly displayed. ONE SOLUTION is to create a CUSTOM SYSTEMD SERVICE to adjust tty output properly. You can have the service restart itself occasionally so you don't have to pinpoint the precise location where stty opost onlcr
should go.
SOLUTION:
#Find out what tty instance your Desktop Environment (e.g. Gnome, KDE Plasma, etc.) is running. Typically it's tty1, but since you're using LightDM, it should actually be tty7. You need this information when you create your systemd service in Step 2.
who
in your terminal. It should produce output like:user-name tty7 2021-02-08 12:11 (:0)
#Create a custom systemd service as root in /etc/systemd/system/
. Under the ExecStart=
section, include the tty information you found in Step 1. Name the service anything you want, such as staircase-effect.service
.
sudo nano /etc/systemd/system/staircase-effect.service
in your terminal. Here is a sample unit to try with important options explained afterwards.[Unit]
Description=Fix tty staircase effect
DefaultDependencies=no
Before=halt.target shutdown.target reboot.target
[email protected]
StartLimitBurst=5
StartLimitIntervalSec=0[Service]
Type=simple
ExecStart=/bin/stty -F /dev/tty7 opost onlcr
Restart=always
RestartSec=30[Install]
WantedBy=multi-user.target
StartLimitIntervalSec=0
- Setting this option to "0" lets systemd restart your service an infinite amount of times without returning any errors.
Type=simple
- It's better to use "simple" than "oneshot" with this service because it runs in a never-ending loop. AFAIK, "oneshot" prevents other services from running at the same time it is, which would be undesireable in this situation.
ExecStart=/bin/stty -F /dev/tty7 opost onlcr
- This line is what actually solves the staircase messages. Make sure to put in the correct tty number you got from the who
command in Step 1.
Restart=always
- You want this service to repeat itself UNLESS you know exactly where to place it in your startup/shutdown procedure. The stty
command is no good if you run it when text is already displayed properly.
RestartSec=30
- Technically, this option is a matter of personal preference. You're going to want your service to restart itself frequently enough to solve the problem, but not so much so that it becomes its own nuisance.
#Enable your new service as root with systemctl
.
sudo systemctl enable staircase-effect.service
in your terminal. Then reboot
to see if the fix works.OPTIONAL LIGHTDM ADJUSTMENTS:
#The default LightDM service /usr/lib/systemd/system/lightdm.service
conflicts with [email protected]
unnecessarily (https://bugs.archlinux.org/task/49527?opened=22169&status%5B0%5D=). I'm not sure if this is related to the staircase messages or not, but it probably won't hurt to remove the [email protected]
line from the unit file.
sudo systemctl edit --full lightdm.service
in your terminal. Then either remove or comment out the [email protected]
line to stop LightDM from interfering with your standard getty service. reboot
to see the changes.ALTERNATIVE SOLUTIONS:
https://www.reddit.com/r/linux/comments/iwnm9w/shutdown_staircase_output_fix/
Alternative Solution 1 (this is where I got the main stty
command from)
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=617249
Alternative Solution 2 (for users running System V and Debian)