搭建KVM,需要CPU支持虚拟化技术,我们可以用以下命令
egrep ‘(vmx|svm)‘ /proc/cpuinfo
如果你的CPU支持VT虚拟化,则会在flags里面显示vmx,如下所示:
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm
当然光CPU支持VT虚拟化还不够的,还需要在bios里面将VT-X或VT-D选项打开才能真正使用。
kvm安装windows7
yum groupinstall Virtualization "Virtualization Client"
yum install libvirt
重启修改BIOS Intel VT
/etc/init.d/libvirtd start
配置br0桥接网卡
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=1C:C1:DE:6E:A7:0E
TYPE=Ethernet
UUID=90a2761e-b132-44b2-a79c-cc49e0633bda
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
BROADCAST="192.168.0.255"
DNS1="192.168.0.220"
GATEWAY="192.168.0.1"
IPADDR="192.168.0.225"
NETMASK="255.255.255.0"
BRIDGE=br0
vim /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.0.225
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
下载装载virtio的驱动程序
wget http://211.136.8.30/files/41730000001420BF/alt.fedoraproject.org/pub/alt/virtio-win/latest/images/virtio-win-0.1-81.iso
qemu-img create -f qcow2 -o size=100G ./windows7_1.qcow2
或者qemu-img create -f qcow2 windows2008.img 500G
virt-install --name=windows7_x64_1 --vcpus=4 --ram=4096 --os-variant=win7 --disk=/data/virtual/windows7_x64_1/windows7_1.qcow2,bus=virtio,cache=writeback,format=qcow2 --disk=/data/virtual/virtio-win-0.1-81.iso,device=cdrom,bus=ide --vnclisten=0.0.0.0 --cdrom=/data/virtual/cn_windows_7_ultimate_with_sp1_x64_dvd_618537.iso --network bridge=br0,model=virtio --mac=00:10:13:AE:09:01 --vnc --vncport=5959 --vnclisten=0.0.0.0 --hvm
VNC连接安装,端口需要在5900以上
virsh list --all 查看所以虚拟机
virsh destroy windows_server_2008_x64_1 强行关闭
virsh shutdown windows_server_2008_x64_1 关闭
本文出自 “执念” 博客,请务必保留此出处http://zcl1101017794.blog.51cto.com/7962179/1603596
原文地址:http://zcl1101017794.blog.51cto.com/7962179/1603596