Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

第 159 章 KVM

目錄

159.1. kvm install usage yum
159.1.1. brctl / tunctl
159.1.2. virt-install
159.2. Ubuntu
159.3. CentOS 6.2
159.4. Scientific Linux Virtualization
159.5. libvirt
159.5.1. virsh
159.5.1.1. console
159.5.1.2. dumpxml
159.5.2. Virtual Machine Manager
159.6. FAQ
159.6.1. No hypervisor options were found for this connection
159.6.2. 如何判斷當前伺服器是實體機還是虛擬機

http://wiki.centos.org/HowTos/KVM

159.1. kvm install usage yum

確認處理器是否支持KVM

egrep 'vmx|svm' /proc/cpuinfo
		

對當前系統做一個全面升級

sudo yum update
sudo yum upgrade
		

Installing

如果你不想安裝Virtualization組,想單獨安裝需要的軟件,可是使用下面命令

# yum install qemu-kvm libvirt virt-install bridge-utils
		

確認kvm已經安裝

lsmod | grep kvm
# lsmod | grep kvm 
kvm_intel             138567  0 
kvm                   441119  1 kvm_intel
		

Create the disk image

qemu-img create -f qcow2 disk.img 5G

or

dd if=/dev/zero of=disk.img bs=1G count=5
# qemu-img create -f qcow2 disk.img 5G
Formatting 'disk.img', fmt=qcow2, size=5242880 kB

# dd if=/dev/zero of=disk.img bs=1G count=5
5+0 records in
5+0 records out
5368709120 bytes (5.4 GB) copied, 61.0353 seconds, 88.0 MB/s
		

Creating a virtual machine

/usr/libexec/qemu-kvm -hda disk.img -cdrom archlinux-2009.08-core-x86_64.iso -m 512 -boot d
		

如果你不在localhost上安裝OS,你需要指定vnc,這樣你可以遠程連接到kvm

[root@scientific ~]# /usr/libexec/qemu-kvm disk.img -cdrom rhel-server-5.6-x86_64-dvd.iso -m 8000 -boot d -vnc :1
		
[root@scientific ~]# yum install -y virt-manager virt-top virt-v2v virt-viewer
or
[root@scientific ~]# yum groupinstall 'Virtualization'
		

159.1.1. brctl / tunctl

[root@scientific ~]# yum install -y tunctl
			

DHCP

brctl addbr br0
ifconfig eth0 0.0.0.0
brctl addif br0 eth0
dhclient br0
tunctl -b -u root
ifconfig tap0 up
brctl addif br0 tap0
			

STATIC IP Address

brctl addbr br0
ifconfig eth0 0.0.0.0
brctl addif br0 eth0
ifconfig br0 up
tunctl -b -u root
ifconfig tap0 up
brctl addif br0 tap0

ifconfig br0 192.168.1.120 netmask 255.255.255.0 up
ip route add default via 192.168.3.1 dev br0
			

[root@scientific ~]# ip route
192.168.3.0/24 dev br0  proto kernel  scope link  src 192.168.3.43
192.168.3.0/24 dev tap0  proto kernel  scope link  src 192.168.3.21

default via 192.168.3.1 dev br0
[root@scientific ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.4ea7e4cf4633       no              eth0
                                                        tap0
br06499         8000.000000000000       no
			

啟動KVM

指定網絡參數 -net nic -net tap,ifname=tap0,script=no
/usr/libexec/qemu-kvm -hda disk.img -m 8000 -net nic -net tap,ifname=tap0,script=no -vnc :1

/usr/libexec/qemu-kvm -hda disk.img -m 8000 -net nic -net tap,ifname=tap0,script=no -nographic -daemonize
			

159.1.2. virt-install

yum install -y libvirt python-virtinst virt-manager
			

命令行安裝

sudo virt-install --connect qemu:///system -n Ubuntu32 -r 512 --vcpus=1 -f /dev/sda3 -s 9 -c Desktop/ubuntu-10.10-desktop-i386.iso --vnc --noautoconsole --os-type linux --os-variant generic26 --accelerate --network=bridge:virbr0 --hvm
sudo virt-install --connect qemu:///system -n Ubuntu32 -r 512 --vcpus=1 -f ~/ubuntu32.qcow2 -s 12 -c esktop/ubuntu-10.10-desktop-i386.iso --vnc --noautoconsole --os-type linux --os-variant generic26 --accelerate --network=bridge:br0 --hvm
			

進入GUI工具

virsh -c qemu:///system list
sudo virt-manager