Fix display size on libvirt/Qemu guest

Lot of times I find myself of VM that does not correctly resize the screen display and that is literally nuisance. So, here is quick and dirty fix for this.

First you need to find out information about your display with following command:

xrandr -q

And you will see output like this:

Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
Virtual-0 connected primary 1920×1080+0+0 0mm x 0mm
1024×768      59.92 +
1920×1200     59.88
1920×1080     59.96*
1600×1200     59.87
1680×1050     59.95
1400×1050     59.98
1280×1024     59.89
1440×900      59.89
1280×960      59.94
1280×854      59.89
1280×800      59.81
1280×720      59.86
1152×768      59.78
800×600       59.86
848×480       59.66
720×480       59.71
640×480       59.38
Virtual-1 disconnected
Virtual-2 disconnected
Virtual-3 disconnected

This tells you the currently configured screens and the resolutions. In my case, the only connected screen as seen above is “Virtual-0“. Now, time to do the magic.

You just need to set the correct display/screen size with following command:

xrandr --output Virtual-0 --mode 1920x1200

Also, if you need to add a new resolution, first you need to create a modeline with following command:

cvt 1200 1024

You will get output like :

# 1200×1024 59.82 Hz (CVT) hsync: 63.59 kHz; pclk: 101.75 MHz
Modeline “1200x1024_60.00”  101.75  1200 1280 1400 1600  1024 1027 1037 1063 -hsync +vsync

 

and then set that with:

xrandr --output Virtual-0 --mode 1200x1024

Hope this helps you do away with some really pathetic display sizes in VM 🙂

Install virtual machines in one line

To install a VM from command line, you can use the following command. Change the required parameters as need but you need to change at-least CDROM iso image and disk-path.

virt-install \
    -n myVM \
    --description "Test VM" \
    --os-type=Linux \
        --os-variant=centos7 \
        --ram=2048 \
        --vcpus=2 \
        --disk path=./myVM.img,bus=virtio,size=10 \
        --graphics none \
        --cdrom  <Image installtion CDROM>.iso \
        --net user

Most simple and fast lightweight container with Fedora systemd

If you need to have a quick bash shell in sandbox with not network as well, then the most simple command I could find so far is:

sudo virt-sandbox -c lxc:/// /bin/bash

For this you will need to have libvirt-sandbox installed which you can do with the following command:

sudo yum install libvirt-sandbox