1. 程式人生 > >KVM 使用 virt-install 建立虛擬機器失敗經歷

KVM 使用 virt-install 建立虛擬機器失敗經歷

rawqcow2

Qemu-imgcreate –f raw /home/main.raw 30G

virt-install --name=libaohui --ram=4096--vcpus=4-f /home/main.raw--location /home/nsfocus/ubuntu-16.04-desktop-amd64.iso--network bridge=br0 --extra-args='console=tty0console=ttyS0,115200n8 serial' --force

----------------------------------------------------------------------------

----------------------------------------------------------------------------------------------

KVM virt-install usage可惜第一個虛擬機器就失敗了。 命令格式如下,採用純文字安裝模式:

virt-install \
--name=ubuntu-13.10-vm9 \
--ram=512 --vcpus=2 \
-f /home/kvm/ubuntu64.qcow2 \
--cdrom /home/ubuntu-13.10-desktop-i386.iso \
--network bridge=br0 \
--extra-args='console=tty0 console=ttyS0,115200n8 serial'
--force

從輸出來看,建立配置檔案成功了,可是停在下面之後再也沒有console輸出。

Starting install...
Creating domain...                                                 0 B 00:07 
Connected to domain ubuntu-13.10-vm9
Escape character is ^]

virsh list已經顯示該虛擬機器在執行:

# virsh list
 Id Name                 State
----------------------------------
8 ubuntu-13.10-vm9 running

檢視virt-install日誌檔案 $HOME/.virtinst/virt-install.log如下:

[Mon, 30 Dec 2013 17:03:41 virt-install 8927] DEBUG (cli:137) Launched with command line:
/usr/bin/virt-install --name=ubuntu-13.10-vm9 --ram=512 --vcpus=2 -f /home/kvm/ubuntu64.qcow2 
--cdrom /home/ubuntu-13.10-desktop-i386.iso --network bridge=br0 --extra-args=console=tty0 
console=ttyS0,115200n8 serial --force
[Mon, 30 Dec 2013 17:03:41 virt-install 8927] DEBUG (cli:161) Requesting libvirt URI default
[Mon, 30 Dec 2013 17:03:41 virt-install 8927] DEBUG (cli:163) Received libvirt URI qemu:///system
[Mon, 30 Dec 2013 17:03:41 virt-install 8927] DEBUG (virt-install:418) Requesting virt method 'default', hv type 'default'.
[Mon, 30 Dec 2013 17:03:41 virt-install 8927] DEBUG (virt-install:721) Received virt method 'hvm'
[Mon, 30 Dec 2013 17:03:41 virt-install 8927] DEBUG (virt-install:722) Hypervisor name is 'qemu'
[Mon, 30 Dec 2013 17:03:41 virt-install 8927] DEBUG (cli:311) Forcing return value of True to prompt '%s'
[Mon, 30 Dec 2013 17:03:41 virt-install 8927] DEBUG (cli:688) DISPLAY is not set: defaulting to nographics.
[Mon, 30 Dec 2013 17:03:41 virt-install 8927] DEBUG (DistroInstaller:119) DistroInstaller location is a local file/path: /home/ubuntu-13.10-desktop-i386.iso

檢視qemu日誌,/var/log/libvirt/qemu:

cat ubuntu-13.10-vm9.log
2013-12-30 17:03:42.005+0000: starting up
char device redirected to /dev/pts/2 (label charserial0)
...

從上面的日誌來看,應該是成功將輸出重定向到了虛擬機器串列埠,可是在主機上看不到。於是網了搜尋了一下,發現 KVM Guest installed from console. But how to get to the guest’s console? 比較符合我這個情況。於是立即改為 --extra-args='console=tty0 console=ttyS0,115200n8 serial', 還是不行!

於是將 cdrom 改為 location ,竟然提示找不到安裝檔案,莫非安裝檔案有問題?於是換了一個我用過的 Ubuntu 版本,還是提示找不到安裝檔案。

starting install...
ERROR    Could not find an installable distribution at '/home/os'
Domain installation may not have been
 successful.  If it was, you can restart your domain
 by running 'virsh start ubuntu-13.10-vm8'; otherwise, please
 restart your installation.
ERROR    Could not find an installable distribution at '/home/os'

這就奇怪了。後來想可能這2個 Ubuntu 的安裝檔案可能不支援文字模式的安裝,於是又換了一個CentOS的最新安裝ISO,一試果然成功!

virt-install \
--name=ubuntu-13.10-vm12 \
--ram=512 --vcpus=2 \
-f /home/kvm/ubuntu64.qcow2 \
--location /home/os --network bridge=br0 \
--extra-args='console=tty0 console=ttyS0,115200n8 serial' \
--force
 
 
Starting install...
Retrieving file .treeinfo 100% |=========================|  334 B    00:00     
Retrieving file vmlinuz.. 100% |=========================| 3.8 MB    00:00     
Retrieving file initrd.im 100% |=========================|  30 MB    00:01     
Creating domain...                                                 0 B 00:01 
Connected to domain ubuntu-13.10-vm12
Escape character is ^]
Initializing cgroup subsys cpuset
Initializing cgroup subsys cpu
Linux version 2.6.32-431.el6.i686 (mockbuild@c6b8.bsys.dev.centos.org) 
(gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC) ) #1 SMP Fri Nov 22 00:26:36 UTC 2013
KERNEL supported cpus:
  Intel GenuineIntel
  AMD AuthenticAMD
  NSC Geode by NSC
  Cyrix CyrixInstead
  Centaur CentaurHauls
  Transmeta GenuineTMx86
  Transmeta TransmetaCPU
  UMC UMC UMC UMC
BIOS-provided physical RAM map:
 BIOS-e820: 0000000000000000 - 000000000009fc00 (usable)
 BIOS-e820: 000000000009fc00 - 00000000000a0000 (reserved)
 BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved)
 BIOS-e820: 0000000000100000 - 000000001fffe000 (usable)
 BIOS-e820: 000000001fffe000 - 0000000020000000 (reserved)
 BIOS-e820: 00000000fffc0000 - 0000000100000000 (reserved)

硬體初始化都沒有問題,裝到這裡,以為一切將會順利。哪想到當真正安裝的時候又報“ Unable to find devices of the type needed for this installation type ."的錯,網上查了一下,一般都是安裝映象或者硬碟驅動器有問題。難道又要卡在這裡?

那就只剩最後一條路,使用VNC圖形介面安裝。

root@node-2:~# virt-install \
--name=ubuntu-13.10-vm15 \
--ram=512 --vcpus=2 \
-f /home/kvm/ubuntu64.qcow2 
\--cdrom /home/CentOS-6.5-i386-bin-DVD1.iso 
\--vnc --vncport=5920 --vnclisten=0.0.0.0 
\--network bridge=br0 
\--extra-args='console=tty0 console=ttyS0,115200n8 serial' 
\--force
 
 
Starting install...
Creating domain...                                                 0 B 00:00 
Unable to connect to graphical console: virt-viewer not installed. 
Please install the 'virt-viewer' package.
Domain installation still in progress. You can reconnect to 
the console to complete the installation process.

這下又回到 CentOS/Ubuntu: KVM安裝歷程 遇到的問題,即網路防火牆的原因,很多軟體沒法通過yum或apt-get自動下載。

嘗試了手工下載virt-viewer 包來安裝,可是dependent的包實在太多,萬一其中的包有很多dependent的包,工作量就是天文數字。這條路不通。

下一步計劃就是放棄在公司電腦折騰,用回自己電腦吧!這下工作就簡單多了,大把參考文件。