How can I simply change into a text mode runlevel under systemd?
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
norinit ?
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 tographical.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.
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.