1 首先要檢視CPU是否支援虛拟化:
egrep '^flags.*(vmx|svm)' /proc/cpuinfo
2 KVM與qemu的關系:
KVM是Linux kernel的一個子產品,可以用指令modprobe去加載KVM子產品。加載了該子產品後,才能進一步通過工具建立虛拟機。但是僅有KVM子產品是不夠的。因為使用者無法直接控制核心去做事情,還必須有一個運作在使用者空間的工具才行。這個使用者空間的工具,kvm開發者選擇了已經成型的開源虛拟化軟體QEMU。說起來QEMU也是一個虛拟化軟體。它的特點是可虛拟不同的CPU。比如說在x86的CPU上可虛拟一個power的CPU,并可利用它編譯出可運作在power上的CPU,并可利用它編譯出可運作在power上的程式。KVM使用了QEMU的一部分,并稍加改造,就成了可控制KVM的使用者空間工具了。是以你會看到,官方提供的KVM下載下傳有兩大部分(qemu和kvm)三個檔案(KVM子產品、QEMU工具以及二者的合集)。也就是說,你可以隻更新KVM子產品,也可以隻更新QEMU工具。這就是KVM和QEMU 的關系。(轉)
3 安裝KVM qemu
sudo apt-get install qemu-kvm qemu uml-utilities libvirt-bin libvirt-dev
加載核心子產品:
modprobe kvm_intel #or kvm_amd
安裝圖形界面管理工具:
sudo apt-get install virt-manager
添加到開機啟動:
systemctl enable libvirtd.service
啟動服務:
systemctl restart libvirtd.service
添加現有虛拟機出現錯誤:“ 'internal error: process exited while connecting to monitor: Could not access KVM kernel module: Permission denied failed to initialize KVM: Permission denied”
處理方式:
編輯/etc/libvirt/qemu.conf
user = "root"
# The group for QEMU processes run by the system instance. It can be
# specified in a similar way to user.
group = "root"
# Whether libvirt should dynamically change file ownership
# to match the configured user/group above. Defaults to 1.
# Set to 0 to disable file ownership changes.
dynamic_ownership = 0
把 user group dynamic_owership 前面的注釋去掉
重新開機服務:
systemctl restart libvirtd.service
4 常用指令:
建立虛拟磁盤:
kvm-img create -f qcow2 centos.img 30G
virsh # list # 檢視已經運作的虛拟機
virsh # list --all # 檢視所有虛拟機
quit # 退出virsh指令模式
快照管理:
create:
virsh snapshot-create-as Server08 snap1
list:
virsh snapshot-list Server08
reverse:
virsh snapshot-revert --domain Server08 snap1
del:
virsh snapshot-delete Server08 snap1