Updated on 2024-06-21 GMT+08:00

How Can I Install a GUI on an ECS Running Ubuntu?

Scenarios

To provide a pure system, the ECSs running Ubuntu do not have a GUI installed by default. You can install a GUI on such ECSs as needed.

For GPU-accelerated ECSs, after installing a GUI, you need to configure X Server, x11vnc, and lightdm to make sure that:

  • The graphics system and VNC server are automatically started upon the ECS startup.
  • Applications can invoke GPUs properly after a remote login using VNC.

You can perform the following steps to install a GUI on an Ubuntu ECS:

Constraints

  • This document applies to ECSs running Ubuntu 16.04, 18.04, and 20.04.
  • The Ubuntu ECS must have an EIP bound or have an intranet image source configured.
  • Before installing a GUI on an ECS, ensure that the idle memory is greater than or equal to 2 GB. Otherwise, the GUI installation may fail or the ECS cannot be started after the installation.
  • GPU-accelerated ECSs must have a correct GPU driver installed. For details, see GPU Driver.

Installing a GUI

  1. Log in to the ECS and install a GUI desktop environment.
    1. Run the following command to update the software library:

      apt-get update

    2. Run the following command to install the Ubuntu GUI desktop component:
      • For Ubuntu 16.04, run the following command:

        apt-get install -y scite xorg xubuntu-desktop

      • For Ubuntu 18.04 and 20.04, run the following command:

        apt-get install -y ubuntu-desktop

  2. Run the following command to edit the root/.profile file:

    vim /root/.profile

    Press i to enter the editing mode and change mesg n || true in the last line to tty -s && mesg n || true. After the modification, the file content is as follows:

    # ~/.profile: executed by Bourne-compatible login shells.
     
    if [ "$BASH" ]; then
      if [ -f ~/.bashrc ]; then
        . ~/.bashrc
      fi
    fi
    tty -s && mesg n || true
  3. Press Esc to exit editing mode.
  4. Run the following command to save and exit the configuration file:

    :wq

  5. (Mandatory for Ubuntu 20.04) Add a member account.

    After GUI desktop component is installed on the ECS, you cannot log in to the Ubuntu 20.04 OS as user root user. You need to add a member account for logging in to the GUI desktop.

    Run the following command to add user user01:

    adduser user01

    Set a password for user01 as prompted.

    Adding user `user01' ...
    Adding new group `user01' (1001) ...
    Adding new user `user01' (1001) with group `user01' ...
    Creating home directory `/home/user01' ...
    Copying files from `/etc/skel' ...
    New password: 
    Retype new password: 
    passwd: password updated successfully

    Set information about user01. You can press Enter to skip the setting. Then the system prompts you to check whether the entered information is correct.

    Enter Y.

    Changing the user information for user01
    Enter the new value, or press ENTER for the default
            Full Name []: 
            Room Number []: 
            Work Phone []: 
            Home Phone []: 
            Other []: 
    Is the information correct? [Y/n] Y
  6. Run the reboot command to restart the ECS.
  7. Log in to the ECS using VNC provided on the management console and log in to the GUI desktop using the member account created in 5 or the root account.

(Optional) Configuring X Server, x11vnc, and ligthdm

For GPU-accelerated ECSs, you need to configure X Server, x11vnc, and ligthdm when installing a GUI.

  1. Remotely log in to the ECS.
  2. Query the BusID of the GPU.

    lspci | grep -i nvidia

    Figure 1 GPU's BusID
  3. Generate the X Server configuration.

    nvidia-xconfig --enable-all-gpus --separate-x-screens

  4. Configure the GPU's BusID in "Section Device" in the generated /etc/X11/xorg.conf.
    1. Edit /etc/X11/xorg.conf.

      vi /etc/X11/xorg.conf

    2. Press i to enter editing mode.
    3. Add the GPU's BusID in "Section "Device".
      Figure 2 Adding the GPU's BusID

      The BusID queried in step 2 is a hexadecimal number. You need to convert it to a decimal number before adding it to "Section Device" in /etc/X11/xorg.conf.

      1. For example, the queried BusID is 00.0d.0 (a hexadecimal number) and needs to be converted to PCI:00:13:0 (a decimal number).
    4. Press Esc to exit editing mode.
    5. Run the following command to save and exit the configuration file:

      :wq

  5. Install x11vnc.

    apt-get -y install x11vnc

  6. Install ligthdm.

    apt-get -y install lightdm

  7. Select ligthdm as the default display manager.
    Figure 3 Selecting a display manager
  8. Configure the GUI desktop environment to automatically start upon ECS startup.

    systemctl set-default graphical.target

  9. (Optional) Configure the x11vnc to automatically start upon ECS startup.
    1. Add the /lib/systemd/system/myservice.service file.

      vi /lib/systemd/system/myservice.service

    2. Press i to enter editing mode.
    3. Add the following content to the file:
      [Unit]
      Description=My Service
      After=network.target lightdm.service
      
      [Service]
      Type=oneshot
      ExecStart=/usr/bin/x11vnc -forever -loop -noxdamage -repeat -rfbport 5902 -shared -bg -auth guess -o /var/log/vnc.log
      
      [Install]
      WantedBy=multi-user.target
      Alias=myservice.service
    4. Press Esc to exit editing mode.
    5. Run the following command to save and exit the configuration file:

      :wq

  10. Load configuration files.

    systemctl daemon-reload

    systemctl enable myservice.service

  11. Run the reboot command to restart the ECS.

(Optional) Verifying Drivers on GPU-accelerated ECSs

After installing a GUI on a GPU-accelerated ECS, perform the following operations to check whether the driver is working properly:

  1. Log in to the management console.
  2. Configure a security group for the ECS.
    1. On the ECS list, click the name of an ECS for which you want to configure the security group rule. On the ECS details page, click Security Groups.
    2. Expand the security group and in the upper right corner of the security group rule list, click Modify Security Group Rule.
    3. On the Inbound Rules page, click Add Rule.
    4. In the Add Inbound Rule dialog box, follow the prompts to add the following security group rule:

      Allow inbound access through TCP port 5902. The port number is determined by the rfbport parameter in step 9.c.

  3. Log in to the ECS using VNC.

    The following uses TightVNC as an example.

    Figure 4 TightVNC client
  4. Right-click on the blank area and choose Open in Terminal from the shortcut menu.
  5. Run the following command on the terminal. If the graphics card information is displayed as follows, the driver is working properly.

    nvidia-settings

    Figure 5 Graphics card information

    If a GPU-accelerated ECS has a GRID driver installed, you need to configure a license to use the GPU rendering capability. For details, see Installing a GRID Driver on a GPU-accelerated ECS.