本文共 3404 字,大约阅读时间需要 11 分钟。
目录
http://wiki.centos.org/HowTos/KVM
确认处理器是否支持KVM
egrep 'vmx|svm' /proc/cpuinfo
对当前系统做一个全面升级
sudo yum updatesudo 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 5Gor
dd if=/dev/zero of=disk.img bs=1G count=5# qemu-img create -f qcow2 disk.img 5GFormatting 'disk.img', fmt=qcow2, size=5242880 kB# dd if=/dev/zero of=disk.img bs=1G count=55+0 records in5+0 records out5368709120 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-vieweror[root@scientific ~]# yum groupinstall 'Virtualization'
[root@scientific ~]# yum install -y tunctl
DHCP
brctl addbr br0ifconfig eth0 0.0.0.0brctl addif br0 eth0dhclient br0tunctl -b -u rootifconfig tap0 upbrctl addif br0 tap0
STATIC IP Address
brctl addbr br0ifconfig eth0 0.0.0.0brctl addif br0 eth0ifconfig br0 uptunctl -b -u rootifconfig tap0 upbrctl addif br0 tap0ifconfig br0 192.168.1.120 netmask 255.255.255.0 upip route add default via 192.168.3.1 dev br0
[root@scientific ~]# ip route192.168.3.0/24 dev br0 proto kernel scope link src 192.168.3.43192.168.3.0/24 dev tap0 proto kernel scope link src 192.168.3.21default via 192.168.3.1 dev br0[root@scientific ~]# brctl showbridge name bridge id STP enabled interfacesbr0 8000.4ea7e4cf4633 no eth0 tap0br06499 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
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 --hvmsudo 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 listsudo virt-manager
Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a>comments powered by Disqus 原文出处:Netkiller 系列 手札 本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。