This time, KVM was installed in ubuntu12.04.2, and a new problem occurred while creating the VM.
Symptom:
You cannot ping the virtual machine, log on to the SSH client, and log on to the console. The virtual machine cannot be shut down. It seems that the power management has not been installed successfully.
Solve the network problems first:
Fortunately, you can use virt-cat to check files in the virtual machine.
Disable virtual machine first
virsh destroy vm1
Then check the NIC settings file:
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 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
This DNS-search localdomain looks strange. It is generally defadomain domain.
Localdomain is configured in/etc/hosts of the host machine
127.0.0.1 localhost.localdomain dbkvm
Replace it with this Configuration:
127.0.0.1localhost127.0.1.1dbkvm
Create a VM again, and the network is normal. Can be pinged, and can be logged on through SSH. The console still has problems.
The network settings DNS-search in the virtual machine is set to defaultdomain.
Therefore, it is assumed that the hosts file configuration is incorrect, resulting in a DNS-search error set by the NIC in the virtual machine, resulting in a network connection failure. Therefore, you cannot download and install OpenSSH-server from the network during the creation process.
Let's take a look at power management.
If power management is not installed, the VM cannot be shut down on the host through shutdown.
You must add the following options to create a VM:
--addpkg=acpid
After making up for it, you need to log on to the VM and run the following command:
apt-get install acpid
Then, handle the problem that the console cannot be logged on.
Stop the VM first.
virsh stop vm1
Prepare a file ttys0.conf with the following content:
# 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
Install the guestfish program. This will install some common virt tools, such as virt-edit.
apt-get install guestfish
Also install
apt-get install libguestfs-tools
Now we use virt-copy-in to copy the file to the/etc/init directory of the VM:
virt-copy-in -d vm1 ttyS0.conf /etc/init
Call virsh edit VM1 to edit the VM1 configuration file and add the following content:
<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>
Try it out:
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)
Yes.
The root cause of all problems lies in the/etc/hosts configuration on the incorrect host machine.