[root@linuxidc ~]# virsh list
Id Name State
----------------------------------------------------
7 rhel7 running
查看虚拟机的更多信息:
[root@linuxidc ~]# virsh domainfo rhel7
error: unknown command: 'domainfo'
[root@linuxidc ~]# virsh dominfo rhel7
Id: 7
Name: rhel7
UUID: 7c096b6b-1d56-4405-86e4-509f612b13aa
OS Type: hvm
State: running
CPU(s): 1
CPU time: 107.3s
Max memory: 524288 KiB
Used memory: 524288 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: selinux
Security DOI: 0
Security label: system_u:system_r:svirt_t:s0:c608,c777 (enforcing)
停止运行的虚拟机:
[root@linuxidc ~]# virsh stop rhel7
[root@linuxidc ~]# #virsh shutdown rhel7
[root@linuxidc ~]# #virsh destroy rhel7
开启一个虚拟机:
[root@linuxidc ~]# #virsh start rhel7
删除一个虚拟机:
[root@linuxidc ~]# #virsh destroy rhel7
[root@linuxidc ~]# #virsh undefine rhel7
[root@linuxidc ~]# #rm -rf /var/lib/libvirt/images/mydisk1.img
[root@linuxidc ~]# #virsh pool-refresh default
KVM主机从console口进入虚拟机:
首先,修改虚拟机的内核:
[root@localhost ~]# grubby --update-kernel=ALL --args="console=ttyS0"
重启虚拟机,从KVM host主机console虚拟机:
[root@linuxidc ~]# virsh console rhel7
[root@linuxidc ~]# virsh console rhel7
Connected to domain rhel7
Escape character is ^]
Red Hat Enterprise Linux Server 7.0 (Maipo)
Kernel 3.10.0-123.el7.x86_64 on an x86_64
localhost login: root
Password:
紧急情况的处理,当KVM主机失去了与虚拟主机的所有连接(/etc/fstab,ssh配置等),并且也没有设置任何console连接,那么可以按照以下的办法处理:
首先在KVM主机上关闭虚拟机:
virsh destroy rhel7 查找存储文件位置:
[root@linuxidc ~]# virsh dumpxml rhel7 | grep "source file="
<source file='/var/lib/libvirt/images/mydisk1'/>
将虚拟机的存储文件映射到KVM主机环境:
kpartx -av /var/lib/libvirt/images/mydisk1.img
挂载boot到KVM的mnt目录:
mount /dev/mapper/loop0p1 /mnt
然后编辑/mnt/boot/grub2/grub.cfg文件,在包含有/vmlinuz的那行添加console=ttyS0
卸载mnt目录:
umount /mnt
解除映射:
kpartx -dv /var/lib/libvirt/images/mydisk1.img
重启虚拟机:
virsh start RHEL7
重启完成后,就可以console进入虚拟机:
virsh console rhel7