UBuntu係統安裝KVM創建虛擬機遭遇故障的解決辦(bàn)法
本次在UBuntu12.04.2係統安裝KVM,隨後創(chuàng)建虛擬機,又出現了新的問題。
現象:
ping不(bú)通虛擬機,ssh登錄不上,console方式登錄不上(shàng), 虛擬機無法shutdown,貌似電(diàn)源管理(lǐ)也沒有安裝成功。
先來解決網絡問題:
還好可以通過virt-cat來(lái)檢查虛擬機內部的文件。
先關(guān)閉虛擬機
virsh destroy vm1
然後檢查網卡設置文件:
root@dbkvm:~# virt-cat -d vm1 /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.168.1.51 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 8.8.8.8 dns-search localdomain
這個dns-search localdomain看上(shàng)去很奇怪。一般是defaultdomain。
localdomain是因為host機器的/etc/hosts中配置成(chéng)了:
127.0.0.1 localhost.localdomain dbkvm
將其換成這種配置:
127.0.0.1 localhost 127.0.1.1 dbkvm
再創建虛擬機,網絡(luò)正常了。可以ping通,可以ssh登(dēng)錄。 console問題(tí)還(hái)有。
虛(xū)擬機裏麵的網絡設置(zhì)dns-search 被設置成了defaultdomain。
因此推測是hosts文件的配置錯誤,導(dǎo)致虛擬機中網卡設(shè)置的dns-search錯誤,導致無法(fǎ)連(lián)接網絡(luò),因此不能在創建過程中從網(wǎng)絡下載(zǎi)安(ān)裝openssh-server.
來看一下電源管理
如果不安裝電源(yuán)管理,就不能在host主機通過shutdown關(guān)閉虛擬機。
在創建vm的選項中需要補上:
--addpkg=acpid
事後彌補就要登錄到虛擬機中,然後運(yùn)行命令:
apt-get install acpid
再來處理(lǐ)console不能登錄的問題。
先停止虛擬(nǐ)機。
virsh stop vm1
準備一個(gè)文件ttyS0.conf, 內容(róng)如下:
# ttyS0.conf - getty # This service maintains a getty on ttyS0 from the point the system is # started until it is shut down again. start on stopped rc RUNLEVEL=[2345] stop on runlevel [!2345] respawn
安裝guestfish程序:
apt-get install guestfish
現在用virt-copy-in將文件複製到vm的/etc/init目錄中:
virt-copy-in -d vm1 ttyS0.conf /etc/init
然後調用virsh edit vm1 來編輯vm1的配置文件,添加下麵的內容:
<devices> ... <serial type='pty'> <source path='/dev/pts/2'/> <target port='0'/> </serial> <console type='pty' tty='/dev/pts/2'> <source path='/dev/pts/2'/> <target port='0'/> </console> </devices>
最後試用一下:
virsh start vm1 Domain vm1 started root@dbkvm:~/kvm_scripts# virsh console vm1 Connected to domain vm1 Escape character is ^] Ubuntu 12.04.2 LTS vm1 ttyS0 vm1 login: root Password: Last login: Thu May 2 09:21:03 UTC 2013 from 192.168.1.4 on pts/1 Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-41-virtual x86_64)
可以了。所有問題的根源都出在那個不正確(què)的host機器上的/etc/hosts配(pèi)置。
關鍵詞:UBuntu,KVM,虛擬機
閱讀本文後您(nín)有什麽感想? 已有 人給出評價!
- 0
- 1
- 0
- 2
- 0
- 4