The management of KVM virtual machine is mainly through the virsh command to manage the virtual machine.
1. View the KVM virtual machine configuration file and running status
KVM
虚拟机默认配置文件位置: /etc/libvirt/qemu/
autostart
目录是配置kvm虚拟机开机自启动目录。
# virsh autostart instance-00000001
执行这样的命令后,/etc/libvirt/qemu/会生成autostart目录
# virsh list –all
2. virsh command help
# virsh –help
or
3. KVM virtual machine boot
# virsh start instance-00000002
4. KVM virtual machine shutdown or power off
shutdown
By default, the virsh tool cannot shut down the Linux virtual machine, and the Linux operating system needs to enable and start the acpid service. This service must be configured when installing a KVM linux virtual machine.
# chkconfig acpid on
# service acpid restart
virsh shutdown
# virsh shutdown oeltest01
Force power off
# virsh destroy wintest01
The virsh command can shut down the virtual machine of openstack, but it cannot be turned on
5. Start the virtual machine from the configuration file
# virsh create /etc/libvirt/qemu/instance-00000001.xml
6. Configure a self-starting virtual machine at boot
# virsh autostart instance-00000001
7. Export the KVM virtual machine configuration file
# virsh dumpxml instance-00000002 > /etc/libvirt/qemu/instance-00000002-$(date +%Y%m%d%H%M%S).xml
KVM virtual machine configuration files can be backed up this way.
8. Add and delete KVM virtual machines
# virsh undefine instance-00000002
Description: This command only deletes the configuration file of wintest01, but does not delete the virtual disk file. And the virtual machine is running normally, but when the virtual machine is shut down, the virtual machine no longer exists.
Redefine the virtual machine configuration file
Restore the definition of the original KVM virtual machine by exporting the backup configuration file, and redefine the virtual machine.
# mv instance-00000002-20180507172208.xml instance-00000002.xml
# virsh define /etc/libvirt/qemu/instance-00000002.xml
9. Edit the KVM virtual machine configuration file
# virsh edit instance-00000002
virsh edit will invoke the vi command to edit the /etc/libvirt/qemu/wintest01.xml configuration file. You can also edit, modify, and save directly through the vi command.
It is possible but not recommended to edit directly through vi.
10. Console management linux virtual machine
Configure virsh console see below
kvm virtual machine console login configuration of kvm virtualization study notes
# virsh console instance-00000002
11. Other virsh commands
hang server
# virsh suspend instance-00000002
restore server
# virsh resume instance-00000002