qemu-img管理虚拟机

1. 查看正在运行的虚拟机

[root@idca-vm02 ~]# virsh list

Id    名称                         状态

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

2     idca-bankccb-b2c-45            running

4     idca-bankicbc-42-clone         running

6     idca_rhel5_con29_6.29          running

7     idca_w03_bkccb_b2b_101         running

10    idca_w03_bkicbc_b2b_102        running

16    idca-bankcncb-44               running

18    idca_w03_bkcmb_b2b_105         running

20    idca_w03_bkpab_87              running

32    idca_w03_bkcomm_b2b_103        running

34    idca-bankhxb-43                running

38    idca_rhel5_con23_6.23_new      running

43    idca_w03_bkpab_dk_6.88         running

2. 查看所有虚拟机

[root@idca-vm02 ~]# virsh list --all

Id    名称                         状态

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

2     idca-bankccb-b2c-45            running

4     idca-bankicbc-42-clone         running

6     idca_rhel5_con29_6.29          running

7     idca_w03_bkccb_b2b_101         running

10    idca_w03_bkicbc_b2b_102        running

16    idca-bankcncb-44               running

18    idca_w03_bkcmb_b2b_105         running

20    idca_w03_bkpab_87              running

32    idca_w03_bkcomm_b2b_103        running

34    idca-bankhxb-43                running

38    idca_rhel5_con23_6.23_new      running

43    idca_w03_bkpab_dk_6.88         running

-     idca_rhel5_con23_6.23          关闭

-     idca_w03_mod                   关闭

3.编辑某个域的 XML 配置

virsh  edit  idca-bankcncb-44

xml文件内容如下:

[root@idca-vm02 ~]# virsh  edit  idca-bankcncb-44

<domain type='kvm'>

<name>idca-bankcncb-44</name>

<uuid>17d9c1a2-a34d-6b7a-88ff-e96412bbdda5</uuid>

<memory unit='KiB'>1048576</memory>

<currentMemory unit='KiB'>1048576</currentMemory>

<vcpu placement='static'>2</vcpu>

<os>

<type arch='x86_64' machine='rhel6.5.0'>hvm</type>

<boot dev='hd'/>

</os>

<domain type='kvm'>

<name>idca-bankcncb-44</name>

<uuid>17d9c1a2-a34d-6b7a-88ff-e96412bbdda5</uuid>

<memory unit='KiB'>1048576</memory>

<currentMemory unit='KiB'>1048576</currentMemory>

<vcpu placement='static'>2</vcpu>

<os>

<type arch='x86_64' machine='rhel6.5.0'>hvm</type>

<boot dev='hd'/>

</os>

<features>

<acpi/>

<apic/>

<pae/>

</features>

<clock offset='utc'/>

<on_poweroff>destroy</on_poweroff>

<on_reboot>restart</on_reboot>

<on_crash>restart</on_crash>

<devices>

<emulator>/usr/libexec/qemu-kvm</emulator>

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

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

<source file='/kvmfs/vmfspool/idca-bankicbc-42_vd1-clone-clone-5.img'/>

<target dev='hda' bus='ide'/>

<address type='drive' controller='0' bus='0' target='0' unit='0'/>

</disk>

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

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

<source file='/kvmfs/vmfspool/idca-bankicbc-42_vd2-clone-clone-5.img'/>

<target dev='hdb' bus='ide'/>

<address type='drive' controller='0' bus='0' target='0' unit='1'/>

</disk>

<controller type='usb' index='0'>

<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>

</controller>

<controller type='ide' index='0'>

<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>

</controller>

<interface type='bridge'>

<mac address='52:54:00:38:b0:3b'/>

<source bridge='br0'/>

<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>

</interface>

<serial type='pty'>

<target port='0'/>

</serial>

<console type='pty'>

<target type='serial' port='0'/>

</console>

<input type='tablet' bus='usb'/>

<input type='mouse' bus='ps2'/>

<graphics type='vnc' port='-1' autoport='yes'/>

<sound model='ich6'>

<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>

3. 开启、关闭、挂起、删除一个域

virsh start     idca-bankhxb-43

virsh shutdown     idca-bankhxb-43

virsh suspend  idca-bankhxb-43

virsh destrory(stop)  idca-bankhxb-43

4.镜像格式转换

qemu-img convert -O raw idca-bankcncb-62.qcow2 idca-bankcncb-62.img

5.virsh克隆虚拟机

virt-clone -o idca-bankccb-b2c-45 -n idca-bankccb-b2c-45_20170515bak -f ./idca-bankccb-b2c-45_20170515bak.img

参考:http://www.cnblogs.com/beanmoon/p/4673525.html

6.virsh命令帮助

[root@idca-vm02 ~]# virsh help

Grouped commands:

Domain Management (help keyword 'domain'):

attach-device                  从一个XML文件附加装置

attach-disk                    附加磁盘设备

attach-interface               获得网络界面

autostart                      自动开始一个域

blkdeviotune                   Set or query a block device I/O tuning parameters.

blkiotune                      Get or set blkio parameters

blockcommit                    Start a block commit operation.

blockcopy                      Start a block copy operation.

blockjob                       Manage active block operations

blockpull                      Populate a disk from its backing image.

blockresize                    Resize block device of domain.

change-media                   Change media of CD or floppy drive

console                        连接到客户会话

cpu-baseline                   compute baseline CPU

cpu-compare                    compare host CPU with a CPU described by an XML file

cpu-stats                      show domain cpu statistics

create                         从一个 XML 文件创建一个域

define                         从一个 XML 文件定义(但不开始)一个域

desc                           show or set domain's description or title

destroy                        destroy (stop) a domain

detach-device                  从一个 XML 文件分离设备

detach-disk                    分离磁盘设备

detach-interface               分离网络界面

domdisplay                     domain display connection URI

domhostname                    print the domain's hostname

domid                          把一个域名或 UUID 转换为域 id

domif-setlink                  set link state of a virtual interface

domiftune                      get/set parameters of a virtual interface

domjobabort                    abort active domain job

domjobinfo                     domain job information

domname                        将域 id 或 UUID 转换为域名

dompmsuspend                   suspend a domain gracefully using power management functions

dompmwakeup                    wakeup a domain from pmsuspended state

domuuid                        把一个域名或 id 转换为域 UUID

domxml-from-native             Convert native config to domain XML

domxml-to-native               Convert domain XML to native config

dump                           把一个域的内核 dump 到一个文件中以方便分析

dumpxml                        XML 中的域信息

edit                           编辑某个域的 XML 配置

inject-nmi                     Inject NMI to the guest

send-key                       Send keycodes to the guest

managedsave                    managed save of a domain state

managedsave-remove             Remove managed save of a domain

maxvcpus                       connection vcpu maximum

memtune                        Get or set memory parameters

migrate                        将域迁移到另一个主机中

migrate-setmaxdowntime         set maximum tolerable downtime

migrate-setspeed               Set the maximum migration bandwidth

migrate-getspeed               Get the maximum migration bandwidth

numatune                       Get or set numa parameters

reboot                         重新启动一个域

reset                          reset a domain

restore                        从一个存在一个文件中的状态恢复一个域

resume                         重新恢复一个域

save                           把一个域的状态保存到一个文件

save-image-define              redefine the XML for a domain's saved state file

save-image-dumpxml             saved state domain information in XML

save-image-edit                edit XML for a domain's saved state file

schedinfo                      显示/设置日程安排变量

screenshot                     take a screenshot of a current domain console and store it into a file

setmaxmem                      改变最大内存限制值

setmem                         改变内存的分配

setvcpus                       改变虚拟 CPU 的号

shutdown                       关闭一个域

start                          开始一个(以前定义的)非活跃的域

suspend                        挂起一个域

ttyconsole                     tty 控制台

undefine                       undefine a domain

update-device                  update device from an XML file

vcpucount                      domain vcpu counts

vcpuinfo                       detailed domain vcpu information

vcpupin                        control or query domain vcpu affinity

emulatorpin                    control or query domain emulator affinity

vncdisplay                     vnc 显示

Domain Monitoring (help keyword 'monitor'):

domblkerror                    Show errors on block devices

domblkinfo                     domain block device size information

domblklist                     list all domain blocks

domblkstat                     获得域设备块状态

domcontrol                     domain control interface state

domif-getlink                  get link state of a virtual interface

domiflist                      list all domain virtual interfaces

domifstat                      获得域网络接口状态

dominfo                        域信息

dommemstat                     get memory statistics for a domain

domstate                       域状态

list                           列出域

Host and Hypervisor (help keyword 'host'):

capabilities                   性能

freecell                       NUMA可用内存

hostname                       打印管理程序主机名

node-memory-tune               Get or set node memory parameters

nodecpustats                   Prints cpu stats of the node.

nodeinfo                       节点信息

nodememstats                   Prints memory stats of the node.

nodesuspend                    suspend the host node for a given time duration

qemu-attach                    QEMU Attach

qemu-monitor-command           QEMU Monitor Command

qemu-agent-command             QEMU Guest Agent Command

sysinfo                        print the hypervisor sysinfo

uri                            打印管理程序典型的URI

version                        显示版本

Interface (help keyword 'interface'):

iface-begin                    create a snapshot of current interfaces settings, which can be later committed (iface-commit) or restored (iface-rollback)

iface-bridge                   create a bridge device and attach an existing network device to it

iface-commit                   commit changes made since iface-begin and free restore point

iface-define                   define (but don't start) a physical host interface from an XML file

iface-destroy                  destroy a physical host interface (disable it / "if-down")

iface-dumpxml                  interface information in XML

iface-edit                     edit XML configuration for a physical host interface

iface-list                     list physical host interfaces

iface-mac                      convert an interface name to interface MAC address

iface-name                     convert an interface MAC address to interface name

iface-rollback                 rollback to previous saved configuration created via iface-begin

iface-start                    start a physical host interface (enable it / "if-up")

iface-unbridge                 undefine a bridge device after detaching its slave device

iface-undefine                 undefine a physical host interface (remove it from configuration)

Network Filter (help keyword 'filter'):

nwfilter-define                define or update a network filter from an XML file

nwfilter-dumpxml               network filter information in XML

nwfilter-edit                  edit XML configuration for a network filter

nwfilter-list                  list network filters

nwfilter-undefine              undefine a network filter

Networking (help keyword 'network'):

net-autostart                  自动开始网络

net-create                     从一个 XML 文件创建一个网络

net-define                     从一个 XML 文件定义(但不开始)一个网络

net-destroy                    destroy (stop) a network

net-dumpxml                    XML 中的网络信息

net-edit                       为网络编辑 XML 配置

net-info                       network information

net-list                       列出网络

net-name                       把一个网络UUID 转换为网络名

net-start                      开始一个(以前定义的)不活跃的网络

net-undefine                   取消定义一个非活跃的网络

net-update                     update parts of an existing network's configuration

net-uuid                       把一个网络名转换为网络UUID

Node Device (help keyword 'nodedev'):

nodedev-create                 create a device defined by an XML file on the node

nodedev-destroy                destroy (stop) a device on the node

nodedev-detach                 detach node device from its device driver

nodedev-dumpxml                XML 中的节点设备详情

nodedev-list                   这台主机中中的枚举设备

nodedev-reattach               reattach node device to its device driver

nodedev-reset                  重置节点设备

Secret (help keyword 'secret'):

secret-define                  define or modify a secret from an XML file

secret-dumpxml                 secret attributes in XML

secret-get-value               Output a secret value

secret-list                    list secrets

secret-set-value               set a secret value

secret-undefine                undefine a secret

Snapshot (help keyword 'snapshot'):

snapshot-create                Create a snapshot from XML

snapshot-create-as             Create a snapshot from a set of args

snapshot-current               Get or set the current snapshot

snapshot-delete                Delete a domain snapshot

snapshot-dumpxml               Dump XML for a domain snapshot

snapshot-edit                  edit XML for a snapshot

snapshot-info                  snapshot information

snapshot-list                  List snapshots for a domain

snapshot-parent                Get the name of the parent of a snapshot

snapshot-revert                Revert a domain to a snapshot

Storage Pool (help keyword 'pool'):

find-storage-pool-sources-as   找到潜在存储池源

find-storage-pool-sources      发现潜在存储池源

pool-autostart                 自动启动某个池

pool-build                     建立池

pool-create-as                 从一组变量中创建一个池

pool-create                    从一个 XML 文件中创建一个池

pool-define-as                 在一组变量中定义池

pool-define                    在一个 XML 文件中定义(但不启动)一个池

pool-delete                    删除池

pool-destroy                   destroy (stop) a pool

pool-dumpxml                   XML 中的池信息

pool-edit                      为存储池编辑 XML 配置

pool-info                      存储池信息

pool-list                      列出池

pool-name                      将池 UUID 转换为池名称

pool-refresh                   刷新池

pool-start                     启动一个(以前定义的)非活跃的池

pool-undefine                  取消定义一个不活跃的池

pool-uuid                      把一个池名称转换为池 UUID

Storage Volume (help keyword 'volume'):

vol-clone                      clone a volume.

vol-create-as                  从一组变量中创建卷

vol-create                     从一个 XML 文件创建一个卷

vol-create-from                create a vol, using another volume as input

vol-delete                     删除卷

vol-download                   Download a volume to a file

vol-dumpxml                    XML 中的卷信息

vol-info                       存储卷信息

vol-key                        returns the volume key for a given volume name or path

vol-list                       列出卷

vol-name                       returns the volume name for a given volume key or path

vol-path                       returns the volume path for a given volume name or key

vol-pool                       returns the storage pool for a given volume key or path

vol-resize                     resize a vol

vol-upload                     upload a file into a volume

vol-wipe                       wipe a vol

Virsh itself (help keyword 'virsh'):

cd                             change the current directory

connect                        连接(重新连接)到 hypervisor

echo                           echo arguments

exit                           退出这个非交互式终端

help                           打印帮助

pwd                            print the current directory

quit                           退出这个非交互式终端

参考

# http://blog.csdn.net/bravezhe/article/details/8461386

#kvm搭建http://blog.csdn.net/bravezhe/article/details/8461700

#虚拟机修改名字http://blog.sina.com.cn/s/blog_5d867af10101c3by.html

qemu-img管理虚拟机的更多相关文章

  1. 使用virt-manager创建和管理虚拟机

    1.虚拟机管理程序和虚拟机管理 一个服务器上只安装单一操作系统的时代已经过去,单个服务器可通过安装多个虚拟机来运行不同操作系统.虚拟机的大量使用减少了所需的服务其硬件,降低了服务器的功耗,但却带来了另 ...

  2. 使用 Virtual Machine Manager 管理虚拟机

    转载自https://www.ibm.com/developerworks/cn/cloud/library/cl-managingvms/   尽管服务器管理在过去问题重重,但虚拟化管理简化了一些问 ...

  3. virsh命令管理虚拟机

    virsh命令管理虚拟机 libvirt有两种控制方式,命令行和图形界面. 1.图形界面:通过执行名virt-manager,启动libvirt的图形界面,在图形界面下可以一步一步的创建虚拟机,管理虚 ...

  4. CentOS7.1 KVM虚拟化之经常使用管理虚拟机命令(3)

    一.查看虚拟机列表及状态 [root@kvm01 ~]# virsh list --all Id Name State ---------------------------------------- ...

  5. kvm命令管理虚拟机

    virsh 既有命令行模式,也有交互模式,在命令行直接输入 virsh 就进入交互模式, virsh 后面跟命令参数,则是命令行模式: KVM 工具集合 libvirt:操作和管理KVM虚机的虚拟化 ...

  6. Mac OS 使用 Vagrant 管理虚拟机(VirtualBox)

    Vagrant(官网.github)是一款构建虚拟开发环境的工具,支持 Window,Linux,Mac OS,Vagrant 中的 Boxes 概念类似于 Docker(实质是不同的),你可以把它看 ...

  7. Hyper-V1:创建和管理虚拟机

    Hyper-V是微软的管理虚拟机(Virtual Machine)的服务,在安装Hyper-V功能之后,系统自动安装可视化的虚拟机管理工具:Hyper-V Manager.在同一台物理机上,能够使用H ...

  8. 在vCenter5.5中为用户创建角色,管理虚拟机

    在vSphere的使用中,如有只有vCenter+ESXi节点的两级配置,为了达到多租户管理及权限分配,可以在vCenter5.5中为用户创建角色,管理虚拟机 1.以管理员身份登陆vCenter 2. ...

  9. nova 命令管理虚拟机

    nova命令管理虚拟机: $ nova list #查看虚拟机$ nova stop [vm-name]或[vm-id] #关闭虚拟机$ nova start [vm-name]或[vm-id] #启 ...

随机推荐

  1. 洛谷P2473 [SCOI2008]奖励关(期望+状压)

    传送门 我数学期望还是太差了…… 先考虑状压模型,设$dp[i][S]$表示第$i$轮,当前宝物状态为$S$,能获得的最大期望分数 然而这个模型有一个问题,第$i$轮不一定能达到状态$S$ 那么考虑转 ...

  2. IT兄弟连 JavaWeb教程 EL与JSTL表达式经典案例

    案例需求:使用MVC模式编写一个程序,当发起一个deptList.do请求时,在servlet中准备一个部门列表对象,把这个列表对象放入request作用域中转发到deptlist.jsp,使用JST ...

  3. javaScript中for-in语句

    for-in语句是一种精准的迭代语句,用来枚举对象的属性 实例: <!DOCTYPE html><html><head> <title>For-In S ...

  4. mysql引擎问题研究

    mysql引擎问题研究 数据库引擎 缺省情况下,MYSQL支持三个引擎:ISAM,MYISAM和HEAP.还存在MYSQL+API的引擎例如InnoDB. 数据库引擎特点 ISAM:执行读取操作速度很 ...

  5. 用shell脚本监控MySQL主从同步

    企业面试题1:(生产实战案例):监控MySQL主从同步是否异常,如果异常,则发送短信或者邮件给管理员.提示:如果没主从同步环境,可以用下面文本放到文件里读取来模拟:阶段1:开发一个守护进程脚本每30秒 ...

  6. css margin padding 四个方向

    margin 和padding虽然有四个单独的方向属性,如margin-left,padding-bottom等等. 但是可以用margin:2px 3px 4px 5px     四个参数的含义:上 ...

  7. Hungary Algorithm国外板子

    Codeforces 1107一题除了dp做法还有二分带权匹配O(n^3)做法,国外网友的板子时间非常优秀,但矩阵设定的事情并不是很懂-- //Codeforces 1107F const int m ...

  8. tera term超级终端

    一款Window上的虚拟终端工具,它同时支持串口连接和网络连接,而对于网络连接它支持Telnet和SSH协议.最关键的是Tera Term支持自己的脚本语言,即TTL(Tera Term Langua ...

  9. 修改Azure Website默认时区

    Azure Website默认时区为国际标准时间,对中国用户来说不太方便友好,如何设置成北京时间呢? 打开Azure Website的“配置”页,找到“应用设置”节点. 在应用设置中添加设置项,密钥为 ...

  10. 报错:Error: ENOENT, no such file or directory 'c:\Users\Administrator\WebstormProjects\blogtest\views\footer.ejs'

    这是我在index上引用<%- include footer %>,找不到该文件 所以报错 建立文件footer.ejs