Systemd is working with services and targets. Targets is the equivalent of runlevels, services is the equivalent of init scripts.
Most of systemd configuration is located in /usr/lib/systemd
, while standard init are in /etc/{init.d,rc*.d,inittab}
.
When an issue kicks in during the boot process (default are getty.target or graphical.target, you can get them with systemctl get-default
) systemd is switching to emergency.target.
This "emergency" target will in turn, load the file emergency.service
. This service contains multiple lines, and among them:
...
[Service]
Environment=HOME=/root
WorkingDirectory=/root
ExecStartPre=-/bin/plymouth quit
ExecStartPre=-/bin/echo -e 'Welcome to emergency mode! After logging in, type "journalctl -xb" to view\\nsystem logs, "systemctl reboot" to reboot, "systemctl default" to try again\\nto boot into default mode.'
ExecStart=-/bin/sh -c "/sbin/sulogin; /usr/bin/systemctl --fail --no-block default"
...
We just need to replace the call to /sbin/sulogin
:
ExecStart=-/bin/sh -c "/sbin/sushell; /usr/bin/systemctl --fail --no-block default"
And we will be dropped directly to a shell, instead of getting prompted for the password via sulogin. (We can use /bin/sh
, but /sbin/sushell
falls in line with the answers for CentOS6/RHEL6. In fact, sushell
simply exec's $SUSHELL
which defaults to /bin/bash
.)
To make this change "permanent", ie, immune to yum
updates, make the change to a copy of this file and place it in /etc/systemd/system/
. Also, to make the "rescue mode" work the same way, replace the same line in rescue.service
. Here's a shell/sed script to simplify the process:
for SERVICE in rescue emergency ; do
sed '/^ExecStart=/ s%"/sbin/sulogin;%"/sbin/sushell;%' /usr/lib/systemd/system/$SERVICE.service > /etc/systemd/system/$SERVICE.service
done
To test this, make sure the system is otherwise not in use, and tell systemd
to switch to the rescue
target:
systemctl rescue
This will close network connections and open a shell at the console. You can test with the emergency
target, but that doesn't work quite as cleanly (For some reason) and may require a full reboot to come out of.
You can also test these from the boot-menu (grub). For testing the emergency mode, it's easy. Boot and when you get the menu, hit "e" to edit, and use the D-pad to navigate to the line beginning with linux16
and append (hit CTRL-A
to get to the end of the line) emergency
:
linux16 ... emergency
For testing rescue mode, it's the same steps as above but you must be more explicit:
linux16 ... systemd.unit=rescue.target