196 瀏覽數

ARM KVM (CentOS)

測試環境為 CentOS 7 ARM 處理器平台.

看了一下 KVM 官方網站的確有寫到支援 ARM 處理器,所以來試試看.
http://www.linux-kvm.org/page/Processor_support

ARM:
Virtualization support for ARM was initially added to ARMv7-A processors starting with Cortex-A15 and including Cortex-A7 and Cortex-A17.
ARMv8-A processors include support for virtualization.
Refer to http://www.arm.com/products/processors/cortex-a/ for more information.

關於 KVM 可以先參考一下.

KVM 只負責虛擬化的部份 HVM (hardware-assisted virtualization), VMM (Hypervisor) 的工作,至於模擬硬體裝置就交給了 QEMU.

先確定你的核心已經有支援 KVM

[root@localhost ~]# dmesg | grep -i kvm
KVM [1]: Hyp mode initialized successfully

KVM 不一定是使用模組的方式,也可能是採用核心的方式,檢查一下你的核心 config 檔案看是哪一種方式.

[root@localhost ~]# cat /boot/config-3.10.0-327.el7
[root@localhost ~]# lsmod | grep kvm

所需套件為:

[root@localhost ~]# yum install qemu-kvm qemu-img virt-manager libvirt libvirt-python libvirt-client virt-install virt-viewer bridge-utils
  • qemu-kvm
    QEMU emulator
  • qemu-img
    QEMU disk image manager
  • virt-install
    Command line tool to create virtual machines.
  • virt-manager
    GUI tool to create virtual machines.
  • libvirt
    Provides libvirtd daemon that manages virtual machines and controls hypervisor.
  • libvirt-client
    Provides client side API’s for accessing servers and also provides virsh utility which provides command line tool to manage virtual machines.
  • virt-viewer
    Graphical console

libvirt 服務需要 start (立即) 與 enable (開機)

[root@localhost ~]# systemctl start libvirtd
[root@localhost ~]# systemctl enable libvirtd

我的 CentOS7 ARM 桌面起不來所以是透過 #SSH -X IP 將圖形介面轉移到另外一台 Linux 有桌面系統上.

[root@localhost ~]# ssh -X 172.16.0.100

ARM KVM (IP:172.16.0.100)

 
[root@localhost ~]# virt-manager &

套件安裝完後執行 #virt-manager 遇到的第一個問題,只剩下 Import existing disk image 能用.

Connection: QEMU/KVM

Warning: Failed to setup UEFI for AArch64: Did not find any uefi binary path for arch 'aarch64'
Install options are limited

Choose how you would like to install the operating system
Local install media (ISO image or CDROM)
Network Install (HTTP, FTP, or NFS)
Network Boot (PXE)
Import existing disk image

arm_kvm01
上網查了一下,參考了下面的解決方式.
https://marcin.juszkiewicz.com.pl/2015/04/17/running-vms-on-fedoraaarch64/

應該是這些開機選項都是要有支援 EFI 的開機方式,但 QEMU 安裝完並沒有設定,需要自行設定.我們需要透過 dnf 來安裝套件 edk2.git-aarch64,但這套件不在 標準 CentOS 裡面,需要自行新增 yum Repo 檔 (firmware.repo) ,或是手動編寫 /etc/yum.repos.d/firmware.repo .

關於 dnf 請自行參考 http://benjr.tw/96160

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget https://www.kraxel.org/repos/firmware.repo
[root@localhost yum.repos.d]# cat /etc/yum.repos.d/firmware.repo

[qemu-firmware-jenkins]
name=firmware for qemu, built by jenkins, fresh from git repos
baseurl=https://www.kraxel.org/repos/jenkins/
metadata_expire=5m
enabled=1
gpgcheck=0

[qemu-firmware-manual]
name=firmware for qemu, built manually, not so fresh
baseurl=https://www.kraxel.org/repos/manual/
enabled=0
gpgcheck=0

[root@localhost yum.repos.d]# dnf install edk2.git-aarch64

接下來編輯 qemu.conf 的後面.

[root@localhost ~]# vim /etc/libvirt/qemu.conf
nvram = [
   "/usr/share/edk2.git/aarch64/QEMU_EFI-pflash.raw:/usr/share/edk2.git/aarch64/vars-template-pflash.raw"
]

注意 [ ] 裡面不能有注解 #

重啟 libvirt 服務就可以了.

[root@localhost ~]# systemctl restart libvirtd
[root@localhost ~]# systemctl status libvirtd

並確認 libvirtd 的狀態是 Active: active (running)

雖然在安裝虛擬機器時列了很多種作業系統不過在 ARM KVM 下也只能模擬 ARM , Aarch64 ,也就該作業系統必須支援該種處理器才能使用.
支援哪一種平台 Machine type ,可以透過指令 #qemu-system-aarxh64 , #qemu-system-arm 來確認.

[root@localhost ~]# qemu-system-aarxh64 -machine help 
[root@localhost ~]# qemu-kvm -machine help 
upported machines are:
virt                 RHELSA 7.1 ARM Virtual Machine (alias of virt-rhelsa7.1)
virt-rhelsa7.1       RHELSA 7.1 ARM Virtual Machine (default)

如果你的環境只能用文字介面,可以透過指令的方式來安裝虛擬機器,我並沒有試過,下面是網路找來的方式.

# virt-install  --name=itzgeekguest  --ram=1024  --vcpus=1  --cdrom=/tmp/CentOS-6.5-x86_64-minimal.iso --os-type=linux --os-variant=rhel6  --network bridge=br0 --graphics=spice  --disk path=/var/lib/libvirt/images/itzgeekguest.dsk,size=4
  • –name
    Name of the Virtual machine
  • –ram
    Memory size in MB
  • –vcpus
    Virtal cpu’s in numbers
  • –cdrom
    Location of the ISO image
  • –os-type
    OS type like Linux, Windows and Unix
  • –os-variant
    OS variant like rhel 6, solaris
  • –network
    Networking
  • –graphics
    Guest display settings
  • –disk path
    Location of the disk with size of 4 GB

不過最後在新增虛擬機器時 還是出現下面這個錯誤訊息,目前也不知道怎麼解決.不過在 Ubuntu16.04.1 ARM http://benjr.tw/96185 卻是可以正常使用.

create kernel irqchip failed failed to initialize kvm: no such device

發表迴響