現象:
ping不通虛擬機,ssh登錄不上,console方式登錄不上, 虛擬機無法shutdown,貌似電源管理也沒有安裝成功。
先來解決網絡問題:
還好可以通過virt-cat來檢查虛擬機內部的文件。
先關閉虛擬機
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 interfaceauto loiface lo inet loopback# The primary network interfaceauto eth0iface eth0 inet staticaddress 192.168.1.51netmask 255.255.255.0network 192.168.1.0broadcast 192.168.1.255gateway 192.168.1.1# dns-* options are implemented by the resolvconf package, if installeddns-nameservers 8.8.8.8dns-search localdomain這個dns-search localdomain看上去很奇怪。一般是defaultdomain。
localdomain是因為host機器的/etc/hosts中配置成了:
127.0.0.1 localhost.localdomain dbkvm將其換成這種配置:
127.0.0.1 localhost127.0.1.1 dbkvm再創建虛擬機,網絡正常了??梢詐ing通,可以ssh登錄。 console問題還有。
虛擬機里面的網絡設置dns-search 被設置成了defaultdomain。
因此推測是hosts文件的配置錯誤,導致虛擬機中網卡設置的dns-search錯誤,導致無法連接網絡,因此不能在創建過程中從網絡下載安裝openssh-server.
來看一下電源管理
如果不安裝電源管理,就不能在host主機通過shutdown關閉虛擬機。
在創建vm的選項中需要補上:
--addpkg=acpid事后彌補就要登錄到虛擬機中,然后運行命令:
apt-get install acpid再來處理console不能登錄的問題。
先停止虛擬機。
virsh stop vm1準備一個文件ttyS0.conf, 內容如下:
# 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 vm1Domain vm1 startedroot@dbkvm:~/kvm_scripts# virsh console vm1Connected to domain vm1Escape character is ^]Ubuntu 12.04.2 LTS vm1 ttyS0vm1 login: rootPassword:Last login: Thu May 2 09:21:03 UTC 2013 from 192.168.1.4 on pts/1Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-41-virtual x86_64)可以了。所有問題的根源都出在那個不正確的host機器上的/etc/hosts配置。
新聞熱點
疑難解答