CentOS7 源碼安裝Xen

之前已經寫過一篇 Fedora25下源碼安裝Xen4.8 。但是由於條件受限,實驗需要在CentOS7的環境下進行。本來想着這兩者應該差不多,但是在CentOS7上源碼安裝時卻出現了很多問題。掙扎了近一個星期,現在將這些錯誤總結一下。

1. /etc/grub2.cfg文件的修改
在之前,安裝完Xen和Domain0以後,會自動生成Fedora, with Xen hypervisor的啓動選項。進入以後就沒有問題了。在CentOS7下,安裝完以後沒有with xen hypervisor的選項,因此需要手動添加。添加過程其實很簡單,但是之前不敢改。先看看可以啓動的一些列表是怎麼寫的。下面是能正常啓動的,內核版本爲4.9.13的centos系統,也是Domain0系統。
(我遇到的很多問題都是因爲xen hypervisor服務沒有起來, Domain0是正常的)

# less /etc/grub2.cfg
***
menuentry 'CentOS Linux (4.9.13) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-4.9.13-advanced-ed7325d2-37d5-47ac-b284-6c03eb2b0c4f' {
        load_video
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  8bc8dcdd-f939-48ff-a294-8ca57cb89ac9
        else
          search --no-floppy --fs-uuid --set=root 8bc8dcdd-f939-48ff-a294-8ca57cb89ac9
        fi
        linux16 /vmlinuz-4.9.13 root=/dev/mapper/cl-root ro crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet 
        initrd16 /initramfs-4.9.13.img
}
***

我對比了這個啓動項和之前的啓動項發現大部分內容都是相同的,只需要在 fi 後面添加一個啓動xen服務即可。/etc/grub2.cfg文件不能直接修改,因此我們要增加啓動項需要去修改/etc/grub.d/40_custom。將上面的部分(複製自己grub2.cfg裏面的)修改部分有三個:

  1. menuentry 後面的名字,這個名字自己取一個就行了。
  2. fi 下面加以行 multiboot /xen.gz
  3. 最後兩行的linux16和initrd16都改爲了module
#vim /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry 'CentOS, with Xen' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-4.9.13-advanced-ed7325d2-37d5-47ac-b284-6c03eb2b0c4f' {
        load_video
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  8bc8dcdd-f939-48ff-a294-8ca57cb89ac9
        else
          search --no-floppy --fs-uuid --set=root 8bc8dcdd-f939-48ff-a294-8ca57cb89ac9
        fi
        multiboot /xen.gz
        module /vmlinuz-4.9.13 root=/dev/mapper/cl-root ro crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet 
        module /initramfs-4.9.13.img
}

修改完以後要更新/etc/grub2.cfg, 命令如下:

#grub2-mkconfig -o /etc/grub2.cfg

2. xl info提示以下錯誤

xl info 
xc: error: Could not obtain handle on privileged command interface (2 = No such file or directory): Internal error
libxl: error: libxl.c:99:libxl_ctx_alloc: cannot open libxc handle: No such file or directory
cannot init xl context

出現類似的錯誤的原因總結起來有幾點:

  • 沒有掛載xenfs,這時候嘗試掛載xenfs。如果掛載失敗,那麼很有可能和我一樣,就是xen
    hypervisor沒有啓動。本來正常的啓動順序應該是,grub先啓動xen
    hypervisor,然後再進入dom0。我直接進入了dom0,沒有啓動xen hypervisor。
# modprobe xenfs
# mount -t xenfs xenfs /proc/xen
  • 需要運行以下幾條命令,然後重啓:
systemctl enable xen-qemu-dom0-disk-backend.service
systemctl enable xen-init-dom0.service
systemctl enable xenconsoled.service
systemctl enable xendomains.service
systemctl enable xen-watchdog.service

如果是ubuntu/debian可能是以下的命令:

update-rc.d xencommons defaults 19 18
update-rc.d xendomains defaults 21 20
update-rc.d xen-watchdog defaults 22 23

3.安裝順序
官方文檔裏面推薦先安裝Dom0,然後再安裝xen工具。但實際上,對於CentOS來說應該先安裝xen工具,然後再安裝Dom0.(我也不懂爲什麼,在什麼地方看到的也找不到了。但最後成功了)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章