debian6 kvm安裝虛擬機

查看 CPU 是否支持硬件虛擬化(VT 技術) es6

root@debian:~# egrep '(vmx|svm)' --color=always /proc/cpuinfo 
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 pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 popcnt lahf_lm tpr_shadow vnmi flexpriority ept vpid
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 pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 popcnt lahf_lm tpr_shadow vnmi flexpriority ept vpid

若是沒有打印出任何東西,表示 CPU 不支持硬件虛擬化。可是仍須要肯定在 BIOS 中是否啓用了該虛擬化技術。若是返回 SVM 旗幟標誌,則表示您的處理器支持 AMD-V。而返回 VMX 旗幟標誌,則表示您的處理器支持 INTEL-VT。另外BISO也要打開虛擬化支持。 shell


安裝kvm軟件包 vim

root@debian:~# atp-get install qemu-kvm

root@debian:~# dpkg -l | grep kvm
ii  qemu-kvm                            0.12.5+dfsg-5+squeeze3       Full virtualization on x86 hardware

debian6 中包名爲qemu-kvm,debian5中包名爲kvm api


配置橋接網絡: 網絡

root@debian:~# vim /etc/network/interfaces 
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
      address 10.1.6.175
      netmask 255.255.255.0
      gateway 10.1.6.254

bridge_ports eth0
bridge_hello 2
bridge_maxage 12
bridge_fd 0
bridge_stp off

bridge_fd is the bridge forward delay time, in seconds, default 15. oop

bridge_hello is the bridge hello time, in seconds, default 2. flex

bridge_maxage is the bridge’s maximum message time, in seconds, default is 20. ui

bridge_stp controls the spanning tree protocol, on or off. Default is off, and is recommended to stay that way. spa


重啓網卡生效 rest


建立虛擬機鏡像

root@debian:/opt# kvm-img create -f qcow2 vm.img 5G
經常使用的格式有2種,一個是 qemu qcow2 格式,是能夠增加的文件格式.另一個是 raw 格式,實際是磁盤上一個連續區域。


有2中方法建立虛擬機:

一種是使用kvm命令建立

root@debian:/opt# kvm -m 2048 -drive file=vm.img -cdrom /tmp/debian-6.0.2.1-amd64-CD-1.iso -vnc 10.1.6.175:1 -boot d

使用vnc進行鏈接安裝,安裝完以後改變啓動順序以硬盤啓動,再次使用vnc鏈接配置相關設置

root@debian:/opt# kvm -m 2048 -drive file=vm.img -cdrom /tmp/debian-6.0.2.1-amd64-CD-1.iso -vnc 10.1.6.175:1 -boot c


第二種方法使用libvirt管理虛擬機

libvirt支持kvm,xen等主流虛擬機的管理。

安裝libvirt

root@debian:~# apt-get install libvirt-bin virtinst
libvirt-bin    the programs for the libvirt library

virtinst    Programs to create and clone virtual machines

virtinst是virt-install的一種shell形式管理

設置/etc/libvirt/libvirtd.conf的listen_addr參數,設置監聽地址,修改/etc/libvirt/qemu.conf的vnc_listen參數,設置vnc監聽地址。

重啓libvirt:/etc/init.d/libvirt-bin restart

virt-install 安裝虛擬機:

root@debian:/opt#virt-install -d -n vm_kvm -r 2048 --disk path=/opt/debian6.img,device=disk,bus=virtio,size=30,format=qcow2 --network bridge=br0,model=virtio --vnc --cdrom=/tmp/debian-6.0.2.1-amd64-CD-1.iso

若是磁盤格式是qcow2   注意參數format=qcow2, 不然識別不到

命令執行完後,會在/etc/libvirt/qemu目錄下生成一個vm_kvm.xml的配置文件,供啓動虛擬機時使用,該配置文件可修改,而後能夠經過VNC進行安裝。

virt-install 相關參數:

-n --name= 客戶端虛擬機名稱

-r --ram=  客戶端虛擬機分配的內存

-u --uuid= 客戶端UUID

--vcpus=2 客戶端的vcpu個數

-v --hvm 全虛擬化

-p --paravirt 半虛擬化

-l --location=localdir 安裝源

--vnc 使用vnc

-c --cdrom= 光驅 安裝途徑

-s --file-size= 使用磁盤映像的大小單位爲GB

-f --file= 做爲磁盤映像使用的文件

--disk= 使用不一樣選項做爲磁盤使用安裝介質

cache=none
若是不加該參數,默認cache policy爲write through。
kvm官方及IBM都推薦使用raw,設置cache爲none,以關閉kvm磁盤的cache策略,讓數據能夠直接落在實體硬盤上
相關文章
相關標籤/搜索