KVM虚拟机在线扩展磁盘空间

本文介绍如何使用KVM进行虚拟机磁盘的在线扩展,包括创建qcow2磁盘文件、添加磁盘到运行中的虚拟机以及验证磁盘是否成功添加的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

KVM支持在线扩展磁盘空间,支持RHEL系列6以上的版本

列出在线虚拟机磁盘

[root@e3 images]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 29    centos6.6                      running
 41    centos6.5                      running
 -     kvm001                         关闭
 -     kvm002                         关闭
 -     kvm003                         关闭
 -     template                       关闭

[root@e3 images]# virsh domblklist centos6.5  #列出在线虚拟机磁盘情况
目标     源
------------------------------------------------
vda        /data/kvm/images/centos6.5.qcow2

[root@e3 images]#

创建一块qcow2磁盘并在线添加

[root@e3 images]# qemu-img create -f qcow2 centos6.5-add.qcow2 5G #创建一块5G大小的硬盘
Formatting 'centos6.5-add.qcow2', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 lazy_refcounts=off 
[root@e3 images]# ll centos6.5-add.qcow2 
-rw-r--r--. 1 root root 197120 1月  21 18:31 centos6.5-add.qcow2
#在线添加磁盘
[root@e3 images]# virsh attach-disk centos6.5 /data/kvm/images/centos6.5-add.qcow2 vdb --cache=none --subdriver=qcow2   ##
成功附加磁盘

查看

[root@e3 images]# virsh domblklist centos6.5  
目标     源
------------------------------------------------
vda        /data/kvm/images/centos6.5.qcow2
vdb        /data/kvm/images/centos6.5-add.qcow2  #添加成功

#切换虚拟机里查看
[root@kvm003 ~]# fdisk -l

Disk /dev/vda: 32.2 GB, 32212254720 bytes
16 heads, 63 sectors/track, 62415 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000903e2

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018       41611    20458496   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/VolGroup-lv_root: 19.9 GB, 19906166784 bytes
255 heads, 63 sectors/track, 2420 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-lv_swap: 1040 MB, 1040187392 bytes
255 heads, 63 sectors/track, 126 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/vdb: 5368 MB, 5368709120 bytes   #添加的
16 heads, 63 sectors/track, 10402 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

转载于:https://my.oschina.net/kcw/blog/370329

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值