UBuntu系統(tǒng)安裝KVM創(chuàng)建虛擬機(jī)遭遇故障的解決方法

本次在UBuntu12.04.2系統(tǒng)安裝KVM,隨后創(chuàng)建虛擬機(jī),又出現(xiàn)了新的問題。
現(xiàn)象:
ping不通虛擬機(jī),ssh登錄不上,console方式登錄不上, 虛擬機(jī)無法shutdown,貌似電源管理也沒有安裝成功。
先來解決網(wǎng)絡(luò)問題:
還好可以通過virt-cat來檢查虛擬機(jī)內(nèi)部的文件。
先關(guān)閉虛擬機(jī)
virsh destroy vm1然后檢查網(wǎng)卡設(shè)置文件:
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看上去很奇怪。一般是defaultdomain。
localdomain是因為host機(jī)器的/etc/hosts中配置成了:
127.0.0.1 localhost.localdomain dbkvm
將其換成這種配置:
127.0.0.1 localhost
127.0.1.1 dbkvm
再創(chuàng)建虛擬機(jī),網(wǎng)絡(luò)正常了??梢詐ing通,可以ssh登錄。 console問題還有。
虛擬機(jī)里面的網(wǎng)絡(luò)設(shè)置dns-search 被設(shè)置成了defaultdomain。
因此推測是hosts文件的配置錯誤,導(dǎo)致虛擬機(jī)中網(wǎng)卡設(shè)置的dns-search錯誤,導(dǎo)致無法連接網(wǎng)絡(luò),因此不能在創(chuàng)建過程中從網(wǎng)絡(luò)下載安裝openssh-server.
來看一下電源管理
如果不安裝電源管理,就不能在host主機(jī)通過shutdown關(guān)閉虛擬機(jī)。
在創(chuàng)建vm的選項中需要補(bǔ)上:
--addpkg=acpid
事后彌補(bǔ)就要登錄到虛擬機(jī)中,然后運(yùn)行命令:
apt-get install acpid
再來處理console不能登錄的問題。
先停止虛擬機(jī)。
virsh stop vm1
準(zhǔn)備一個文件ttyS0.conf, 內(nèi)容如下:
# 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
現(xiàn)在用virt-copy-in將文件復(fù)制到vm的/etc/init目錄中:
virt-copy-in -d vm1 ttyS0.conf /etc/init
然后調(diào)用virsh edit vm1 來編輯vm1的配置文件,添加下面的內(nèi)容:
<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)
可以了。所有問題的根源都出在那個不正確的host機(jī)器上的/etc/hosts配置。
相關(guān)文章
- 這篇文章主要介紹了在Ubuntu的命令行終端里管理KVM虛擬機(jī)的教程,包括虛擬機(jī)的創(chuàng)建及遠(yuǎn)程連接等操作,也同樣適用于Debian系的其他Linux系統(tǒng)借鑒,需要的朋友可以參考下2016-03-01
在Ubuntu系統(tǒng)上安裝部署KVM虛擬機(jī)的基本教程
這篇文章主要介紹了在Ubuntu系統(tǒng)上安裝部署KVM虛擬機(jī)的基本教程,包括虛擬機(jī)內(nèi)網(wǎng)絡(luò)橋接的基本設(shè)置,需要的朋友可以參考下2015-12-31- KVM(Kernel Based Virtual Machine)是一個免費的虛擬化工具,它與VMware、Hyper-V類似,也可以讓我們在主機(jī)操作系統(tǒng)中創(chuàng)建虛擬機(jī)。本文講解如何為Ubuntu 15.04安裝和配置KV2015-10-27
ubuntu12.04環(huán)境下使用kvm ioctl接口實現(xiàn)最簡單的虛擬機(jī)
qemu、virtual box、vmware、xen都是虛擬機(jī),一般用戶接觸到的virtual box和vmware比較多,都是用來ubuntu中跑windows,或者windows中跑ubuntu的。這篇文章給大家介紹了ubu2016-10-14