@@ -82,6 +82,62 @@ def optionally_disable_rnd
8282 end
8383 end
8484
85+ # Disable Wayland in GDM to ensure Xorg is used
86+ # This is required for Ubuntu 22.04+ where Wayland is the default
87+ # Without this, GDM won't start Xorg on headless GPU instances
88+ def disable_wayland
89+ bash 'Disable Wayland in GDM' do
90+ user 'root'
91+ code <<-DISABLEWAYLAND
92+ set -e
93+ if [ -f /etc/gdm3/custom.conf ]; then
94+ sed -i 's/#WaylandEnable=false/WaylandEnable=false/' /etc/gdm3/custom.conf
95+ # If the line doesn't exist at all, add it under [daemon] section
96+ if ! grep -q "^WaylandEnable=false" /etc/gdm3/custom.conf; then
97+ sed -i '/\\ [daemon\\ ]/a WaylandEnable=false' /etc/gdm3/custom.conf
98+ fi
99+ fi
100+ DISABLEWAYLAND
101+ end
102+ end
103+
104+ # Override allow_gpu_acceleration to disable Wayland before starting X
105+ def allow_gpu_acceleration
106+ # Update the xorg.conf to set up NVIDIA drivers.
107+ # NOTE: --enable-all-gpus parameter is needed to support servers with more than one NVIDIA GPU.
108+ nvidia_xconfig_command = "nvidia-xconfig --preserve-busid --enable-all-gpus"
109+ nvidia_xconfig_command += " --use-display-device=none" if node [ 'ec2' ] [ 'instance_type' ] . start_with? ( "g2." )
110+ execute "Set up Nvidia drivers for X configuration" do
111+ user 'root'
112+ command nvidia_xconfig_command
113+ end
114+
115+ # dcvgl package must be installed after NVIDIA and before starting up X
116+ # DO NOT install dcv-gl on non-GPU instances, or will run into a black screen issue
117+ install_dcv_gl
118+
119+ # Disable Wayland to ensure GDM starts Xorg
120+ disable_wayland
121+
122+ # Configure the X server to start automatically when the Linux server boots and start the X server in background
123+ bash 'Launch X' do
124+ user 'root'
125+ code <<-SETUPX
126+ set -e
127+ systemctl set-default graphical.target
128+ systemctl isolate graphical.target &
129+ SETUPX
130+ end
131+
132+ # Verify that the X server is running
133+ execute 'Wait for X to start' do
134+ user 'root'
135+ command "pidof X || pidof Xorg"
136+ retries 10
137+ retry_delay 5
138+ end
139+ end
140+
85141 def post_install
86142 # ubuntu-desktop comes with NetworkManager. On a cloud instance NetworkManager is unnecessary and causes delay.
87143 # Instruct Netplan to use networkd for better performance
0 commit comments