1. 看cpu是否支持虚拟化
egrep '(vmx|svm)' --color=always /proc/cpuinfo
2. 打开bios的cpu虚拟化支持
3. 配置kernel
[*] Virtualization --->
--- Virtualization
<M> Kernel-based Virtual Machine (KVM) support
< > KVM for Intel processors support
< > KVM for AMD processors support
Device Drivers --->
[*] Network device support --->
<M> Universal TUN/TAP device driver support
Networking support --->
Networking options --->
<*> 802.1d Ethernet Bridging
<*> 802.1Q VLAN Support
Processor type and features --->
[*] Paravirtualized guest support --->
[*] KVM paravirtualized clock
[*] KVM Guest support
-*- Enable paravirtualization code
[*] Paravirtualization layer for spinlocks
Processor type and features --->
[*] Enable KSM for page merging
4. make && make modules_install
5.重启之后
modprobe kvm
modprobe kvm-intel
modprobe tun
6. 安装包
emerge -av qemu-kvm bridge-utils usermode-utilities iptables libvirt
7
qemu-img create -f qcow2 -o preallocation=metadata gentoo-i386.img 10G
8
emerge -av bridge-utils
brctl addbr br0
ifconfig br0 192.168.1.1 netmask 255.255.255.0 up
9
emerge -av usermode-utilities
tunctl -b -u USER -t tap0
10
brctl addif br0 tap0
ifconfig tap0 up 0.0.0.0 promisc
11
qemu-kvm -cpu host -smp 2 -m 2G -drive file=PATH,cache=writeback,ifname=virtio gentoo-i386.img -cdrom livecd-i686-installer-2007.0.iso -boot d -vnc 0.0.0.0:1 -net nic,macaddr=00:00:00:00:00:01 -net tap,ifname=tap0,script=no,downscript=no
12
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j SNAT --to-source LOCAL_IP
到此整个虚拟机安装过程结束
其他qemu功能:
1. 创建qemu 副本(基于最初的img文件)
qemu-img create -b gentoo-i386.img -f qcow2 gentoo-i386.img.1
2 复制qemu 镜像文件
qemu-img convert gentoo-i386.img -O qcow2 gentoo-i386.img.1
添加nat
iptables -t nat -A PREROUTING -i eth0 -d $ETH_IP -j DNAT --to-destination $TARGET_IP
iptables -t nat -A POSTROUTING -d $TARGET_IP -j SNAT --to-source $BR0_IP