How can I simply change into a text mode runlevel under systemd?

17,488

Solution 1

If you just need to switch to text mode with no GUI stuff like the X server running, you can use systemctl to get your machine to the so-called multi-user.target:

sudo systemctl start multi-user.target

You revert this and get back to the desktop (graphical.target) by either rebooting or by switching back manually in the same way as above:

sudo systemctl start graphical.target

If you really need a true runlevel change to 3, that can be done using the init command, as @terdon pointed out in his comment:

sudo init 3

You can verify your current runlevel with the runlevel command. It will output two letters: the left one is your previous runlevel, whereas the right one represents your current runlevel.

You go back to the desktop by setting the runlevel to 5 again:

sudo init 5

Important general notes for both methods:

  • Both switching to multi-user.target or runlevel 3 will terminate the X server and kill all GUI applications and your desktop environment. Make sure you closed all sensible applications and saved your work before you start, otherwise their state will be lost!

  • Neither systemctrl start ???.target nor init ? do switch your active TTY. That means, if you run these commands from a terminal emulator on your desktop (normally on TTY7), you will be at a black screen afterwards (optionally with some debug output).

    It's simply because the TTYs 8-12 are not connected to text consoles but reserved for video consoles to display GUIs. Only TTY 1-7 are text consoles.

    So to operate in multi-user.target or on runlevel 3, you have to switch to a text console TTY, e.g. by pressing Ctrl+Alt+F1 for TTY1. You get back to the desktop (TTY7) later after you returned to graphical.target or runlevel 5 by pressing Ctrl+Alt+F7 respectively.

    When you get to such a text console, note that you have to log in again first by typing your username and password as requested.

Solution 2

To solve your task, you might as well reboot into recovery mode, which is text-based and will address your need.

Turn off the machine and hold down "Shift" will booting. A Grub menu will appear. Usually the second option is what you want, labeled "Advanced" or "Recovery". This should boot you to a text based menu. Select the option for a root shell.

Do you want you need to do.

If you found the drives are mounted read-only, you can remount the root read-write:

mount -o remount,rw /

Enter "exit" as your last shell command. You'll be returned to the menu, where you can select "Resume booting".

Considering how fast machines boot from SSDs, this approach will be competitively fast with using systemd isolate to switch in and out of a graphical environment.

Share:
17,488

Related videos on Youtube

sharkant
Author by

sharkant

i like White chocolate with almonds from ALDI, vangelis, hong kong Pop Music from the 80s and early 90s, star trek the classic series, blue led lights at night. I dislike social pressure, being not as intelligent and good looking as i wished to be, the headache and Tinnitus i suffer from 24/7. I am a White male from Germany, suffering from agoraphobia, bound to a Limit of locomotion within a radius of about 1 km , but it depends on specific environmental Features. i am a single, i have a few friends, but i am alone most of the time.

Updated on September 18, 2022

Comments

  • sharkant
    sharkant over 1 year

    I have got ubuntu 16.04 installed with the systemd. I need to install a cuda toolkit from nvidia, but I can only install it from runlevel 3.

    Now I have found some answers here, but none of them worked. e.g.:

    • echo "manual" | dd of=/etc/init/lightdm.override

      I was told this makes me select the runlevel on start

    • systemctl isolate runlevel3.target

      Here, I was told it changes into runlevel 3 without booting, but it simply made the display pitch black.

    • terdon
      terdon about 7 years
      I assume you really need to change runlevel, not simply get a CLI login screen, right? I mean, you know about Ctrl+Alt+F1 and that's not what you need?
    • sharkant
      sharkant about 7 years
      i do not know what ctrl+alt+f1 makes, it is some magical place, which looks like a pure text console, but when i type "runlevel" it tells me it is still in runlevel 5.
    • terdon
      terdon about 7 years
      heh, yes pretty much. That's just a "tty", it lets you start a new session but only using the CLI. To get back to the GUI, press Ctrl+7. Will that do or do you still need to change the actual run level? And I'm on mobile now so I can't test, but doesn't sudo init 3 work with systemd?
    • sharkant
      sharkant about 7 years
      sudo init 3 works in so far as it makes my display full black without any text,
    • sharkant
      sharkant about 7 years
      i tried to install the cuda-toolkit in the ctrl+alt+f1-world, but i got an error message, that the x-server is still running.
    • Byte Commander
      Byte Commander about 7 years
      @terdon It's the right command, it just does not switch TTYs from the desktop one to a working text console. Therefore the black screen. I posted a detailed answer.
  • sharkant
    sharkant about 7 years
    i am not sure if i understood this right. i pressed ctrl+alt+f1 to get into this tty1 and once i was there i evoked systemctl start multi-user.target, but the display still went dark...
  • Byte Commander
    Byte Commander about 7 years
    And if you press ctrl+alt+f1 again after that? Just in case you somehow jumped back to TTY7 when the X server there exited? Otherwise there might be a graphics problem, no idea.
  • sharkant
    sharkant about 7 years
    i understood it this way: the x-server is this thing that creates graphic applications and some terminals are graphic applications too even though they look like text applications. if i initialize runlevel 3 or multi-user.target from them it gets dark, because i ve killed the parent from where i evoked it. so i have to go to some place which looks like one of those terminal but which is not a child of x-server, and i understood that the terminal which i enter by pressing ctrl+alt+f1 is such a terminal, one which is still there after x-server is gone.
  • sharkant
    sharkant about 7 years
    but i went into this tty1, typed systemctl start multi-user.target and it still got dark
  • Byte Commander
    Byte Commander about 7 years
    @sharkant Sorry to say, but it works for me, I can't reproduce the issue you describe. Maybe it helps if you boot into text mode instead of manually switching there later - see askubuntu.com/q/788323/367990 for more info.
  • sharkant
    sharkant about 7 years
    thanks, you helped me to understand, that i have to kill the x-server from tt1-tt6