磁盘管理常用命令

一、查看虚拟磁盘信息

[root@kvm01 ~]# qemu-img info /opt/centos7.qcow2 
image: /opt/centos7.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.6G
cluster_size: 65536
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
2         youhua_ok              271M 2020-05-22 10:22:45   00:32:18.354
Format specific information:
    compat: 1.1
    lazy refcounts: false

二、创建一个1G的磁盘,其默认格式为.raw

[root@kvm01 ~]# qemu-img create /opt/test 1G
Formatting '/opt/test', fmt=raw size=1073741824 

三、创建一个去qcow2的磁盘文件

[root@kvm01 opt]# qemu-img create -f qcow2 /opt/fun.qcow2 2G
Formatting '/opt/fun.qcow2', fmt=qcow2 size=2147483648 encryption=off cluster_size=65536 lazy_refcounts=off 

四、磁盘扩容+2G

[root@kvm01 opt]# qemu-img resize /opt/fun.qcow2 +2G
Image resized.

五、磁盘扩容至10G

[root@kvm01 opt]# qemu-img info fun.qcow2 
image: fun.qcow2
file format: qcow2
virtual size: 2.0G (2147483648 bytes)
disk size: 196K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
[root@kvm01 opt]# qemu-img resize fun.qcow2 10G
Image resized.
[root@kvm01 opt]# qemu-img info fun.qcow2 
image: fun.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 260K
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false

六、转换虚拟磁盘的格式

[root@kvm01 opt]# time qemu-img convert -f qcow2 -O raw fun.qcow2 fun.raw

real	0m0.034s
user	0m0.017s
sys	0m0.016s

七、创建快照,默认文件名为unix时间戳

[root@kvm01 opt]# virsh snapshot-create centos7 
Domain snapshot 1590126824 created

八、查看快照

[root@kvm01 opt]# virsh snapshot-list centos7 
 Name                 Creation Time             State
------------------------------------------------------------
 1590126824           2020-05-22 13:53:44 +0800 running

九、在创建快照时对文件重命名

[root@kvm01 opt]# virsh snapshot-list centos7 
 Name                 Creation Time             State
------------------------------------------------------------
 1590126824           2020-05-22 13:53:44 +0800 running
 beifeng_over         2020-05-22 13:57:24 +0800 running

十、还原快照


[root@kvm01 opt]# virsh snapshot-revert centos7 --snapshotname 1590126824  

十一、删除快照

[root@kvm01 opt]# virsh snapshot-delete centos7 --snapshotname 1590126824  
Domain snapshot 1590126824 deleted
Categories: docker&k8s

0 Comments

发表评论

Avatar placeholder

邮箱地址不会被公开。 必填项已用*标注