Configuring X Windows on a Virtual Machine

When using X windows on a virtual machine I have found that the screen resolution is detected automatically it can often default to a maximum resolution of 1024×768 pixels.

Depending on your system you may be able to select a better resolution (by navigating to systempreferencesmonitors) after logging in but you can configure the default display resolution using /etc/X11/xorg.conf.

On recent versions of Linux assuming that the easiest way to do this is to generate a new file automatically and then modify it. To do this you need to login as root on the console and stop Xwindows (if it is running), how you do this will depend on your system but it will usually involve stopping the display manager which in my case is lightdm as I’m using the MATE desktop.

The following command tries to stop most of the well-known display managers (and redirects any errors to /dev/null so they are not shown on the screen).

# (/etc/init.d/xdm stop||/etc/init.d/kdm stop||/etc/init.d/gdm stop \
> ||/etc/init.d/lightdm stop||/etc/init.d/lxdm stop||/etc/init.d/slim stop) \
> 2>/dev/null
[ ok ] Stopping lightdm (via systemctl): lightdm.service.
#

The next step is to use Xorg to generate a new xorg.conf.

# Xorg -configure
X.Org X Server 1.16.4
Release Date: 2014-12-20
X Protocol Version 11, Revision 0
Build Operating System: Linux 3.16.0-4-amd64 x86_64 Debian
  :
  :
  :
Your xorg.conf file is /root/xorg.conf.new
 
To test the server, run ‘X -config /root/xorg.conf.new’
 
(EE) Server terminated with error (2). Closing log file.
#

This will create new file configuration file in your current directory which should look something like the one below.

Section "ServerLayout"
	Identifier     "X.org Configured"
	Screen      0  "Screen0" 0 0
	InputDevice    "Mouse0" "CorePointer"
	InputDevice    "Keyboard0" "CoreKeyboard"
EndSection

Section "Files"
	ModulePath   "/usr/lib/xorg/modules"
	FontPath     "/usr/share/fonts/X11/misc"
	FontPath     "/usr/share/fonts/X11/cyrillic"
	FontPath     "/usr/share/fonts/X11/100dpi/:unscaled"
	FontPath     "/usr/share/fonts/X11/75dpi/:unscaled"
	FontPath     "/usr/share/fonts/X11/Type1"
	FontPath     "/usr/share/fonts/X11/100dpi"
	FontPath     "/usr/share/fonts/X11/75dpi"
	FontPath     "built-ins"
EndSection

Section "Module"
	Load  "glx"
EndSection

Section "InputDevice"
	Identifier  "Keyboard0"
	Driver      "kbd"
EndSection

Section "InputDevice"
	Identifier  "Mouse0"
	Driver      "mouse"
	Option	    "Protocol" "auto"
	Option	    "Device" "/dev/input/mice"
	Option	    "ZAxisMapping" "4 5 6 7"
EndSection

Section "Monitor"
	Identifier   "Monitor0"
	VendorName   "Monitor Vendor"
	ModelName    "Monitor Model"
EndSection

Section "Device"
        ### Available Driver options are:-
        ### Values: <i>: integer, <f>: float, <bool>: "True"/"False",
        ### <string>: "String", <freq>: "<f> Hz/kHz/MHz",
        ### <percent>: "<f>%"
        ### [arg]: arg optional
        #Option     "HWcursor"           	# [<bool>]
        #Option     "Xinerama"           	# [<bool>]
        #Option     "StaticXinerama"     	# <str>
        #Option     "GuiLayout"          	# <str>
        #Option     "AddDefaultMode"     	# [<bool>]
        #Option     "RenderAccel"        	# [<bool>]
        #Option     "DRI"                	# [<bool>]
        #Option     "DirectPresents"     	# [<bool>]
        #Option     "HWPresents"         	# [<bool>]
        #Option     "RenderCheck"        	# [<bool>]
	Identifier  "Card0"
	Driver      "vmware"
	BusID       "PCI:0:15:0"
EndSection

Section "Screen"
	Identifier "Screen0"
	Device     "Card0"
	Monitor    "Monitor0"
	SubSection "Display"
		Viewport   0 0
		Depth     1
	EndSubSection
	SubSection "Display"
		Viewport   0 0
		Depth     4
	EndSubSection
	SubSection "Display"
		Viewport   0 0
		Depth     8
	EndSubSection
	SubSection "Display"
		Viewport   0 0
		Depth     15
	EndSubSection
	SubSection "Display"
		Viewport   0 0
		Depth     16
	EndSubSection
	SubSection "Display"
		Viewport   0 0
		Depth     24
	EndSubSection
EndSection

To set the screen resolution to one you want to use you need to edit this file and change the screen section.

# nano xorg.conf.new

You need to replace the existing screen section with the one below, changing the display resolution and colour depth as required. In this example the default resolution will be 1440×900 pixels the colour depth will be 24-bit.

Section "Screen"
	Identifier "Screen0"
	Device     "Card0"
	Monitor    "Monitor0"
        DefaultDepth  24
        SubSection "Display"
                Depth     24
                Modes     "1440x900" "1280x800" "1024x768" "800x600"
        EndSubSection
EndSection

You can check these settings by starting Xwindows using the new configuration file but I didn’t bother as all you will get is a blank screen (use Ctrl-Alt-F1 to switch back to the console and Ctrl-C to quit)

# X -config /root/xorg.conf.new
 
X.Org X Server 1.16.4
Release Date: 2014-12-20
X Protocol Version 11, Revision 0
Build Operating System: Linux 3.16.0-4-amd64 x86_64 Debian
Current Operating System: Linux unknown 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1 (2016-12-30) x86_64
Kernel command line: BOOT_IMAGE=/boot/vmlinuz-3.16.0-4-amd64 root=UUID=7534e7ff-2bcc-468b-9b07-645755a785d6 ro quiet
Build Date: 11 February 2015 12:32:02AM
xorg-server 2:1.16.4-1 (http://www.debian.org/support)
Current version of pixman: 0.32.6
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.
Markers: (–) probed, (**) from config file, (==) default setting,
        (++) from command line, (!!) notice, (II) informational,
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: “/var/log/Xorg.0.log”, Time: Thu Jun 8 12:11:27 2017
(++) Using config file: “/root/xorg.conf.new”
(==) Using system config directory “/usr/share/X11/xorg.conf.d”
^C(EE) Server terminated successfully (0). Closing log file.
#

To make these changes permanent move the configuration file to the correct folder and reboot.

# mv xorg.conf.new /etc/X11/xorg.conf
# reboot

If it all worked then the display resolution should be set when the X server starts.

If it doesn’t work or you still don’t get the screen resolution that you expected you can try using the vesa driver instead of the vmware driver. To do this you need to modify /etc/X11/xorg.conf again.

# nano /etc/X11/xorg.conf

Then you need to modify the following line in the device section.

	Identifier  "Card0"
	Driver      "vmware"

When you have finished it should look like this.

	Identifier  "Card0"
	Driver      "vesa"

Then reboot again..

This entry was posted in CentOS, Debian, Linux, Raspbian, RedHat, Ubuntu, Virtualisation and tagged . Bookmark the permalink.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.