Installation

Assuming you just did a clean installation of Ubuntu 20.04 in your server, we are going to install xen hypervisor. To be noted, you need to use lvm to manage your server’s hard disks when you install ubuntu 20.04.

Configure the network

Ubuntu 20.04 uses netplan to manage the network. There are two things in particular needs to be considered. First, a server usually has more than one ethernet port (in this case, there are four), ubuntu 20.04 tries to wait all the ports to be configured using DHCP. Three ports are not connected to cables, so minutes of time were wasted on waiting. Make ethernet ports which are not used optional can speed up the start process. Second, we need to create a bridge to make the ip addresses in your physical local network assigned to virutal machines. So you can access to any virtual machine from other devices in your local network. For example, if your network uses ips range like 192.168.0.0-255, your virtual machine will get ip like 192.168.0.101.

Edit /etc/netplan/00-installer-config.yaml

network:
  ethernets:
    eno1:
      dhcp4: true
    eno2:
      dhcp4: true
      optional: true
    eno3:
      dhcp4: true
      optional: true
    eno4:
      dhcp4: true
      optional: true
  bridges:
    xenbr0:
      dhcp4: true
      interfaces:
        - eno1
  version: 2

Apply the configuration

netplan apply

Install xen-hypervisor-amd64

apt-get update && apt-get upgrade -y && apt-get install -y xen-hypervisor-amd64
# After the installation has been finished, reboot your server.
reboot

Increase host’s disk space

Ubuntu 18.04 by default allocated very small amount of disk space to the host (or host domain, Domain-0), you probably want to increase your host’s disk space by allocating more space using lvm.

lvresize -L 20G /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

Maintenance

Take a snapshot of a lvm disk

lvcreate -L592M -s -n backup /dev/ubuntu-vg/xen-xxx-disk
mount /dev/ubuntu-vg/backup /data/backup

Backup and compress disk of virtual machine

dd if=/dev/ubuntu-vg/xen-xxx-disk | gzip --fast > /backup/disk.gz

Recover disk of virtual machine

zcat /backup/disks/disk.gz > /dev/ubuntu-vg/xen-xxx-disk

Reference

  • https://blog.ubuntu.com/2017/12/01/ubuntu-bionic-netplan
  • https://netplan.io/examples
  • https://www.howtoforge.com/perfect_xen_setup_debian_ubuntu_p6
  • https://www.jethrocarr.com/2013/11/23/restoring-lvm-volumes/
  • https://www.tecmint.com/manage-and-create-lvm-parition-using-vgcreate-lvcreate-and-lvextend/
  • http://tldp.org/HOWTO/LVM-HOWTO/snapshots_backup.html