Situation
Need Resize CentOS7 VM Disk In KVM
How To
Check Disk Info
# qemu-img info /data/img/demo
image: /data/img/demo
file format: qcow2
virtual size: 20 GiB (21474836480 bytes)
disk size: 3.29 GiB
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
refcount bits: 16
corrupt: false
Resize Disk
~ # qemu-img resize /data/img/demo +80G
Image resized.
~ # qemu-img info /data/img/demo
image: /data/img/demo
file format: qcow2
virtual size: 200 GiB (214748364800 bytes)
disk size: 3.29 GiB
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
refcount bits: 16
corrupt: false
Start VM And Resize Block
~ # virsh start demo
Domain demo started
~ # virsh blockresize anthos /data/img/demo 100G
Block device '/data/img/demo' is resized
Login VM And Check Disk Use fdisk
Add New Partition
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000dfe2d
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (41943040-209715199, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-209715199, default 209715199):
Using default value 209715199
Partition 3 of type Linux and of size 80 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
Apply Partition Table Changes Without Reboot
# partprobe
Create PV, Extend VG And Resize Disk
# pvcreate /dev/sda3
# vgextend centos /dev/sda3
# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 98.99 GiB
PE Size 4.00 MiB
Total PE 25342
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 20479 / <80.00 GiB
VG UUID NCxnoc-FVzv-lj1b-mYhj-AD2n-bng0-aZxvS8
# lvresize -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 96.99 GiB (24830 extents).
Logical volume centos/root successfully resized.
# lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID t63G7X-JCe3-l8Pe-aXaz-j61m-dvJe-HB7RPy
LV Write Access read/write
LV Creation host, time centos-temp, 2022-05-13 04:45:42 -0400
LV Status available
# open 1
LV Size 96.99 GiB
Current LE 24830
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4455424 to 25425920
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 908M 0 908M 0% /dev
tmpfs 919M 0 919M 0% /dev/shm
tmpfs 919M 8.6M 911M 1% /run
tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/mapper/centos-root 97G 4.5G 93G 5% /
/dev/sda1 1014M 181M 834M 18% /boot
tmpfs 184M 0 184M 0% /run/user/0