26

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?

  • 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
  • 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
  • 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 9:09
49

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.

  • 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. – Raphael Teubner Dec 13 '16 at 9:30
  • Enter into recover mode from Grub, then as root revert to the previous runlevel. – LottaLava May 26 '17 at 3: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 2: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 3: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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.