Using KVM directly

While the rest of this documentation focuses on using KVM through libvirt, it is also possible to work with KVM directly. This is not the recommended way due to it being cumbersome but can be very useful at times.

KVM is very similar to Qemu and it is possible to run machines from the command line.

The basic syntax is :

kvm -m 512 -hda disk.img -cdrom ubuntu.iso -boot d -smp 2

There are many other options. Help is available with:

kvm --help

Bridged Networking

In order to run KVM using bridged networking as a user we need to perform some configuration.

1. First bridge your network card as above KVM/Networking#Creating a network bridge on the host

2. Install uml-utilities

3. Set permissions on your tun device. Using any editor, edit /etc/udev/rules.d/40-permissions.rules, add this line at the bottom of the file :

4. Reboot (to bring up your bridge and tun device).

5. Edit /etc/kvm/kvm-ifup adding sudo in front of the ip and brctl commands

6. We need a wrapper script for launching kvm. I put this script in ~/bin and call it kvm-bridge. If ~/bin is on your path you can call the command directly with kvm-bridge. This script was modified from a number of sources

7. Set the executable bit on the new script you just created:

8. Modify sudoers to allow members of the kvm group to run the wrapper kvm-bridge and create a bridged network interface without running KVM as root.

Add these line at the end of the file :

9. Now start kvm from the command line. You do not need to declare a network interface

iptables

Add these rules to iptables :

# allow incoming packets for kvm guest
IPTABLES -A FORWARD -d $IPADDR_FROM_GUEST_OS -j ACCEPT
# allow outgoing packets from kvm
IPTABLES -A FORWARD -s $IPADDR_FROM_GUEST_OS -j ACCEPT

Change "$IPADDR_FROM_GUEST_OS" to the actual ip address of the kvm guest (I advise you configure your guests to have a static IP address).

If you use ufw, add these rules to /etc/ufw/before.rules


CategoryVirtualization

KVM/Directly (last edited 2015-07-09 23:58:36 by dsmythies)