kvm commands to manage virtual machine

virsh both command line mode, there are also interactive mode, in command-line virsh to enter directly into the interactive mode, followed by virsh command parameters, the command line mode;
Charles Bridge command
[root @ zxw6 ~] # brctl Show
Bridge Bridge name STP Enabled in the interfaces the above mentioned id
br0 8000.000c295c6c9e NO ens33
virbr0 8000.52540005d291 yes virbr0-NIC

(1) --- base operation commands to manage the virtual machine line
syntax structure:
virsh <Command> <Domain-ID> [the OPTIONS]
List all the parameters in the command help
help list list command parameters listed in
the help menu
(2 ) in addition to these simple commands, actually there are many more in the form of virsh command:
virsh help Print help
virsh attach-device from an XML file attachment
virsh attach-disk additional disk devices
gain network interface the attach-interface virsh
virsh the destroy delete a domain
virsh detach-device separation equipment from an XML file
virsh detach-disk separate disk devices
virsh detach-interface separate network interface
virsh define reply to a virtual machine
virsh undefine delete a virtual machine domain

virsh list lists the virtual machines running on the current host
virsh list --all listed on the current host all virtual machines
virsh start vm1 (virtual machine name) to open a virtual machine
virsh shutdown vm1 (virtual machine name ) normal shut down a virtual machine
virsh destroy vm1 forced to shut down a virtual machine
virsh autostart vm1 boot from the virtual machine vm1
virsh autostart --disable vm1 closed boot from the start
virsh edit vm1 edit a virtual machine's configuration file
virsh pool- list lists storage pool

Virtual machine saved path
[root @ zxw6 Network-scripts] # cd / etc / the libvirt / QEMU
[root @ zxw6 QEMU] # LS
autostart centos7.0.xml Networks


命令行下创建 && 管理虚拟机
Virt-install:命令行下创建虚拟机的命令,不过在它后面需要跟上很多的参数
    --name: 虚拟机的名字。
    --disk Location: 磁盘映像的位置。
    --graphics : 怎样连接 VM ,通常是 SPICE 。
    --vcpu : 虚拟 CPU 的数量。
    --ram : 以兆字节计算的已分配内存大小。
    --location : 指定安装源路径
    --network : 指定虚拟网络,通常是 virbr0 或者自己设定的 br0
第一步:创建磁盘管理
qemu-img create -f qcow2 -o size=3G /var/lib/libvirt/images/zxw.qcow2
第二步:下载
[root@zxw6 images]# yum install virt-install -y
第三步:创建
[root@zxw6 images]# virt-install --name=zxw --disk path=/var/lib/libvirt/images/zxw.qcow2 --ram=1024 --vcpu=1 --graphics spice --location=/var/lib/libvirt/images/CentOS-7-x86_64-DVD-1611.iso --network=bridge=br0
WARNING 需要图形显示,但未设置 DISPLAY。不能运行 virt-viewer。
WARNING 没有控制台用于启动客户机,默认为 --wait -1

开始安装......
搜索文件 .treeinfo...... | 366 B 00:00
搜索文件 vmlinuz...... | 5.1 MB 00:00
搜索文件 initrd.img...... | 41 MB 00:01
创建域...... | 0 B 00:00
ERROR unsupported format character '奠(0xffffffe7) at index 47
域安装好像没有成功。
如果是这样,可以运行下列命令重启您的域:
virsh --connect qemu:///system start zxw
否则,请重新开始安装。
第四步进入图形化安装

注:以此安装操作之后,会在桌面显示一个 virtviewer ,进入到安装步骤

 

 

删除一个虚拟机
[root@zxw6 qemu]# virsh undefine zxw
域 zxw 已经被取消定义

[root@zxw6 qemu]# ls
autostart centos7.0.xml networks
回复一个虚拟机
[root@zxw6 ~]# virsh define zxw.xml
定义域 zxw(从 zxw.xml)

[root@zxw6 ~]# virsh list --all
Id 名称 状态
----------------------------------------------------
1 centos7.0 running
- zxw 关闭

 


克隆一个虚机:
virt-clone -o vm2 -n vm4 -f /var/lib/libvirt/images/vm4.qcow2
[root@zxw6 images]# virt-clone -o centos7.0 -n zxw -f /var/lib/libvirt/images/zxw.qcow2

 四、KVM 通过virsh console连入虚拟机
 新安装一台虚拟机后,是无法通过virsh console 命令连入虚拟机中的,这时我们需要开启虚拟机的console功能。
1、centos7以下,及其他情况
(1)添加ttyS0的许可,允许root登陆
         [root@localhost ~]# echo "ttyS0" >> /etc/securetty
(2)编辑/etc/grub.conf中加入console=ttyS0

 

(3)编辑/etc/inittab,在最后一行加入内容:S0:12345:respawn:/sbin/agetty ttyS0 115200
  

 

  

(4)重启服务器
         reboot
(5)宿主机上测试
         virsh console vm-name
(6)退出console连接的虚拟机li
         按 ctrl+] 组合键退出virsh console

Guess you like

Origin www.cnblogs.com/itzhao/p/11313056.html