39

Pretty simple, I am trying to change the runlevel. Everything I find online points me to the file located in:

/etc/init/rc-sysinit.conf

Here I have tried changing the "DEFAULT_RUNLEVEL" to 3 or anything else and it makes no difference (the original value was 2 which didn't make much sense either). No matter what, my machine boots fully and when I check the runlevel command, I see "N 5" as the result every time.

How do I change the runlevel? I would rather not override it through grub or some other workaround mechanism. And I am not looking for how to disable X specifically.

All the instructions I was finding online were a bit old, did something change with 16.04?

muru
  • 197,895
  • 55
  • 485
  • 740
gnomed
  • 569
  • So do you want to change it manually after boot or automatically boot to a different runlevel every time? – Byte Commander Jun 17 '16 at 21:00
  • automatic every time. It was set up with ubuntu desktop, but now I wanna lower the runlevel and put it in a corner somewhere. – gnomed Jun 17 '16 at 21:15
  • Actually, why do you want to change the runlevel? Do you only want to boot to a terminal interface instead of loading the desktop? In that case you should instead modify the standard target systemd loads at boot and add the "text" kernel option. – Byte Commander Jun 17 '16 at 21:33
  • I guess that is what I want. I was just trying to minimize the resources it consumes if I don't need any graphical environment at all. – gnomed Jun 17 '16 at 22:02
  • Not really. I'm trying to change the runlevel, thats what I want to do, and it should be perfectly reasonable and possible to do, shouldn't it? Even if this doesn't accomplish my end goal I would like to know why every online tutorial I've followed does not seem to be correct on Ubuntu 16.04. – gnomed Jun 17 '16 at 22:25
  • 4
    Probably because since 15.10, Ubuntu uses systemd instead of upstart and that file you're talking about is for upstart. If you read even older articles, you will find ways for the old init as well. But with systemd, you can simply switch between the GUI and text mode using sudo systemctl start graphical.target and sudo systemctl start multi-user.target. – Byte Commander Jun 17 '16 at 22:31
  • A "runlevel" doesn't have much meaning in systemd. You should explain what it is you really want to achieve by changing runlevels. – muru Jun 18 '16 at 04:20
  • 5
    To all reviewers This is a valid question! There IS a way to change the runlevel (whether or not it is called "runlevels" or "targets") using systemctl isolate – Ron Jun 18 '16 at 09:09
  • Thanks very much, I understand why people would want me to just be "up to date" with the latest concepts and might be frustrated by my seemingly stubborn question, but I like having all the background information possible. Thanks for seeing what I was asking @Ron and also bringing me up to speed at the same time. – gnomed Jun 20 '16 at 17:47

1 Answers1

78

Ubuntu 16.04 uses systemd instead of init and hence the concept of runlevels is replaced by the term targets. So there is indeed a mapping between init-based runlevels and systemd-based targets:

   Mapping between runlevels and systemd targets
   ┌─────────┬───────────────────┐
   │Runlevel │ Target            │
   ├─────────┼───────────────────┤
   │0        │ poweroff.target   │
   ├─────────┼───────────────────┤
   │1        │ rescue.target     │
   ├─────────┼───────────────────┤
   │2, 3, 4  │ multi-user.target │
   ├─────────┼───────────────────┤
   │5        │ graphical.target  │
   ├─────────┼───────────────────┤
   │6        │ reboot.target     │
   └─────────┴───────────────────┘

Now, to just change the "runlevels" in 16.04, you can use for eg:

sudo systemctl isolate multi-user.target

To make this the default "runlevel", you can use:

sudo systemctl enable multi-user.target
sudo systemctl set-default multi-user.target

From man systemctl

   isolate NAME
       Start the unit specified on the command line and its dependencies and stop all others. If
       a unit name with no extension is given, an extension of ".target" will be assumed.

       This is similar to changing the runlevel in a traditional init system. The isolate command
       will immediately stop processes that are not enabled in the new unit, possibly including
       the graphical environment or terminal you are currently using

Also have a look at man systemd.special to know more about the targets in systemd.

Ron
  • 20,638
  • HI @Ron your response is great I did it in order to install the Nvidia official driver but now my screen doesn't show anything but a blue screen. How can I fix this ? Thanks in advance for your helps. –  Dec 13 '16 at 09:30
  • Enter into recover mode from Grub, then as root revert to the previous runlevel. – LottaLava May 26 '17 at 03:13
  • yeah. I was just going to comment on how the guys giving these extremely nice commands of going from gui boot to text-mode don't care at all about telling us about how to return from text-boot to gui boot. – nyxee Aug 19 '17 at 02:42
  • So, just to note, i run sudo systemctl set-default multi-user.target in the GUI mode, on reboot, I got a blank screen, which was a good sign that GUI had failed to boot, so I pressed Ctrl-Alt-F3 to enter Runlevel 3, did what I needed (installed NVIDIA-CUDA), run sudo systemctl set-default graphical.target and returned to the GUI login screen. But, I have now failed to log in. is that the correct way to revert to the previous runlevel? – nyxee Aug 19 '17 at 03:20
  • 2
    @nyxee - Yes, sudo systemctl set-default graphical.target is the correct way to revert back to the GUI desktop environment. Your login failure sounds unrelated to switching between runlevels - it sounds more like the nVidia boot loop problem. To find out for sure, drop back down to runlevel 3, remove the nVidia and Cuda drivers, install an nVidia driver from the repo, set default to runlevel 5 (graphical.target), then reboot and see if you can log in. – Andy Turfer Aug 23 '17 at 14:41
  • thanks. I had done that but thanks for the confirmation. looks like the whole problem is actually to do with ubuntu-desktop, X11 and unity. So I uninstalled them also. nvidia had actually silently been uninstalled by the system. when i reinstalled it via rep (the best way), i sterted running into networking issues. som removing the ubuntu culprots and using alternative desktop environments was my best option. will have to miss unity and hud. – nyxee Aug 23 '17 at 15:38
  • 1
    Why the command sudo systemctl enable multi-user.target ?? On my system: 20.04 it returns the error The unit files have no installation config ... This means they are not meant to be enabled using systemctl. The other command: sudo systemctl set-default multi-user.target created a symlink which should do the job :) so THX – Thorsten Niehues Feb 18 '21 at 12:12