Ubuntu 16.04 LTS - how is the X server started?

I have thought that /usr/bin/startx script is used to start the X server but it looks like it is not true. Which process or script starts the X server? The X server has to be started before lightdm greeter is visible but when exactly?


/etc/init.d/lightdm starts the Xserver. Lightdm gets started first then it starts the Xserver. The parent process of the Xserver (Xorg) is lightdm (PID 25600 as shown in example below). You can see this by executing:

ps -ef | grep lightdm

root     25600     1  0 00:50 ?        00:00:00 /usr/sbin/lightdm  
root     25608 25600  2 00:50 tty7     00:00:35 /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch  
root     25686 25600  0 00:50 ?        00:00:00 lightdm --session-child 12 19

Running the following commands will stop and start lightdm and Xserver accordingly:

sudo /etc/init.d/lightdm stop  
sudo /etc/init.d/lightdm start

Boot into a text screen and use startx

If your Ubuntu system boots into a text screen, for example a minimal system or a server system, you can use startx to start xserver (and a simple window manager like openbox or fluxbox or a desktop environment like gnome, kde, lxde, ... xfce).

For example, it is enough to start and use a simple graphical desktop (in a minimal or server system) after three program packages are installed,

sudo apt update
sudo apt install fluxbox xinit xterm

with the command

startx

Boot directly into a graphical desktop

If you have an Ubuntu desktop system (standard Ubuntu or one of the community flavours Kubuntu, Lubuntu, ... Xubuntu), you need not use startx, the graphical desktop environment is started automatically (and you need not run startx). If I understand correctly, it is started via systemd. See for example the following links,

wiki.archlinux.org/index.php/Systemd/User#Xorg_and_systemd

wiki.archlinux.org/index.php/xorg

Switch between text mode and graphic mode

Switching between text mode and graphics mode is described in the accepted answer of the following link

Booting into text mode in 16.04

To boot Ubuntu 16.04 Desktop without X one time, add systemd.unit=multi-user.target to the linux command line in GRUB.

To make this the default, use

sudo systemctl set-default multi-user.target

To return to default booting into X, use

sudo systemctl set-default graphical.target

To see the current default target,

sudo systemctl get-default