KVM on Debian Sid
- Baruch Even and Leonard NorrgÄrd have integrated KVM into the debian archive.
To install and run KVM on Debian, follow these steps:
1. Run these commands as root:
# apt-get update # apt-get install kvm kvm-source qemu module-assistant # m-a a-i kvm
The package qemu is only needed for the qemu-img command (see below). The packages kvm-source and module-assistant were needed to create the kernel modules.
Depending on if you are using an AMD or Intel processor, run one of these commands:
# modprobe kvm-amd
or
# modprobe kvm-intel
2. The installation of kvm created a new system group named kvm in /etc/group. You need to add the user accounts that will run kvm to this group (replace username with the user account name to add):
# adduser username kvm
3. Log out and then login again to acquire the new group added to the account. The following commands can be run with an ordinary user account that is a member of the kvm group.
4. Create a virtual disk image (10 gigabytes in the example, but it is a sparse file and will only take as much space as is actually used, which is 0 at first, as can be seen with the du command: du vdisk.qcow, while ls -l vdisk.qcow shows the sparse file size):
$ qemu-img create vdisk.qcow 10G
5. Install an operating system. The -m option sets the RAM size for the guest, in megabytes:
$ kvm \ -hda vdisk.qcow \ -cdrom /path/to/boot-media.iso \ -boot d \ -m 384
If you're installing Windows, add the -no-acpi flag.
6. After installation is complete, run it with:
$ kvm \ -hda vdisk.img \ -m 384
7. Read the manual page for more information:
$ man kvm
In order to set up bridged networking, you could do the following:
8. Run as root:
$ apt-get install bridge-utils
9. Take down the ethernet interface that you want to use for bridging.
$ switch=$(ip route ls | awk '/^default / { for(i=0;i<NF;i++) { if ($(i) == "dev") print $(i+1) }}') $ ifdown ${switch}
10. Edit /etc/network/interfaces and comment out this interface (${switch}). Make a copy of the configuration, change the name of the interface (to forexample 'br0') and add the lines:
bridge_ports ethx bridge_stp off bridge_maxwait 5
Replace ethx in the above with the value of ${switch}. Make sure it says 'auto br0'.
For example, if your /etc/network/interfaces looked before like:
# The primary network interface allow-hotplug eth1 iface eth1 inet static address 192.168.2.4 netmask 255.255.255.0 network 192.168.2.0 broadcast 192.168.2.255 gateway 192.168.2.2 dns-nameservers 192.168.2.2 dns-search localdomain
than afterwards it should look like:
# The primary network interface #allow-hotplug eth1 #iface eth1 inet static # address 192.168.2.4 # netmask 255.255.255.0 # network 192.168.2.0 # broadcast 192.168.2.255 # gateway 192.168.2.2 # dns-nameservers 192.168.2.2 # dns-search localdomain # Bridge auto br0 iface br0 inet static address 192.168.2.4 netmask 255.255.255.0 network 192.168.2.0 broadcast 192.168.2.255 gateway 192.168.2.2 bridge_ports eth1 bridge_stp off bridge_maxwait 5 dns-nameservers 192.168.2.2 dns-search localdomain
11. Bring up the bridged interface:
$ ifup br0
At this point, an 'ifconfig -a' should show ${switch} without IP number, and br0 with the IP number that you used to have for ${switch}. Host networking should work again as usual.
12. Boot your guest OS by adding the command line parameters:
$ $ kvm \ -hda vdisk.img \ -m 384 \ -net nic,vlan=0,model=rtl8139 \ -net tap,vlan=0
If you configure your guest OS with a static IP, use one on the same subnet as the br0 but one that is FREE (ie, for the above example, 192.168.2.5).