============== ↓↓↓ kvm 虚拟机内查看扩容前大小 ↓↓↓ ==============
[root@web01 ~]# fdisk -l
Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000251f9
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 501759 249856 83 Linux
/dev/vda2 501760 20971519 10234880 8e Linux LVM
Disk /dev/mapper/cl-root: 7696 MB, 7696547840 bytes, 15032320 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 /dev/mapper/cl-swap: 1044 MB, 1044381696 bytes, 2039808 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 /dev/mapper/cl-home: 1732 MB, 1732247552 bytes, 3383296 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
============== ↑↑↑ kvm 虚拟机内查看扩容前大小 ↑↑↑ ==============
================ ↓↓↓ 宿主机执行以下命令 ↓↓↓ ================
[root@mytest disk]# ll
total 10080564
-rw-r--r--. 1 qemu qemu 10737418240 Sep 18 12:12 web01.raw
-rw-r--r--. 1 qemu qemu 10737418240 Aug 22 15:20 web02.raw
-rw-r--r--. 1 root root 10737418240 Jan 16 2020 web03.raw
[root@mytest disk]# pwd
/kvm/disk
[root@mytest disk]# qemu-img resize /kvm/disk/web01.raw +1G
Image resized.
[root@mytest disk]# ll
total 10080564
-rw-r--r--. 1 qemu qemu 11811160064 Sep 18 13:59 web01.raw
-rw-r--r--. 1 qemu qemu 10737418240 Aug 22 15:20 web02.raw
-rw-r--r--. 1 root root 10737418240 Jan 16 2020 web03.raw
[root@mytest disk]# virsh destroy web01
Domain web01 destroyed
[root@mytest disk]# virsh start web01
Domain web01 started
================ ↑↑↑ 宿主机执行命令 ↑↑↑ ================
==============↓↓↓ kvm 虚拟机内执行扩容操作 ↓↓↓ ==============
CentOS Linux 7 (Core)
Kernel 3.10.0-514.el7.x86_64 on an x86_64
web01 login: root
Password:
Last login: Fri Sep 18 01:58:56 on ttyS0
[root@web01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 7.2G 2.0G 5.2G 28% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/mapper/cl-home 1.7G 33M 1.6G 2% /home
/dev/vda1 241M 125M 117M 52% /boot
tmpfs 100M 0 100M 0% /run/user/0
[root@web01 ~]# fdisk -l
Disk /dev/vda: 11.8 GB, 11811160064 bytes, 23068672 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: 0x000251f9
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 501759 249856 83 Linux
/dev/vda2 501760 20971519 10234880 8e Linux LVM
Disk /dev/mapper/cl-root: 7696 MB, 7696547840 bytes, 15032320 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 /dev/mapper/cl-swap: 1044 MB, 1044381696 bytes, 2039808 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 /dev/mapper/cl-home: 1732 MB, 1732247552 bytes, 3383296 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
[root@web01 ~]# fdisk /dev/vda
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): 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 (20971520-23068671, default 20971520): 【回车】
Using default value 20971520
Last sector, +sectors or +size{K,M,G} (20971520-23068671, default 23068671): 【回车】
Using default value 23068671
Partition 3 of type Linux and of size 1 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.
[root@web01 ~]# partprobe
[root@web01 ~]# fdisk -l
Disk /dev/vda: 11.8 GB, 11811160064 bytes, 23068672 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: 0x000251f9
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 501759 249856 83 Linux
/dev/vda2 501760 20971519 10234880 8e Linux LVM
/dev/vda3 20971520 23068671 1048576 83 Linux
Disk /dev/mapper/cl-root: 7696 MB, 7696547840 bytes, 15032320 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 /dev/mapper/cl-swap: 1044 MB, 1044381696 bytes, 2039808 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 /dev/mapper/cl-home: 1732 MB, 1732247552 bytes, 3383296 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
[root@web01 ~]# pvcreate /dev/vda3
Physical volume "/dev/vda3" successfully created.
[root@web01 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name cl
PV Size 9.76 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2498
Free PE 1
Allocated PE 2497
PV UUID 1t2gPn-q02W-Q415-jYmZ-RC3x-TJ1p-DzuZ2w
"/dev/vda3" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vda3
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID FRz7Gd-S43s-gQJ2-aDYX-82RN-E50d-rUHUGV
[root@web01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 7.2G 2.0G 5.2G 28% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/mapper/cl-home 1.7G 33M 1.6G 2% /home
/dev/vda1 241M 125M 117M 52% /boot
tmpfs 100M 0 100M 0% /run/user/0
[root@web01 ~]# vgextend cl /dev/vda3
Volume group "cl" successfully extended
[root@web01 ~]# lvextend -L +1023M /dev/cl/root
Rounding size to boundary between physical extents: 1.00 GiB.
Size of logical volume cl/root changed from 7.17 GiB (1835 extents) to 8.17 GiB (2091 extents).
Logical volume cl/root successfully resized.
[root@web01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 7.2G 2.0G 5.2G 28% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/mapper/cl-home 1.7G 33M 1.6G 2% /home
/dev/vda1 241M 125M 117M 52% /boot
tmpfs 100M 0 100M 0% /run/user/0
[root@web01 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=497288k,nr_inodes=124322,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/cl-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
/dev/mapper/cl-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/vda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=101652k,mode=700)
[root@web01 ~]# xfs_growfs /dev/cl/root
meta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=469760 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1879040, 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 1879040 to 2141184
[root@web01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 8.2G 2.0G 6.2G 25% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/mapper/cl-home 1.7G 33M 1.6G 2% /home
/dev/vda1 241M 125M 117M 52% /boot
tmpfs 100M 0 100M 0% /run/user/0
============== ↑↑↑ kvm 虚拟机内执行扩容操作 ↑↑↑ ==============