reset password

Set Up Ubuntu Server to Host VMs

Download and install Ubuntu Server 16.04 LTS. During installation, select the following options:

  • Mail Server
  • Standard System Utilities
  • Virtual Machine Host
  • OpenSSH Server

After installation, use apt-get to install the following packages:

  • virtinst
  • libosinfo-bin

1. Create a Virtual Machine

Download an ISO image, e.g.

>  wget http://releases.ubuntu.com/16.04.4/ubuntu-16.04.4-server-amd64.iso

Create a config file like sd2018-ubuntu-server.cfg which specifies the parameters of the VM. Run the script createvm.sh to create the VM. For example:

> createvm.sh sd2018-ubuntu-server.cfg

The VM tool will create a VNC session to provide a GUI so we can complete the installation of the guest OS. First, open another terminal and run the following command to find out the port of the VNC session:

> virsh dumpxml <name> | grep vnc

where <name> is the name of the VM specified in the config file. And then, connect to the VNC session using a VNC viewer (e.g. TightVNCfrom a different computer -- we need a GUI to run a VNC viewer, and the Ubuntu Server we use to host VMs does not have one. After the OS installation is completed, the VM will be restarted, and you can connect to it at the same port using VNC.

2. Clone More VMs

Once a VM is created, it's easy to clone more VMs with the same configuration using virt-clone. For example:

> virt-clone --original sd2018-ubuntu-server --name sd2018-ubuntu-server-1 --file /mnt/disk2/vm/sd2018-ubuntu-server-1.qcow2

The first argument is the name of the original VM -- note that this VM must be stopped before it can be cloned. The second argument is the name of new VM, and the third argument is the VM image file to be created (qcow2 is the VM image file format).

3. Manage VMs

VMs can be managed using virsh. Here are some common virsh commands:

virsh list --all List all VMs
virsh list List the running VMs
virsh start|shutdown|suspend|reboot <name> Start, stop, suspend, or reboot a VM
virsh autostart <name> Automatically starts a VM at boot
virsh dumpxml <name> Display the information of a VM in XML format
virsh help List all virsh commands
virsh help <command> Display the information of a virsh command

 

 

This page has been viewed 14825 times.