7

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
  • 100,812
sharkant
  • 1,311
  • 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? – terdon Apr 06 '17 at 22:45
  • 1
    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. – sharkant Apr 06 '17 at 22:48
  • 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? – terdon Apr 06 '17 at 22:51
  • sudo init 3 works in so far as it makes my display full black without any text, – sharkant Apr 06 '17 at 23:00
  • 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. – sharkant Apr 06 '17 at 23:01
  • @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. – Byte Commander Apr 06 '17 at 23:21

2 Answers2

6

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.

Byte Commander
  • 107,489
  • 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... – sharkant Apr 06 '17 at 23:31
  • 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. – Byte Commander Apr 06 '17 at 23:35
  • 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 Apr 06 '17 at 23:39
  • but i went into this tty1, typed systemctl start multi-user.target and it still got dark – sharkant Apr 06 '17 at 23:40
  • @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 http://askubuntu.com/q/788323/367990 for more info. – Byte Commander Apr 06 '17 at 23:46
  • thanks, you helped me to understand, that i have to kill the x-server from tt1-tt6 – sharkant Apr 06 '17 at 23:47
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.