如何在 Ubuntu 中启用或禁用 GUI

如何在 Ubuntu 中启用或禁用 GUI

Say if I wanted to replicate Ubuntu Server and have no GUI running what would I do to make this happen? Upon running htop/top from tty session I see both gnome and xorg are still running and sucking up quite a substantial amount of memory (I'm using VirtualBox and have 1024MB allocated to Ubuntu). I would preferably want the ability to disable/stop gnome and Xorg whenever I wish in order to free resources. I don't see any point in switching to tty from Xorg and keeping the processes running. I would however like to have the ability to re-enable/start the necessary files upon leaving tty. I do not want things to be permanently disabled although having this option would be useful/

Any help? Thanks

答案1

You can use systemctl to "isolate" targets, which is to some extend similar to switching runlevels. The targets of interest here are

  • graphical.target

  • multi-user.target

Confusingly, graphical.target is the default target in both Ubuntu desktop and server, but since there is no display manager installed in server it's essentially the same as multi-user.target.

Switch while Ubuntu is running

Switch to "text mode" (you can simply run this in e.g. gnome-terminal):

sudo systemctl isolate multi-user.target

Switch to "graphical mode":

sudo systemctl isolate graphical.target

Set boot target

You can set the default target that is reached after boot (persists across reboot), e.g.:

sudo systemctl set-default multi-user.target

You can also set a target with the kernel parameter systemd.unit, e.g.

systemd.unit=multi-user.target

The kernel parameter has precedence over the default target.

This can be used to boot to a specific target once by editing the grub boot entry before boot. Or you could add multiple boot entries for different targets.

答案2

You can use systemctl(the systemd system and service manager) to control your display manager. In the case of Ubuntu, this is GDM - Gnome Display Manager, SDDM and LightDM are other common display managers.

To check the status from the command line:

sudo systemctl status gdm

To stop:

sudo systemctl stop gdm

To start:

sudo systemctl start gdm

To disable (prevent loading at system startup):

sudo systemctl disable gdm

To enable (loading at system startup):

sudo systemctl enable gdm

答案3

Another way of achieving this is to edit the line beginning with the linux command on your grub entry and add the number 3 at the end to boot in runlevel 3 which won't start x-server at all by default.

It should look something like this :

 linux  /boot/vmlinuz-5.3.0-46-generic root=UUID=SOME_UUID ro quiet splash 3

This has the same result as others have pointed out , but you can change it even before the system boots up.

在 grub 菜单中,按下菜单项e上的按钮,在行末ubuntu输入 后,按下即可启动。请注意,这不会为您保存此配置。如果要保存它,您必须编辑文件。(如果您无法在启动屏幕上获取 grub 菜单,则会出现这种情况,因为例如 grub 的超时设置为零。)3Ctrl+x/boot/grub/grub.cfg

另一个选择是安装Ubuntu 服务器它根本没有 GUI。除非你有理由坚持使用桌面版。(例如,桌面版默认安装了更多工具,如 g++)。

相关内容