- How to Switch Between CLI and GUI on Linux Server
- Init-based Run Levels in Linux
- Change Init-Based Run Levels in Linux
- Set A Default Init Run Level
- Systemd-Based Boot Target In Linux
- Switching Boot Targets Between CLI and GUI in Linux
- Set A Default SystemD Target in Linux
- Keyboard Shortcut To Switch Between CLI and GUI
- Как запустить графическую оболочку Ubuntu
- Запуск графической оболочки Ubuntu
How to Switch Between CLI and GUI on Linux Server
If we trace the evolution of computers, we can see that initially, we don’t have Mouse. So, we used to interact with computers having Command Line Interface (CLI) only through keyboards passing inputs to perform actions via command line program.
As progressed, now we can easily interact and perform actions via a graphical user interface (GUI) that provides various menus like windows, and buttons. Nowadays people are more inclined and used to GUI-based OS.
Altogether, the computer now comes with an option to work either in the command line or graphical mode. Further, you can also start GUI from the command line and CLI from graphical mode, whichever suits your requirement.
In this article, we’ll see how can we switch between the command line and the graphical interface on Linux Server. But before that, let’s also get an overview of the concept that actually makes changing GUI to CLI and CLI to GUI work.
Init-based Run Levels in Linux
In Linux with an init system manager, the run level defines the operating state of the init process and the whole system and indicates system services that are running.
When the Linux Kernel boots, the init process is the first thing that gets started, and further, it leads to the initialization of other Linux processes.
The moment the init process begins it looks for the value of the default run level of the system. Run level i.e. state of the system is represented in a single-digit integer.
The Standard Linux kernel supports the following seven different run levels:
- 0 – Halt the system
- 1 – Single user mode
- 2 – Multiple user mode with no network file system
- 3 – Multiple user mode under CLI
- 4 – User-definable
- 5 – Multiple user mode under GUI
- 6 – Reboot
By default, if a system has a desktop environment like GNOME or KDE, it boots to graphical run level 5, or else the command line run level 3.
That is why by simply changing the run level of the system you can switch between user interfaces.
Change Init-Based Run Levels in Linux
If you want to know the current run level of your system it is running, type:
To switch to CLI from GUI, change the run level to 3 by running:
Enter and password and you’ll be redirected to the command line mode where you need to log in again.
Likewise, if you want to come back to GUI from CLI, type the following in the command line:
Set A Default Init Run Level
Want to boot your system directly to the command line at startup? You need to make run level 3 as default by modifying the following line in the /etc/inittab file (you’ll not find this file in Linux with Systemd system manager):
Similarly, replace 3 with 5 to make GUI as default run level in Linux.
Systemd-Based Boot Target In Linux
Currently, the majority of Linux distributions have already replaced the old init system with the modern systemd system manager. Hence, instead of the runlevel concept, we need to use the Systemd-based target concept to switch between CLI and GUI in Linux.
Similar to runlevel 3 for CLI and runlevel 5 for GUI, systemd has a corresponding target multi-user.target for CLI and graphical.target for GUI.
By executing the below command, you can list all systemd active targets:
$ systemctl list-units --type target
Switching Boot Targets Between CLI and GUI in Linux
Now, to change the target manually or switch to command line mode from GUI, you can use the systemctl command with isolate subcommand in the given below format:
$ sudo systemctl isolate multi-user.target
To switch back to GUI from command line mode, specify graphical.target with the command:
$ sudo systemctl isolate graphical.target
Set A Default SystemD Target in Linux
As you boot the Linux system, it loads the default target. So, you can identify the current default target using the systemctl command along with the get-default subcommand:
$ sudo systemctl get-default
And to change the current target and set it as default for all next boot, use the set-default option with multi-user.target for CLI or graphical.target for GUI as argument:
$ sudo systemctl set-default multi-user.target [For CLI] $ sudo systemctl set-default graphical.target [For GUI]
Next, reboot the system to apply the default target:
Keyboard Shortcut To Switch Between CLI and GUI
If you already have a desktop environment on your Linux system, you can also switch between your graphical desktop and command line text mode by simply pressing CTRL + ALT + N . Here Replace N with numbers 1 to 7.
Linux has by default six text terminals and one graphical terminal. So, to switch to command line mode, you can press CTRL + ALT + F1/F2/F3/F4/F5/F6 and switch back to the graphical mode by pressing CTRL + ALT + F7 .
Keyboard Shortcut is only helpful temporarily as we cannot use it set the default mode for permanent the way we can in the above Init or Systemd-based methods.
Conclusion
Though GUI is the most prevalent way of using Linux systems, CLI is still relevant as it helps in troubleshooting if GUI fails or system resources is too less to support GUI.
That is why it’s worth knowing how we can switch between graphical and command modes and also set either as default. As we learned, this can be done in various ways like by the modern way of changing the boot target in systemd, Keyboard shortcuts, and legacy init system manager.
Как запустить графическую оболочку Ubuntu
Если вы запустили систему в текстовом режиме или вовсе это сервер и на нём надо работать только через терминал, но на нём уже есть установлено графическое окружение, есть несколько способов его запустить.
В этой статье мы постараемся разобраться как запустить графическую оболочку Ubuntu из терминала несколькими способами.
Запуск графической оболочки Ubuntu
Сначала можно посмотреть текущий уровень запуска в systemd. Для этого выполните:
systemctl list-units —type target | egrep «eme|res|gra|mul» | head -1
Если уровень запуска не graphical.target вы можете это исправить выполнив команду:
sudo systemd isolate graphical.target
После этого уровень запуска будет изменён на графический и графическая оболочка запуститься автоматически. Если вам нужно запустить менеджер входа вручную выполните такую команду:
sudo systemctl start display-manager
Эта команда запустит менеджер входа в систему, после этого вы сможете ввести логин и пароль, а затем запуститься графическая оболочка.
С более простыми графическими оболочками, вроде Openbox, Fluxbox, i3wm и даже XFCE может сработать ещё один метод, очень популярный ранее. Это команда startx. Однако чтобы она сработала в файле ~/.xinitrc надо прописать оболочку, которую вы хотите запустить. Например:
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
[ -x «$f» ] && . «$f»
done
unset f
fi
feh —bg-fill ~/Загрузки/52453-sklon_holm_cerkvushka_sneg.jpg &
lxpanel &
exec openbox-session
Блок if загружает все конфигурационные файлы из каталога /etc/X11/xinit*, сторчка, начинающаяся с feh добавляет фон рабочего стола, следующая — нижнюю панель, а последняя запускает сам openbox. Теперь запуск графической оболочки Ubuntu из консоли выполняется командой:
Или если, на первом экране уже что-то запущено, можно использовать любой другой доступный, например, второй:
Обратите внимание, что оболочку можно запустить только из консоли TTY, из терминала в графическом окружении это не сработает. Как видите, всё просто. Ваша оболочка запуститься в том же терминале, в котором вы выполнили startx.
Обнаружили ошибку в тексте? Сообщите мне об этом. Выделите текст с ошибкой и нажмите Ctrl+Enter.