Create and Configure a KVM Guest

by bluemedora_editor on June 8, 2010

A Priori:

We assume you are currently logged in on a physical machine with the kvm, kmod-kvm and qemu packages installed.

(in our example, kvm1 is the host machine and s81rh4 is the guest machine.)

1. Become root.

[bluemedora@kvm1 /]$ su -

2. Create an empty image with ‘qcow2‘ formatting, pass guest image location and size.

[root@kvm1 ~]# qemu-img create -f qcow2 /var/lib/libvirt/images
/CentOS4.img 5G

3. Optionally, export your mouse control (not all systems require this).

[root@kvm1 ~]# export SDL_VIDEO_X11_DGAMOUSE=0

4. Start image from virtual hda and virtual cdrom drive attached. Pass cdrom media location, memory size, and boot device.

[root@kvm1 ~]# qemu-kvm -hda /var/lib/libvirt/images/CentOS4.img -cdrom
/home/bluemedora/Desktop/CentOS-4.6-i386-binDVD.iso -m 1024 -boot d

(At this point the guest should be booting from the cdrom media location.)

5. Format the virtual hard drive, install the guest operating system. Execute a clean shutdown on guest.

6. Boot the guest from the virtual hda to confirm correct configuration. Pass guest image location.

[root@kvm1 ~]# qemu-kvm -hda /var/lib/libvirt/images/CentOS4.img(At this point, the guest should be running without networking configured.)

7. Configure eth0 interface on the guest.

[root@s81rh4 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Edit the file to conform to the below example. (your numbers may differ)

DEVICE=eth0
BOOTPROTO=static
BROADCAST=10.66.3.255
IPADDR=10.66.3.25
NETMASK=255.255.255.0
HWADDR=52:54:00:12:34:56
NETWORK=10.66.3.0
ONBOOT=yes
TYPE=Ethernet

8. Execute a clean shutdown on guest.

9. Configure eth0 network interface on the host.

[root@kvm1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Edit the file to conform to the below example. (your numbers may differ)

# Broadcom Corporation NetXtreme BCM5722 Gigabit Ethernet PCI Express
DEVICE=eth0
BRIDGE=vnet0
BOOTPROTO=none
BROADCAST=10.66.3.255
HWADDR=00:26:B9:8E:84:A3
IPADDR=10.66.3.23
IPV6INIT=yes
IPV6_AUTOCONF=yes
NETMASK=255.255.255.0
NETWORK=10.66.3.0
ONBOOT=yes
GATEWAY=10.66.3.1
TYPE=Ethernet

10. Create and configure a network bridge on the host.

[root@kvm1 ~]# vi /etc/sysconfig/network-scripts/ifcfg-vnet0

Edit the file to conform to the below example. (your numbers may differ)

# This is a virtual interface configured for KVM
DEVICE=vnet0
BOOTPROTO=none
BROADCAST=10.66.3.255
IPADDR=10.66.3.23
NETMASK=255.255.255.0
NETWORK=10.66.3.0
ONBOOT=yes
GATEWAY=10.66.3.1

11. Create a script on the host that will create a network tap and add it to the network bridge at host boot time.

[root@kvm1 ~]# vi /etc/init.d/tap-config

Edit the file to conform to the below example. (your numbers may differ)

# create a network tap tunctl; # activate the tap ifconfig tap0 up; # add the tap interface to the existing bridge ‘vnet0’ brctl addif vnet0 tap0;

# KVM known issues may require exporting the mouse (add the following line if necessary) export SDL_VIDEO_X11_DGAMOUSE=0;

12. Create a link to the above script.

[root@kvm1 /]# touch /etc/rc5.d/S99tap-config[root@kvm1 /]# ln -s /etc/init.d/tap-config /etc/rc5.d/S99tap-config

13. Reboot the host.

[root@kvm1 /]# shutdown -r now

14. Become root.

[bluemedora@kvm1 /]$ su -

15. You should now be able to start the guest with proper network configuration. Pass hda, the memory size, a network interface, and a network tap.

[root@kvm1 ~]# qemu-kvm -hda /var/lib/libvirt/images/CentOS4.img -m 1024
-net nic -net tap,ifname=tap0,script=no

 

Get started

Try BindPlane for free. No credit card required.

Sign up
True Visibility
BindPlane for VMware vRealize Operations

True Visibility allows cloud management teams to use VMware vRealize’s powerful machine learning and capacity planning engine across their entire hybrid cloud environment.

Azure Monitor...everything
BindPlane for Microsoft Azure Monitor

Make Azure Monitor your first-pane-of-glass across your entire multi-cloud, multi-database or hybrid platform environment.

Thank you for contacting us. Your information was received. We'll be in touch shortly.