Common faults and solutions of kvm

1. Start the virtual machine Connection reset by peer

 

# virsh start vmhost1error: Failed to start domain vmhost1error: Unable to read from monitor: Connection reset by peer

Shutting down the host server during the running of the virtual machine may cause this situation. Since the kvm virtual machine controller in the host server and the virtual machine session installed in the kvm are abnormally reset, we can solve it as follows:

# virsh managedsave-remove vmhost1# virsh start vmhost1

If you start to view the log under /var/log/libvirt/qemu/vmhost1.log, the following error is reported:

Cannot set up guest memory 'pc.ram': Cannot allocate memory

This problem may be that the memory allocated to vmhost1 is too large (or even exceeds the memory size of the physical host), or it may be that the host does not have enough memory allocated to this virtual machine, causing it to fail to start!


2. There is no /usr/bin/kvm when the Define virtual machine is reloaded

 

error: Failed to define domain from hostname.xmlerror: Cannot find QEMU binary /usr/bin/kvm: No such file or directory

Solution:

# ln -s /usr/libexec/qemu-kvm /usr/bin/kvm

 


三、error: internal error process exited while connecting to monitor

 

# virsh start vmhost1  
error: Failed to start domain vmhost1error: internal error process exited while connecting to monitor: kvm: -drive file=/dev/sp1368155439693/v1368544020461,if=none,id=drive-virtio-disk0,format=qcow2: could not open disk image /dev/sp1368155439693/v1368544020461: Invalid argument

Analysis: The format of the image is wrong. Use qemu-img info to check whether the type specified in the image and the xml configuration file is consistent!


四、Unable to load library 'virt': libvirt.so

 

Unable to load library 'virt': libvirt.so: cannot open shared object file: No such file or directoryLinux下解决:      ln -s /usr/lib/libvirt.so.0   /usr/lib/libvirt.so windows下解决:      将libvirt-0.dll改名为virt.dll

 


五、error: Refusing to undefine while domain managed save image exists

 

# virsh undefine vmhost1error: Refusing to undefine while domain managed save image existshttp://www.redhat.com/archives/libvir-list/2011-July/msg01219.html

Workaround: virsh undefined $domain --managed-save


6. Error starting libvirtd process

 

# /usr/local/sbin/libvirtd -d -l --config /usr/local/etc/libvirt/libvirtd.conf (编译安装的启动方式)
error:/usr/local/sbin/libvirtd: initialization failed
try to install libpcap-devel RPM and rebuild libvirt  http://comments.gmane.org/gmane.comp.emulators.libvirt/58218apt-get install libpcap-dev 上面的方法好像都没有效果,但是尝试了http://wiki.libvirt.org/page/The_daemon_cannot_be_started说的,把配置文件里的 listen_tls = 0注释取消(更奇怪的问题,在我的客户端链接不对)

 


Seven, start the virtual machine error

 

# virsh start vmhost1error: Failed to start domain vmhost1error: internal error process exited while connecting to monitor: Could not access KVM kernel module: No such file or directoryfailed to initialize KVM: No such file or directoryNo accelerator found!

The above prompt information is because QEMU cannot find the kvm kernel module during the initialization phase.

# modprobe kvm   #载入指定的模块

Restart the computer, enter the bios interface, and set the virtualization label in the advance option to Enabled

通过命令 lsmod | grep kvm    #显示已载入的模块

 


Eight, virtual machine migration

 

# virsh migrate --live 1 qemu+tcp://192.168.0.121 --p2p --tunnelled --unsafe error: operation failed: Failed to connect to remote libvirt URI qemu+tcp://192.168.0.121(在URI后面加上/system,‘system’相当于root用户的访问权限)

#virsh migrate --live 2 qemu+tcp://192.168.0.121/system --p2p --tunnelled
 error: Unsafe migration: Migration may lead to data corruption if disks use cache != none(加上--unsafe参数)#virsh migrate --live 2 qemu+tcp://192.168.0.121/system --p2p --tunnelled --unsafe error: Timed out during operation: cannot acquire state change lock (启动虚拟机有时也会遇此错误),需要重启libvirtd进程

 


Nine, virsh

 

error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Connection refused(libvirtd 进程没有启动,libvirtd是一个监听客户端请求的进程)# virsh -c qemu:///system listerror: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied error: failed to connect to the hypervisor (当前用户没有权限,修改/etc/libvirt/libvirtd.conf,unix_sock_rw_perms = 0777,使所有用户都有权限读写)


Note: If the result of the query contains vmx, then it can prove that the server supports virtualization

 

Installation package

yum -y groupinstall "Virtualization" "Virtualization Client" "Virtualization Platform"

 

modprobe sqm

lsmod | grep kvm

 

ln -sv /usr/libexec/qemu-kvm /usr/bin/ 

 

service libvirtd start 

chkconfig --level 2345 libvirtd on 

chkconfig libvirtd  --list

 

Configure NIC Bridging

virsh iface-bridge eth0 br0

 

Install

virt-install --connect  qemu:///system --virt-type kvm --name rhel6 --ram=1024  --disk path=/var/lib/libvirt/images/rhel6.img,size=8,sparse --os-type=linux --accelerate -c /sdb1/CentOS-6.6-x86_64-bin-DVD.iso --network bridge=br0,model=virtio --vnc  --vncport=5991 --vnclisten=0.0.0.0 --force

 

--vncport The port can be changed by yourself, if it is not specified, it will be obtained automatically

--boot network,cdrom,menu=on This is the boot sequence and can be added

When the following prompt appears, use the vnc client to connect (port: 5991)

netstat -tnlp | grep kvm

tcp        0      0 0.0.0.0:5991                0.0.0.0:*                   LISTEN      3006/qemu-kvm

start installation......

Create Domain... | 0 B 00:00     

Unable to open display:

Run 'virt-viewer --help' to see a full list of available command line options

Domain installation is still in progress. you can reconnect

to the console to complete the installation process.

 

Note: If after the installation is complete, ifconfig can only see the local loopback network card, go to the /etc/sysconfig/network-scripts/ directory and change the ONBOOT of ifcfg-eth0 to yes, and then start the network card.

 

virsh uri: View the connection path of the hypervisor on the current host;

virsh connect:

virsh define: Create a virtual machine according to the pre-defined configuration file in xml format; it will not start automatically after creation;

virsh create: Create, it will start automatically after creation;

virsh undefined: delete

virsh list --all view

virsh destroy rhel6 delete rhel6

virt-install --os-variant list

virsh start rhel66 to start rhel66 or virsh create /etc/libvirt/qemu/rhel66.xml

virsh shutdown rhel66

virsh reboot rhel66  

virsh console rhel66

virsh suspend rhel66 suspend

virsh resume rhel66 resume suspend

 

/etc/libvirt/qemu/ virtual machine xml configuration file directory

virsh edit rhel66 Edit the xml configuration file, vi editing will not take effect immediately

 

Solve the problem that virsh shutdown cannot shut down the KVM virtual machine. The following operations are all on the client, not the host

yum -y install  acpid

service acpid restart

chkconfig --level 2345 acpid on 

chkconfig acpid --list

 

Solve the problem that the host in KVM cannot connect to the client through the console. The following operations are all on the client, not the host

 

1. Add the security permission of ttyS0 to allow root login:

  echo "ttyS0" >> /etc/securetty

 

2. Add parameters to the kernel in the /etc/grub.conf file:

   console=ttyS0

  Pay attention to this step:

  console=ttyS0 must be placed in the kernel line (about the 16th line), not a separate line, that is, console=ttyS0 is a parameter of the kernel, not a separate line

 

3. Add agetty to /etc/inittab:

S0:12345:respawn:/sbin/agetty ttyS0 115200

 

4. Restart the client:

 reboot

 

Rename of kvm virtual machine 

 

1. View all kvm virtual machines

virsh list --all

 Id Name Status

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

 - rhel6 off

2. Renaming the kvm virtual machine is best to shut down the virtual machine first, and then export its xml file

cd /etc/libvirt/qemu

virsh dumpxml rhel6 > CentOS02.xml

 

3. In order to make the renamed virtual machine name consistent with the disk file name, we can first name the previous disk file as CentOS02.img

cd /var/lib/libvirt/images

mv rhel6.1.img CentOS02.img

 

4. Edit the CentOS02.xml file, modify the <name> tag pair and the disk file, here we modify the disk file to CentOS02.img

<domain type='kvm'>

  <name>CentOS02</name>

      ......  

   ...omit......

      ......

  <disk type='file' device='disk'>

      <driver name='qemu' type='raw' cache='none'/>

  <source file='/var/lib/libvirt/images/CentOS02.img'/>

 

5. Use the virsh undefine command to delete the previous virtual machine and define a new kvm virtual machine according to the new xml file

virsh undefined rhel6 ////Delete the rhel6 virtual machine

virsh define /etc/libvirt/qemu/CentOS02.xml //Redefine the new kvm virtual machine

 

6. Finally, we can use the virsh list --all command again to view, the result is as follows

Id Name Status

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

 - CentOS02 shutdown

The kvm machine renamed by the above method can be directly started and used, and it will not affect the files of the udev dynamic management device. Compared with the previous virtual machine, only the name has changed.

 

The setting steps are as follows:

  1. Take Lenovo t420 as an example, press F2 to enter bios settings after booting;

  2. Select the Security option;

  3. Select Virtualization and press Enter to enter;

  4. Press the + key to modify the two options to enabled;

  5. Press F10 and enter y to save and exit.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325690200&siteId=291194637