Setting the Display Resolution on a Virtual Machine

If you install a recent version of Linux on a virtual machine you may find that the default display resolution is rather low. You may be able to select a better resolution (by navigating to systempreferencesmonitors) once you have logged in, but I prefer to configure the display resolution by using xorg.conf.

To generate a new file automatically 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.

# /etc/init.d/lightdm stop
[ 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 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 either reboot or restart the display manager.

# mv xorg.conf.new /etc/X11/xorg.conf
# /etc/init.d/lightdm start
[ ok ] Starting lightdm (via systemctl): lightdm.service.

If it all worked then the display resolution should be set correctly when Xwindows starts.

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

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s