简介
本系列整理virsh命令,这篇是第一篇,整理virsh help domain相关内容
virsh # help domain
Domain Management (help keyword 'domain'):
attach-device attach device from an XML file(通过XML配置给虚拟机添加设备)
attach-disk attach disk device(添加磁盘设备)
attach-interface attach network interface(添加网络设备)
**autostart**
autostart a domain(给虚拟机添加自动启动配置,当libvirtd服务被拉起的时候,自动启动)
blkdeviotune Set or query a block device I/O tuning parameters.(设置或查询磁盘I/ O参数)
blkiotune Get or set blkio parameters(获取或设置blkio参数)
blockcommit Start a block commit operation.(将磁盘文件的变化保存到备份文件中)
blockcopy Start a block copy operation.(拷贝磁盘备份镜像到目的地)
blockjob Manage active block operations(管理active状态的磁盘任务)
blockpull Populate a disk from its backing image.(从backing file中拷贝数据到磁盘)
blockresize Resize block device of domain.(给虚拟机的块设备扩容)
change-media Change media of CD or floppy drive(更新cdrom或floppy设备)
console connect to the guest console(通过控制连接虚拟机)
cpu-baseline compute baseline CPU(计算基准CPU)
cpu-compare compare host CPU with a CPU described by an XML file(将XML中配置的CPU与HostCPU进行对比)
cpu-stats show domain cpu statistics(显示CPU统计信息)
create create a domain from an XML file(根据XML配置创建并启动一个非持久化虚拟机)
define define (but don't start) a domain from an XML file(根据XML配置创建一个虚拟机)
desc show or set domain's description or title(显示或设置虚拟机的描述或者标题)
destroy destroy (stop) a domain(强制删除一个虚拟机)
detach-device detach device from an XML file(根据XML定义删除虚拟机的设备)
detach-disk detach disk device(删除磁盘设备)
detach-interface detach network interface(删除网络设备)
domdisplay domain display connection URI(显示虚拟机的连接URI)
domfsfreeze Freeze domain's mounted filesystems.(冻结虚拟机的挂载文件系统)
domfsthaw Thaw domain's mounted filesystems.(解冻虚拟机的挂载文件系统)
domfsinfo Get information of domain's mounted filesystems.
domfstrim Invoke fstrim on domain's mounted filesystems.(在虚拟机挂载的文件系统上执行fstrim命令)
domhostname print the domain's hostname(打印虚拟机的hostname)
domid convert a domain name or UUID to domain id(把虚拟机的名字或UUID转化为虚拟机ID)
domif-setlink set link state of a virtual interface(虚拟机设备接口链路状态设置)
domiftune get/set parameters of a virtual interface(获取或者设置虚拟机设备接口得参数)
domjobabort abort active domain job(终止虚拟机的一个处于active的任务)
**domjobinfo**
domain job information(获取虚拟机的任务信息,比如正在virsh save可以查询操作情况)
domname convert a domain id or UUID to domain name(通过虚拟机的ID或者UUID获取虚拟机的名字)
**dompmsuspend**
suspend a domain gracefully using power management functions(使用电源管理功能将虚拟机挂起,需要qga支持)
**dompmwakeup**
wakeup a domain from pmsuspended state(唤醒使用dompmsuspend挂起的虚拟机)
domuuid convert a domain name or id to domain UUID(通过虚拟机的name或ID获取虚拟机的UUID)
domxml-from-native Convert native config to domain XML(将已存在的一组QEMU参数转成可以被libvirt使用Domain XML文件)
domxml-to-native Convert domain XML to native config(将已存在的libvirt使用的Domain XML文件转化为QEMU参数)
dump dump the core of a domain to a file for analysis(dump出虚拟机的core文件,用于分析崩溃原因)
dumpxml domain information in XML(获取虚拟机的XML配置信息)
edit edit XML configuration for a domain(编辑虚拟机的XML配置文件)
event Domain Events(获取虚拟机事件)
**inject-nmi**
Inject NMI to the guest(注入NMI中断到虚拟机内部,当硬件发生不可恢复的错误时使用)
iothreadinfo view domain IOThreads
iothreadpin control domain IOThread affinity
iothreadadd add an IOThread to the guest domain
iothreaddel delete an IOThread from the guest domain
send-key Send keycodes to the guest(往虚拟机发送键盘按键指令)
**send-process-signal**
Send signals to processes(给进程发送信号,qemu不支持)
lxc-enter-namespace LXC Guest Enter Namespace(进入LXC虚拟机的命名空间)
**managedsave**
managed save of a domain state(管理保存虚拟机的内存状态到/var/lib/libvirt/qemu/save/*.save,将虚拟机保存并销毁,后续restore的时候恢复到save之前的状态)
**managedsave-remove**
Remove managed save of a domain(删除虚拟机状态管理设置/var/lib/libvirt/qemu/save/*.save文件)
memtune Get or set memory parameters(获取或者设置内存参数)
metadata show or set domain's custom XML metadata
migrate migrate domain to another host(将虚拟机迁移到另一个节点)
migrate-setmaxdowntime set maximum tolerable downtime(设置停机迁移时间)
migrate-compcache get/set compression cache size(获取或者设置内存压缩的cache大小)
migrate-setspeed Set the maximum migration bandwidth(设置迁移的最大带宽)
migrate-getspeed Get the maximum migration bandwidth(获取迁移的最大带宽)
numatune Get or set numa parameters(获取或者设置numa参数)
qemu-attach QEMU Attach(QEMU Attach)
qemu-monitor-command QEMU Monitor Command(给qemu monitor发送命令)
qemu-monitor-event QEMU Monitor Events(监听qemu monitor事件)
qemu-agent-command QEMU Guest Agent Command(给qemu agent发送命令)
**reboot**
reboot a domain(优雅重启虚拟机,acpi|agent(启用的qga情况下调用qga进行关机)|initctl(upstart命令)|signal|paravirt(xen)),对应qemu只支持agent和acpi
reset reset a domain(强制重启虚拟机)
**restore**
restore a domain from a saved state in a file(通过保存的内存文件恢复虚拟机)
**resume**
resume a domain(唤醒处于pause状态的虚拟机,也就是suspend的虚机)
**save**
save a domain state to a file(将虚拟机内存状态保存到一个文件)
**save-image-define**
redefine the XML for a domain's saved state file(刷新虚拟机配置到save虚拟机的文件中)
**save-image-dumpxml**
**saved state domain**
information in XML(dump出save虚拟机文件中的虚拟机配置信息)
**save-image-edit**
edit XML for a domain's saved state file(出save虚拟机文件中的虚拟机配置信息)
schedinfo show/set scheduler parameters(显示或设置scheduler参数)
screenshot take a screenshot of a current domain console and store it into a file(截取当前虚拟机的屏幕,并将其保存到一个文件中)
set-user-password set the user password inside the domain
setmaxmem change maximum memory limit(改变最大内存限制,停机状态下才可以)
setmem change memory allocation(使用virtio-balloon动态增大或者减小内存大小)
setvcpus change number of virtual CPUs(设置vcpu个数)
shutdown gracefully shutdown a domain(优雅关闭虚拟机,acpi|agent(启用的qga情况下调用qga进行关机)|initctl(upstart命令)|signal|paravirt(xen)),对应qemu只支持agent和acpi
start start a (previously defined) inactive domain(启动一个处于关闭状态的虚拟机)
**suspend**
suspend a domain(暂停一个虚拟机)
ttyconsole tty console(tty console显示)
undefine undefine a domain(删除虚拟机的定义)
update-device update device from an XML file(根据XML配置更新虚拟机的设备)
vcpucount domain vcpu counts(获取虚拟机vcpu个数)
vcpuinfo detailed domain vcpu information(显示虚拟机vcpu的详细信息)
vcpupin control or query domain vcpu affinity(控制或者查询虚拟机的vcpu亲和性)
emulatorpin control or query domain emulator affinity(控制或者查询模拟器的亲和性)
vncdisplay vnc display(获取vnc端口号)
1 虚拟机操作相关
create: create create a domain from an XML file
define: define (but don’t start) a domain from an XML file
start: start a (previously defined) inactive domain
destroy: destroy (stop) a domain
shutdown: gracefully shutdown a domain
undefine: undefine a domain
reboot: reboot a domain
reset: reset a domain(Reset the target domain as if by power button)
suspend: suspend a domain
resume: resume a domain
save: save a domain state to a file
restore: restore a domain from a saved state in a file
screenshot: take a screenshot of a current domain console and store it into a file
autostart: autostart a domain(Configure a domain to be automatically started at boot)
managedsave: managed save of a domain state(Save and destroy a running domain, so it can be restarted from the same state at a later time. When the virsh ‘start’ command is next run for the domain, it will automatically be started from this saved state.) managedsave-remove: Remove managed save of a domain
desc: show or set domain’s description or title
domhostname: print the domain’s hostname
domname: convert a domain id or UUID to domain name(输出domain name)
metadata: show or set domain’s custom XML metadata
domuuid: convert a domain name or id to domain UUID
domid: convert a domain name or UUID to domain id
numatune: Get or set numa parameters
emulatorpin: control or query domain emulator affinity(Pin domain emulator threads to host physical CPUs)
2.xml相关
domxml-from-native: Convert native config to domain XML
domxml-to-native: Convert domain XML to native config
dumpxml: domain information in XML
edit: edit XML configuration for a domain
3.cpu相关
vcpucount: domain vcpu counts
vcpuinfo: detailed domain vcpu information
vcpupin: control or query domain vcpu affinity
setvcpus: change number of virtual CPUs
cpu-baseline: compute baseline CPU
cpu-compare: compare host CPU with a CPU described by an XML file
cpu-stats: show domain cpu statistics
4.mem相关
setmaxmem: change maximum memory limit
setmem: change memory allocation
memtune: Get or set memory parameters
5.blk
blkdeviotune: Set or query a block device I/O tuning parameters.
blkiotune: Get or set blkio parameters
blockcommit: Start a block commit operation.(Commit changes from a snapshot down to its backing image合并快照文件)
blockcopy: Start a block copy operation.
blockjob: Manage active block operations
blockpull: Populate a disk from its backing image. (将backing file数据合并至overlay中)
blockresize: Resize block device of domain.
6.attch/detach
attach-device: attach device from an XML file
attach-device: attach disk device
attach-interface: attach network interface
detach-device: detach device from an XML file
detach-disk: detach disk device
detach-interface: detach network interface
update-device: update device from an XML file
7.迁移相关
migrate: migrate domain to another host
migrate-setmaxdowntime: set maximum tolerable downtime
migrate-compcache: get/set compression cache size
migrate-setspeed: Set the maximum migration bandwidth
migrate-getspeed: Get the maximum migration bandwidth
8.guest agent
QEMU guest agent 是一个运行在虚拟机内部的普通应用程序,其目的是实现一种宿主机和虚拟机进行交互的方式这种方式不依赖于网络,而是依赖于VirtIO serial。
QEMU提供了串口设备的模拟及数据交换的通道,最终呈现出来的是一个串口设备(虚拟机内部)和一个unix socket文件(宿主机上)。
通过QEMU guest agent, 宿主机可以控制虚拟机实现冻结/恢复/整理文件系统(freeze and thaw filesystems)、列出IP地址等功能。
set-user-password: set the user password inside the domain
domfsfreeze: Freeze domain’s mounted filesystems.
domfsthaw: Thaw domain’s mounted filesystems.
domfsinfo: Get information of domain’s mounted filesystems.
domfstrim: Invoke fstrim on domain’s mounted filesystems.
dompmsuspend: suspend a domain gracefully using power management functions
dompmwakeup: wakeup a domain from pmsuspended state
9.io thread
当前不知道是配置,还是什么原因,没有相关的信息
iothreadinfo: view domain IOThreads
iothreadpin: control domain IOThread affinity
iothreadadd: add an IOThread to the guest domain
iothreaddel: delete an IOThread from the guest domain
10 操纵save生成的文件
这里主要是处理save生成的文件,包括以xml形式展现等
save-image-define: redefine the XML for a domain’s saved state file(Replace the domain XML associated with a saved state file)
save-image-dumpxml: saved state domain information in XML(Extract the domain XML that was in effect at the time the saved state file file was created with the save command)
save-image-edit: edit XML for a domain’s saved state file
11.Qemu-specific Commands
Use of the following commands is strongly discouraged.
They can cause libvirt to become confused and do the wrong thing on subsequent operations.
Once you have used this command, please do not report problems to the libvirt developers; the reports will be ignored.
qemu-attach QEMU Attach
qemu-monitor-command QEMU Monitor Command
qemu-monitor-event QEMU Monitor Events
qemu-agent-command QEMU Guest Agent Command
12.网络相关
domif-setlink: set link state of a virtual interface
virsh domif-setlink domain vnet0 down
virsh domif-setlink domain vnet0 up
domiftune: get/set parameters of a virtual interface
13.other
domjobabort: abort active domain job
domjobinfo: domain job information
可以用来查询任务进展,比如正在进行virsh save操作的时候,可以使用此命令进行查询
dump: dump the core of a domain to a file for analysis
domdisplay: domain display connection URI
inject-nmi: Inject NMI(不可屏蔽中断) to the guest( This is used when response time is critical, such as non-recoverable hardware errors)
vncdisplay: vnc display(Output the IP address and port number for the VNC display)
ttyconsole: tty console(Output the device for the TTY console)
schedinfo: show/set scheduler parameters
lxc-enter-namespace: LXC Guest Enter Namespace(The virsh lxc-enter-namespace command can be used to enter the namespaces and security context of a container and then execute an arbitrary command.)
send-key: Send keycodes to the guest
在虚拟机内部,每执行一条上述的send-key都会回显一个key字符串
send-process-signal: Send signals to processes
console: connect to the guest console event: Domain Events