【gentoo】kvm 配置

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章