Virtualization in Grid'5000
Purpose
This page presents ways to use KVM on production image. The aim is to permit the execution of virtual machines on the nodes with a "non-deploy" reservation.
First steps
Job submission
In order to test easily the kvm environment, we will use an interactive job.
Disk image, virtual machine
A disk image containing debian squeeze is available at the following path:
/grid5000/images/KVM/squeeze-x64-base.qcow2
It can be use as a base for more advanced work. For the next steps of this tutorial, copy the disk image to /tmp on the node
Network configuration
In order to use the network with kvm, a Tun/Tap interface must be created for each virtual machines. This virtual interface will be attached to your virtual machine, and bridged on the production network. Therefore, the virtual machine will be able to get an IP from the DHCP server and access the network.
A script is available to create automatically this interface on the node:
create_tap
:
- Tun/Tap interfaces are listed by issuing the command
/sbin/ifconfig
.
tap0 Link encap:Ethernet HWaddr 00:16:3e:db:c6:41 inet6 addr: fe80::58ff:a4ff:fe97:c6a8/64 Scope:Link UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:29435 overruns:0 carrier:0 collisions:0 txqueuelen:500 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Note | |
---|---|
- Create one Tun/Tap interface per guest OS. - Use |
Generate a random mac address
- Use the following script
random_mac
. This will generate a random mac address, starting with 00:16:3e, which will be attributed in the next step to the virtual machine.
Note | |
---|---|
The first three bytes are important (identification for the virtualized network). Do not change it. |
Run the guest OS using the kvm command
Start the virtual machine with the kvm command. The following command is just an example, feel free to adapt it to your use case.
The kvm process in launched a screen
session, if you are not familiar with screen, read its documentation.
node :
|
screen kvm -m 512 -hda /tmp/squeeze-x64-base.qcow2 -net nic,model=virtio,macaddr=$MACADDR -net tap,ifname=tap0,script=no -nographic |
Or, use libvirt
Libvirt is a toolkit for managing virtualization servers. Libvirt is also an abstraction layer for different virtualization solutions, including KVM but also Xen and VMWare ESX. In our case, we use libvirt on top of KVM.
- Create a domain file in XML, describing a virtual machine. Don't forget to adapt this example to your case (especially, replace the mac address by a randomly generated one).
eg : domain.xml
<domain type='kvm'> <name>squeeze</name> <memory>524288</memory> <vcpu>1</vcpu> <os> <type arch="x86_64">hvm</type> </os> <clock sync="localtime"/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/kvm</emulator> <disk type='file' device='disk'> <driver type='qcow2'/> <source file='/tmp/squeeze-x64-base.qcow2'/> <target dev='vda' bus='virtio'/> <shareable/> </disk> <interface type='ethernet'> <target dev='tap0'/> <script path='no'/> <model type='virtio'/> <mac address='00:16:3e:78:b8:04'/> </interface> <serial type='pty'> <source path='/dev/ttyS0'/> <target port='0'/> </serial> <console type='pty'> <source path='/dev/ttyS0'/> <target port='0'/> </console> </devices> </domain>
- Now, the guest OS can be started.
- You can also use
virsh
to manage your guest OS:- list the running virtual machines:
virsh list
- open a console on the "squeeze" virtual machine:
virsh console squeeze
- list the running virtual machines:
Note | |
---|---|
- You can use the script |
Misc notes
- Use KVM contextualization, if you want to perform some customization (like using static address) for your VMs.
- For the deployment of an important number of guest OS, you can use the subnet reservation. See also the virtual network interlink.