Does systemd still have the concept of runlevels? For example is it pointless to use telinit <number>?
4 Answers
Within the SystemD(aemon), runlevels are exposed as "Targets." The concept is still there, but the workflow to produce the desired result for your requirement is different.
The attached should clarify this issue.
How do I change the current runlevel?
$ systemctl isolate runlevelX.target How do I change the default runlevel for next-boot?
# Create a symlink $ ln -sf /usr/lib/systemd/system/multi-user.target /etc/systemd/system/default.target ln -sf TARGET DESTINATION-screates symbolic link-fremoves the existing destination file
OR (as @centimane suggested) simply use the "blessed" systemd command:
systemctl set-default [target name].target How do I identify the current runlevel?
$ systemctl list-units --type=target - Can I still use the init command to switch between runlevels?drpaneas– drpaneas2014-10-02 15:47:49 +00:00Commented Oct 2, 2014 at 15:47
- 2If your systemd package is built with SysV compat support, it will include a telinit symlink to the systemd binary, which, when called as telinit, will map runlevels 0-6 to systemd targets - check telinit(8) for a list of those mappings.Wieland– Wieland2014-10-03 07:44:13 +00:00Commented Oct 3, 2014 at 7:44
- 3To change the default target you should use
systemctl set-default [target name].targetrather than manually creating the link.Centimane– Centimane2018-01-08 19:16:33 +00:00Commented Jan 8, 2018 at 19:16 - 1
systemctl list-units --type=targetdoes not identify the current runlevel, it lists all the active .target units though.Elijah Lynn– Elijah Lynn2022-03-03 02:40:40 +00:00Commented Mar 3, 2022 at 2:40
No. As the systemd people themselves wrote twice over, once in their telinit manual and once in their runlevel manual, runlevels are "obsolete". You can forget about runlevels.
These things do not actually exist in systemd at all, outwith a few compatibility shims.
- There are some symbolic links for target names, but these targets are never actually used by systemd proper.
- Rather, the bootstrap process employs a
default.target(and thence one or both of agraphical.targetand amulti-user.target), arescue.target, or anemergency.target. And the shutdown process involves ashutdown.target, areboot.target, ahalt.target, or apoweroff.target. No run-level targets are involved in either bootstrap or shutdown. - The
telinitcommand, which one might think uses the compatibility symbolic links to map its command-line arguments, does not do that either. There's a hardwired table in the source code of thetelinitprogram, and the numbers2,3,4, and5as arguments to the command are hardwired to map tomulti-user.targetandgraphical.target. systemd-update-utmpalso has an internal hardwired table.
- Rather, the bootstrap process employs a
- There is no "init table" of runlevel stuff. systemd is only compatible with van Smoorenburg
rc, not with van Smoorenburginit. - There is no "current run level" value maintained by systemd itself. Rather, the almost wholly undocumented
systemd-update-utmpcommand operates internally in terms of the activation states ofrescue.target,multi-user.target, andgraphical.target. systemd-sysv-generator, systemd's backwards compatibility service unit generator, merges the/etc/rc[234].ddirectories into just the oneWanted-Byrelationship tomulti-user.targetin generated service units. There is no actual reference to run levels in the generated service units. (There used to be, years ago, but the systemd people found that this went wrong, because they weren't being referenced anywhere else.)
If one is a user of a system that builds systemd as did Arch Linux for the questioner at "Why does `init 0` result in "Excess Arguments" on Arch install?", one does not even get the compatibility shims, and commands such as init 0 result in the "native" systemd behaviour, which is to complain that the command has been incorrectly invoked.
Further reading
- Lennart Poettering et al..
runlevel. systemd manual pages. Freedesktop.org. - Lennart Poettering et al..
telinit. systemd manual pages. Freedesktop.org. - Lennart Poettering et al..
bootup. systemd manual pages. Freedesktop.org. - Lennart Poettering (2015-02-08). everywhere: remove configurability of sysv runlevel to target mapping. systemd. github.
- https://unix.stackexchange.com/a/196014/5132
- https://unix.stackexchange.com/a/196197/5132
- https://unix.stackexchange.com/a/233581/5132
- https://unix.stackexchange.com/a/211927/5132
- https://unix.stackexchange.com/a/392612/5132
- Jonathan de Boyne Pollard (2015).
/etc/inittabis a thing of the past.. Frequently Given Answers.
Thanks very much. So, if I understood correctly:
For example:
ls -ll /usr/lib/systemd/system/runlevel*.target Output:
/usr/lib/systemd/system/runlevel0.target -> poweroff.target /usr/lib/systemd/system/runlevel1.target -> rescue.target /usr/lib/systemd/system/runlevel2.target -> multi-user.target /usr/lib/systemd/system/runlevel3.target -> multi-user.target /usr/lib/systemd/system/runlevel4.target -> multi-user.target /usr/lib/systemd/system/runlevel5.target -> graphical.target /usr/lib/systemd/system/runlevel6.target -> reboot.target So as you can see, the concept of runlevels do exists, but it is quite obsolete due to the fact that the runlevel.target files are not actually “real” files but soft-links to the new, modern, better named files scheme which systemd likes to call them “targets”.
So, if you would like to do sth like telinit 5 it would be like this: systemctl isolate runlevel5.target which is identical with: systemctl isolate graphical.target (recommended in my opinion).
Just in case you are interested to know all the possible targets:
ls /usr/lib/systemd/system/*.target - Yes, I believe that you are understanding this correctly. I will be a late adopter of SystemD, as the procedural, step-step-step, INIT.D system is what I am most familiar with... I applaud that you are exploring SystemD. The best part of SystemD is its parallel multi-threading, which enables faster boot. Multi-Threading boot can be accomplished with INIT.D, but requires strong BASH scripting.Tyler Maginnis– Tyler Maginnis2014-10-02 16:03:22 +00:00Commented Oct 2, 2014 at 16:03
- BTW,
ls -llis equivalent tols -l. You might want to get into the habit of usingls -ld.G-Man Says 'Reinstate Monica'– G-Man Says 'Reinstate Monica'2017-05-14 05:53:45 +00:00Commented May 14, 2017 at 5:53 -
telinit 0/telinit 6still work. Since this helps with migration, and I think most distros still don't see a reason to drop the support yet.isolateclearly aspired to mimic how run-levels work, but there are various evil edge cases. I highly recommend ignoring all instructions toisolate runlevel5.targetor evenisolate graphical.target. Example edge case: github.com/systemd/systemd/issues/6505sourcejedi– sourcejedi2018-08-19 14:30:55 +00:00Commented Aug 19, 2018 at 14:30
systemd introduced targets as a counterpart for runlevels in sysV init system. sytemd developers made it almost compatible with most of the sysV scripts. Same happens for telinit <runlevel>. This is translated into systemd equivalent.
For example telinit 0 powers off the machine. systemd has poweroff.target to do the same as runlevel 0. So telinit 0 is translated by systemd to activate poweroff.target.
But some compatibility problems are there with sytemd and sysV init systems-> https://www.freedesktop.org/wiki/Software/systemd/Incompatibilities.
init 1orinit 3orinit 5orinit 6orinit 0orrunlevelstill behave as they always have, and that's all I care about. Much easier syntax thensystemctl blabla blabla.blabla