Bug 1002806

Summary: runlevel command returns "unknown"
Product: [Fedora] Fedora Reporter: Andre Robatino <robatino>
Component: systemdAssignee: systemd-maint
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: dhcolesj, johannbg, kparal, lnie, lnykryn, msekleta, plautrba, shawn.starr, systemd-maint, vpavlin, zbyszek
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: systemd-208-4.fc20 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-11-10 07:37:05 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Andre Robatino 2013-08-30 04:28:47 UTC
Description of problem:
The runlevel command always returns "unknown" in either F20 or Rawhide, regardless of the actual runlevel. Since the concept of runlevel is obsolete, as mentioned in the man page, I don't know if this is an actual bug. I felt compelled to report it since a number of the QA tests currently refer to it.

Version-Release number of selected component (if applicable):
systemd-206-9.fc21

How reproducible:
always

Comment 1 Andre Robatino 2013-08-31 11:23:18 UTC
In either F20 or Rawhide, if I boot using a runlevel ("3" or "5") as a boot option, then the runlevel command returns the proper value ("N 3" or "N 5", resp.). Otherwise, it returns "unknown".

Comment 2 Andre Robatino 2013-08-31 11:52:23 UTC
This bug only appears on systems installed using an install image. When running the 20 Alpha TC2 Desktop Live, or after installing from it, the runlevel command returns "N 5" even though it was not passed as a boot argument. So the quickest way to reproduce this is to do a minimal F20 install from netinst or DVD.

Comment 3 Shawn Starr 2013-09-01 19:40:28 UTC
I hit this on TC2 w/ 32bit trying to install KDE Desktop, runlevel returns unknown, X wont start because there's no runlevel for systemd to determine when to start up graphical.target (Runlevel 5)

Comment 4 Shawn Starr 2013-09-02 16:22:52 UTC
I did a PXE net install from the TC2 http://dl.fedoraproject.org/pub/alt/stage/20-Alpha-TC2/Fedora/i386/os/ repo directly, I did not try 64bit yet to confirm if this is platform specific or not.

Comment 5 Shawn Starr 2013-09-04 12:03:23 UTC
KS file generated, this is based on a bootstrapped ks.cfg and then I manually select the installation type, I chose 'KDE Plasma Workspaces' option then installed with this setup:

On boot, there was no X started since no graphical.target was configured:

lrwxrwxrwx. 1 root root 37 Sep  3 23:07 /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target

[root@t42 ~]# runlevel
unknown

In Fedora 19, you would indeed see the runlevel.

anaconda-ks.cfg:

--- SNIP ---
#version=DEVEL
# System authorization information
auth --enableshadow --enablemd5
# Install OS instead of upgrade
install

# Use network installation
url --url="http://dl.fedoraproject.org/pub/alt/stage/20-Alpha-TC2/Fedora/i386/os/"
# Firewall configuration
firewall --disabled
ignoredisk --only-use=sda
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=enp2s1 --noipv6
network  --hostname=t42
# Root password
rootpw --plaintext letmein
# SELinux configuration
selinux --disabled
# System services
services --enabled="chronyd"
# System timezone
timezone America/Toronto --isUtc
# System bootloader configuration
bootloader --location=mbr --driveorder="sda" --timeout=5 --boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all  --drives=sda
# Disk partitioning information
part / --asprimary --fstype="ext2" --size=76018
part /boot --asprimary --fstype="ext2" --size=300

%pre
%end

%post --logfile /root/dump.log
echo "Disabling services: mcelog, smartd, firewalld, atd, crond"
chkconfig mcelog off
chkconfig smartd off
chkconfig firewalld off
chkconfig atd off
chkconfig crond off
chkconfig chronyd on

echo "nameserver 172.18.2.6" >> /etc/resolv.conf
echo "1 letmein" >> /etc/chrony.keys

%end

%packages --excludedocs --nobase
@admin-tools
@base-x
@core
@dial-up
@fonts
@guest-desktop-agents
@hardware-support
@input-methods
@kde-desktop
@multimedia
@printing
@standard
chrony
grub2
kernel
net-tools
-sendmail

%end
--- SNIP ---

Comment 6 Kamil Páral 2013-09-04 12:13:28 UTC
Shawn, I think this is a different problem. The problem is that multi-user.target is used by default in your case (instead of graphical.target), not that runlevel command displays "unknown". Please file a separate bug report. Also don't forget to try the installation without the kickstart file.

Comment 7 Shawn Starr 2013-09-04 12:24:48 UTC
Hi Kamil,

There may be two separate bugs though as a result of this issue however as you say.

1) systemd showing unknown
2) X not starting because systemd is not setting the target correctly (at least for KDE Plasma Workspaces) which may or may not be related to #1

I'll file a 2nd bug for the issue #2 if it turns out they are related we can link the two

Comment 8 Jóhann B. Guðmundsson 2013-09-04 12:38:54 UTC
So back to what this bug is initially about...

As has been in the man page for runlevel command. 

"This is a legacy command available for compatibility only. It should not be used anymore, as the concept of runlevels is obsolete."

Given that we need users/administrators to adapt to new concept and ways of doing things we at some point we should start removing that obsoleted backward compatibility so I think we should rather come up with a firm legacy removal policy for commands targets etc which systemd obsoletes which we can put under the systemd namespace on the wiki as well as list there which those commands targets etc are and when we plan on obsoleting them as opposed to patch these things up and have them continue to work in their limited/broken way.

Arguably 2 full GA releases should suffice as an migration/obsolete period for those things.

Comment 9 Shawn Starr 2013-09-12 22:01:16 UTC
I will disagree, runlevels are still quite useful and the concept is not 'gone'. Switching the system from different runlevels is still handled:

See:

telinit
telinit [OPTIONS...] {COMMAND}

Send control commands to the init daemon.

     --help      Show this help
     --no-wall   Don't send wall message before halt/power-off/reboot

Commands:
  0              Power-off the machine
  6              Reboot the machine
  2, 3, 4, 5     Start runlevelX.target unit
  1, s, S        Enter rescue mode
  q, Q           Reload init daemon configuration
  u, U           Reexecute init daemon


Its just now the runlevels are targets.

Comment 10 Andre Robatino 2013-09-12 22:04:42 UTC
Not to mention that this bug only affects installs from install images, not running live or installs from live, so it may be caused by something trivial.

Comment 11 Jóhann B. Guðmundsson 2013-09-13 09:21:19 UTC
(In reply to Shawn Starr from comment #9)
> I will disagree, runlevels are still quite useful and the concept is not
> 'gone'. Switching the system from different runlevels is still handled:
> 
> See:

There is not 1 to 1 mapping between run levels and targets and alternating the old commands to providing limited backwards compatibility to the new stuff is only hindering adoption as in change of mindset and workflow since administrators and users alike have certain expectation to the behaviour and workflow using those commands.

telinit for example is no longer working in the same way as it has for the last decade. You no longer go and edit /etc/inittab you do not use it the same way when setting and troubleshooting problem so it's existence only confuse administrators and their expectation regarding it's behaviour. ( And we have had plethora of bugs related to it )

At least that's my point of view as in we should have gotten the users to get accustom to the new commands by essentially forcing them to use the native systemd commands by having them backward incompatible instead of alternating and introducing limit backward compatibility and behaviour with the old commands and the old way administrate and doing things.

Comment 12 Zbigniew Jędrzejewski-Szmek 2013-09-13 12:05:40 UTC
Hi,
the 'runlevel' command in systemd works a bit differently than sysvinit runlevels, because the a specific runlevel is only returned when it is reached, while sysvinit would display it as soon as the switch was requested. So,
to have an answer like '3', two things are required:

1. the target (multi-user.target or graphical.target) must be reached
2. runlevel3.target must be an alias for that target

So, can you do:
$  ls -l /usr/lib/systemd/system/runlevel?.target
$  systemctl status multi-user.target graphical.target default.target runlevel{3,5}.target

?

Comment 13 Andre Robatino 2013-09-13 12:29:17 UTC
On one of my F20 VirtualBox guests, which originally gave "unknown", it now shows "N 5". I don't know when it fixed itself. On a F20 KVM guest I installed from the 20 Alpha RC2 DVD yesterday, it still shows "unknown". Here is the output from that:

[andre@localhost ~]$ ls -l /usr/lib/systemd/system/runlevel?.target
lrwxrwxrwx. 1 root root 15 Sep 12 09:51 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Sep 12 09:51 /usr/lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Sep 12 09:51 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Sep 12 09:51 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Sep 12 09:51 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Sep 12 09:51 /usr/lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Sep 12 09:51 /usr/lib/systemd/system/runlevel6.target -> reboot.target
[andre@localhost ~]$ systemctl status multi-user.target graphical.target default.target runlevel{3,5}.target
multi-user.target - Multi-User System
   Loaded: loaded (/usr/lib/systemd/system/multi-user.target; disabled)
   Active: active since Fri 2013-09-13 08:17:19 EDT; 4min 29s ago
     Docs: man:systemd.special(7)

Sep 13 08:17:19 localhost.localdomain systemd[1]: Starting Multi-User System.
Sep 13 08:17:19 localhost.localdomain systemd[1]: Reached target Multi-User S...

graphical.target - Graphical Interface
   Loaded: loaded (/lib/systemd/system/graphical.target; enabled)
   Active: active since Fri 2013-09-13 08:17:19 EDT; 4min 29s ago
     Docs: man:systemd.special(7)

Sep 13 08:17:19 localhost.localdomain systemd[1]: Starting Graphical Interface.
Sep 13 08:17:19 localhost.localdomain systemd[1]: Reached target Graphical In...

graphical.target - Graphical Interface
   Loaded: loaded (/lib/systemd/system/graphical.target; enabled)
   Active: active since Fri 2013-09-13 08:17:19 EDT; 4min 29s ago
     Docs: man:systemd.special(7)

Sep 13 08:17:19 localhost.localdomain systemd[1]: Starting Graphical Interface.
Sep 13 08:17:19 localhost.localdomain systemd[1]: Reached target Graphical In...

multi-user.target - Multi-User System
   Loaded: loaded (/usr/lib/systemd/system/multi-user.target; disabled)
   Active: active since Fri 2013-09-13 08:17:19 EDT; 4min 29s ago
     Docs: man:systemd.special(7)

Sep 13 08:17:19 localhost.localdomain systemd[1]: Starting Multi-User System.
Sep 13 08:17:19 localhost.localdomain systemd[1]: Reached target Multi-User S...

graphical.target - Graphical Interface
   Loaded: loaded (/lib/systemd/system/graphical.target; enabled)
   Active: active since Fri 2013-09-13 08:17:19 EDT; 4min 29s ago
     Docs: man:systemd.special(7)

Sep 13 08:17:19 localhost.localdomain systemd[1]: Starting Graphical Interface.
Sep 13 08:17:19 localhost.localdomain systemd[1]: Reached target Graphical In...
[andre@localhost ~]$ runlevel 
unknown
[andre@localhost ~]$

Comment 14 Zbigniew Jędrzejewski-Szmek 2013-09-14 00:12:33 UTC
Hm, and what does 'utmpdump < /var/run/utmp' say?

Comment 15 Andre Robatino 2013-09-14 08:04:19 UTC
Just so you know, after my last comment, I first tried updating just systemd, and then everything, and rebooting, to see if it made any difference. It didn't. On the other hand, my 20 and Rawhide VirtualBox guests, which have existed and been continuously updated for a few weeks, both "fixed" themselves at some point. I have no idea how or when.

Anyway, the requested output on my KVM guest (which is now fully updated, and still returns "unknown") is

[andre@localhost ~]$ utmpdump < /var/run/utmp
Utmp dump of /dev/stdin
[2] [00000] [~~  ] [reboot  ] [~           ] [3.11.0-300.fc20.x86_64] [0.0.0.0        ] [Sat Sep 14 03:56:46 2013 EDT]
[7] [01214] [:0  ] [andre   ] [:0          ] [:0                  ] [0.0.0.0        ] [Sat Sep 14 03:57:44 2013 EDT]
[7] [01988] [/0  ] [andre   ] [pts/0       ] [:0                  ] [0.0.0.0        ] [Sat Sep 14 03:58:26 2013 EDT]
[andre@localhost ~]$

Comment 16 Howard Coles Jr. 2013-10-12 20:03:01 UTC
running "telinit 3" or "init 3" will result in the runlevel changing, but in the tty session you ran the command the prompt will never return, nor the session reset.

I must also strongly encourage us to NOT try and obsolete the idea of runlevels.  They are indeed most useful as a fast way to diagnose, and/or fix problems.

Comment 17 Lennart Poettering 2013-10-13 18:08:10 UTC
If "runlevel" returns "unknown" this usually means that the boot is not complete yet. You probably still have some jobs queued. Check which "systemctl list-jobs" which ones those are.

Comment 18 Andre Robatino 2013-10-13 23:25:54 UTC
This is from a clean install from Fedora-20-Beta-TC2-x86_64-DVD.iso (minimal, no updates).

[root@localhost ~]# systemctl list-jobs
No jobs running.
[root@localhost ~]# runlevel
unknown
[root@localhost ~]#

I'm aware that sometimes it takes a while for runlevel to start showing the normal output, but I've given it plenty of time. This never happened before, and I've been running it on each compose for a long time since https://fedoraproject.org/wiki/QA:Testcase_Package_Sets_Minimal_Package_Install specifically suggests using the runlevel command. It might spontaneously "fix" itself eventually, as I noted above, but normal behavior is that it should work almost immediately after the first boot.

Comment 19 Zbigniew Jędrzejewski-Szmek 2013-10-18 20:51:07 UTC
This really looks like systemd bug, probably something to do with the fact that default.target is also known as runlevel5.target. systemd-update-utmp-runlevel.service is not run, even though default.target has it in Wants=, and default.target is "started", i.e. completed. Starting systemd-update-utmp-runlevel.service manually causes that utmp entry to be inserted.

[test@fedora20 ~]$ sudo systemctl start default.target
[test@fedora20 ~]$ runlevel
unknown
[test@fedora20 ~]$ sudo systemctl start runlevel5.target
[test@fedora20 ~]$ runlevel
N 5

[test@fedora20 ~]$ systemctl show --no-pager -p Wants default.target
Wants=gdm.service systemd-readahead-replay.service systemd-readahead-collect.service accounts-daemon.service rtkit-daemon.service
[test@fedora20 ~]$ systemctl show --no-pager -p Wants graphical.target
Wants=gdm.service systemd-readahead-replay.service systemd-readahead-collect.service accounts-daemon.service rtkit-daemon.service
[test@fedora20 ~]$ systemctl show --no-pager -p Wants runlevel5.target
Wants=gdm.service systemd-readahead-replay.service systemd-readahead-collect.service accounts-daemon.service rtkit-daemon.service systemd-update-utmp-runlevel.service

WAT?

Comment 20 Zbigniew Jędrzejewski-Szmek 2013-10-21 18:56:33 UTC
So... runlevel5.target isn't actually referenced by anything, and systemd will happily reach default.target = graphical.target without ever attempting to load runlevel5.target. This means that drop-ins and .wants directories attached to runlevel5.target are not processed. If at any point, runlevel5.target is loaded (systemctl status runlevel5.target is enough), runlevel5.target becomes another name for graphical.target.

I'm not sure what the proper fix here is:

1. disallow .d and .wants and .requires dirs on aliases
2. 1., but only if the alias is not wanted or required somewhere else
3. include .d and .wants and .requires for all aliases of a unit. This would require looking for all aliases in advance, an O(n) operation, unless a cache of aliases is used.

Comment 21 Fedora Update System 2013-10-22 16:10:01 UTC
systemd-208-4.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/systemd-208-4.fc20

Comment 22 Fedora Update System 2013-10-22 18:50:54 UTC
Package systemd-208-4.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing systemd-208-4.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2013-19680/systemd-208-4.fc20
then log in and leave karma (feedback).

Comment 23 lnie 2013-10-23 09:56:00 UTC
still occurs in systemd-208-4.fc20

Comment 24 Zbigniew Jędrzejewski-Szmek 2013-10-23 12:08:24 UTC
(In reply to lnie from comment #23)
> still occurs in systemd-208-4.fc20
Is this after a reboot?

What does 'runlevel; systemctl list-jobs; runlevel; systemctl start runlevel5.target; runlevel' say?

Comment 25 lnie 2013-10-24 03:08:47 UTC
God forgive~,I forgot to reboot it:(
seems be fixed already:)

Comment 26 Andre Robatino 2013-10-24 04:37:18 UTC
@ lnie: If you change your karma on https://admin.fedoraproject.org/updates/FEDORA-2013-19680/systemd-208-4.fc20 to +1, it should reach +3 and go to stable.

@Zbigniew Jędrzejewski-Szmek: In the changelog, you said it was a "temporary fix" - how did you fix it (option 1, 2, 3, or something else)?

Comment 27 Zbigniew Jędrzejewski-Szmek 2013-10-24 05:21:40 UTC
(In reply to Andre Robatino from comment #26)
> @ lnie: If you change your karma on
> https://admin.fedoraproject.org/updates/FEDORA-2013-19680/systemd-208-4.fc20
> to +1, it should reach +3 and go to stable.
I pushed it anyway, assuming that lnie's negative karma doesn't count.

> @Zbigniew Jędrzejewski-Szmek: In the changelog, you said it was a "temporary
> fix" - how did you fix it (option 1, 2, 3, or something else)?
I copied the links from runlevel5.wants to graphical.wants, and the same for other runlevels. Far from ideal, but it seems that people don't use .wants for aliases all that often, and systemd itself was one of the main users.

Comment 28 lnie 2013-10-24 07:58:41 UTC
(In reply to Andre Robatino from comment #26)
> @ lnie: If you change your karma on
> https://admin.fedoraproject.org/updates/FEDORA-2013-19680/systemd-208-4.fc20
> to +1, it should reach +3 and go to stable.
> 
going to add one :)

Comment 29 Fedora Update System 2013-11-10 07:37:05 UTC
systemd-208-4.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.