1 Overview

This lab will step you through the following:

2 Remove your VM in virt-manager

2.1 Open virt-manager

If you closed the virt-manager GUI tool for managing VMs, but your X Window Desktop is still available, then in an xterm type:

$ virt-manager

If you have closed your X Window Desktop then run your TigerVNC client again and connect to:

10.10.0.241:1

to re-open the Desktop.

If you have stopped the vnc-server software on your MacMini follow the instructions in the prior exercises to start vnc-server, run TigerVNC, open virt-manager from an xterm.

2.2 Remove your virtual machine

In the virt-manager interface right click on your VM and select "Delete". When prompted to confirm deletion cick the "Delete" button and this will remove your VM's XML definition file as well as the physical qcow2 backing store file for your VM.

This is the same as completely destroing a real server, so always be careful when doing this.

2.3 Create a new virtual machine gold.ws.nsrc.org

Now go to your xterm window and let's create a new virtual machine, but this time we will call it "gold.ws.nsrc.org". In your xterm window type:

$ cd
$ sudo vmbuilder kvm ubuntu --hostname gold.ws.nsrc.org --mem 512 --debug --rootsize 20480 --dest /data/vm/gold.ws.nsrc.org

This will take a bit to complete the building of your new virtual machine. You should see gold.ws.nsrc.org appear in your virt-manager window as well.

2.4 Clone gold.ws.nsrc.org as host1.ws.nsrc.org

Once vmbuilder completes we are going to use a script to make a copy of the original virtual machine (known as "cloning"). This script does a number of things, including:

First let's see how our VM cloning script works:

$ cd /home/nsrc/workshop-kit
$ scripts/clonevm.sh

You should see:

Usage: scripts/clonevm.sh <source> <clone-as> [target-dir [bridge]]
Then use 'virsh start <clone-as>' to run it

If you do not specify "[target-dir]" your new virtual machines data file will be written to /data/vm/.

If you do not specify "[bridge]" your virtual machine will attach to the br-lan network interface and be on your network backbone, or the 10.10.0.0/24 address range.

To clone gold.ws.nsrc.org as host1.ws.nsrc.org you can simply do:

$ scripts/clonevm.sh gold.ws.nsrc.org host1.ws.nsrc.org

This will be quick. You now have a new VM called host1.ws.nsrc.org with it's data file in /data/vm and attached to the backbone br-lan network interface. In your virt-manager GUI you will see host1.ws.nsrc.org appear.

2.5 Make a change to host1.ws.nsrc.org

Either in your virt-manager GUI highlight the host1.ws.nsrc.org VM and Run the machine and open a console to the VM, or on the command line in an xterm you can do:

$ virsh start host1.ws.nsrc.org
$ virsh console host1.ws.nsrc.org

You might need to press once, then log in to the virtual machine as user "sysadm" and class password and do the following:

$ sudo mkdir /hello
$ ls /

You should see the hello directory listed at the root level of your virtual machine.

2.6 Clone the gold.ws.nsrc.org VM again to host1.ws.nsrc.org

First exit from your virtual machine's console. In the virtual machine type:

$ exit

Then do one of these options depening on if you are using virt-manager or the xterm:

At the command line in your xterm let's clone the gold.ws.nsrc.org VM again:

$ cd /home/nsrc/workshop-kit
$ scripts/clonevm.sh gold.ws.nsrc.org host1.ws.nsrc.org

You'll be asked to remove the data file for the host1.ws.nsrc.org VM:

rm: remove write-protected regular file '/data/vm/gold.ws.nsrc.org/host1.ws.nsrc.org.qcow2'? y

Respond with "y" to continue. You should notice that host1.ws.nsrc.org shows up in virt-manager as "Shutoff" even though it was "Running" before you ran the clonvevm.sh script.

Now in virt-manager let's start host1.ws.nsrc.org and open a console to the VM, then log in on host1.ws.nsrc.org as user sysadm. In the console type:

$ ls /

Do you see the "/hello" directory? You should not. The clonvem.sh script removed the data file for the prior host1.ws.nsrc.org virtual machine and created an entirely new machine in its place, but with the same hostname.

3 Bulk cloning of VMs

Making VMs in bulk is now just a question of having a script which clones the gold master multiple times, and we have one already written.

Have a look at the script and then run it:

$ cd /home/nsrc/workshop-kit
$ cat scripts/clone-hosts.sh

... look at the last line which is a loop calling clonevm.sh

$ scripts/clone-hosts.sh

It should clone 40 virtual machines. Now you can start them, either in virt-manager or using virsh.

By looking at the clone-hosts.sh script, can you work out how to use a loop in the shell to start all 40 machines?