virsh、qemu-img基本管理操作

一、virsh基本操作

1、列出当前正在运行的虚拟机
[root@room9pc01 ~]# virsh list

2、查看虚拟机的信息
[root@room9pc01 ~]# virsh dominfo node1 //查看node1的信息
Id: 1
Name: node1
UUID: 20e15d2f-ea30-4aa3-96dc-91aab6283b10
OS Type: hvm
State: running
CPU(s): 2
CPU time: 92.8s
Max memory: 2048000 KiB
Used memory: 2048000 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: none
Security DOI: 0

二、管理虚拟机

1、启动虚拟机
[root@room9pc01 ~]# virsh start node1

2、重启虚拟机
[root@room9pc01 ~]# virsh reboot node1

3、强制关闭虚拟机
[root@room9pc01 ~]# virsh destroy node1

4、设置虚拟机开机自动运行
[root@room9pc01 ~]# virsh autostart node1

三、qemu-img基本操作管理

1、创建一个新的镜像盘文件
qemu-img命令格式: qemu-img 命令 参数 块文件名称 大小
[root@room9pc01 ~]# qemu-img create -f qcow2 disk.img 50G //qcow2为创建的格式
Formatting ‘disk.img’, fmt=qcow2 size=53687091200 encryption=off cluster_size=65536 lazy_refcounts=off

2、使用后端模板文件创建一个新的镜像盘文件
备注:-b使用后端模板文件
[root@room9pc01 ~]# qemu-img create -b disk.img -f qcow2 disk1.img
Formatting ‘disk1.img’, fmt=qcow2 size=53687091200 backing_file=‘disk.img’ encryption=off cluster_size=65536 lazy_refcounts=off

3、使用后端模板文件创建一个16G的镜像盘文件
[root@room9pc01 ~]# qemu-img create -b disk.img -f qcow2 disk2.img 16G
Formatting ‘disk1.img’, fmt=qcow2 size=53687091200 backing_file=‘disk.img’ encryption=off cluster_size=65536 lazy_refcounts=off

4、查看镜像文件的信息
[root@room9pc01 ~]# qemu-img info disk1.img
image: disk.img
file format: qcow2
virtual size: 50G (53687091200 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: false | help_topic |
| innodb_index_stats |
| innodb_table_stats |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| server_cost |
| servers |
| slave_master_info |

猜你喜欢

转载自blog.csdn.net/weixin_42972553/article/details/82936462
今日推荐