libvirt_kvm技巧收集

生成MAC地址

设置udev权限

Give New Devices tun Group Ownership:

This is a udev rule that is fired when a new tun/tap device is created:

cat <<EOF | sudo tee /etc/udev/rules.d/41-permissions-tun.rules
# provide non-root user access to tun/tap devices for Virtual Machines using VDE etc
KERNEL=="tun", GROUP="tun"
EOF

Because the user is a member of the 'tun' group they can read and write to tun/tap devices. This makes it possible for VM guests to run with regular user permissions and still use VDE networking.

To reread the udev rules do:

sudo udevadm control --reload_rules

配置VDE网络接口

Define the VDE Network Interface:

原文: http://tjworld.net/wiki/Linux/Ubuntu/VirtualMachinesWithVDENetworking

Every VM configuration is going to be slightly different so I'm not going to dwell on the individual options. I'll focus on the options that are important to networking with VDE.

I'll start with an example start-up script for Ubuntu Gutsy Server using my enhanced kvm-72:

#!/bin/bash
qemuctl -qemu kvm -name Gutsy-Server -boot d -m 450 -hda /home/all/VirtualMachines/Ubuntu-Gutsy-Server-x86.qcow2 -k en-gb \
 -net nic,model=rtl8139,macaddr=56:44:45:30:30:32,vlan=0 -net vde,sock=/var/run/kvm0.ctl,vlan=0 $@

You'll notice it is using qemuctl to provide basic GUI control. That can be removed easily (just delete "qemuctl -qemu").

The same script for the pre-kvm-72 hypervisor simply wraps the kvm start-up in a call to vdeq. Here it is:

#!/bin/bash
qemuctl -qemu vdeq kvm -name Gutsy-Server -boot d -m 450 -hda /home/all/VirtualMachines/Ubuntu-Gutsy-Server-x86.qcow2 -k en-gb \
 -net nic,model=rtl8139,macaddr=56:44:45:30:30:32,vlan=0 -net vde,sock=/var/run/kvm0.ctl,vlan=0 $@

You can see the only difference is that qemuctl is told that the qemu binary is called "vdeq" not "kvm". Without qemuctl the start-up would be:

#!/bin/bash
vdeq kvm -name Gutsy-Server -boot d -m 450 -hda /home/all/VirtualMachines/Ubuntu-Gutsy-Server-x86.qcow2 -k en-gb \
 -net nic,model=rtl8139,macaddr=56:44:45:30:30:32,vlan=0 -net vde,sock=/var/run/kvm0.ctl,vlan=0 $@