虚拟机磁盘扩容
参考:https://blog.csdn.net/qq_26963433/article/details/79467959
lsblk -f查看连接的磁盘设备和文件格式
假设原虚拟机使用xfs格式的逻辑卷
- 扩容硬盘,假设扩容设备为/dev/vdb,从100g扩容到200g
- 增加分区fdisk,类型为8e (如果使用整块盘,此步骤非必要)
- fdisk -l 查看分区
- fdisk /dev/vdb,n新建分区其他默认,
- p查看类型,类型不对用t修改
- w保存
- partprobe启用分区表
- 创建物理卷
- pvdisplay查看
- pvcreate /dev/vdb2
- 扩展卷组
- vgdisplay查看 ,原vg名为vg_data
- vgextend vg_data /dev/vdb2
- 扩展逻辑卷
- lvdisplay查看,copy原lv路径
- lvextend -l +100%FREE /dev/vg_data/lv_data
- 刷新文件系统大小
- 扩容文件系统xfs_growfs /dev/vg_data/lv_data
- 其他文件格式是用resize2fs /dev/vg_data/lv_data
- 查看生效 df
举例:
[root@srd-code-gerrit-2 ~]# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000bcc64
Device Boot Start End Blocks Id System
/dev/vda1 2048 8390655 4194304 82 Linux swap / Solaris
/dev/vda2 * 8390656 83886046 37747695+ 83 Linux
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x19260f80
Device Boot Start End Blocks Id System
/dev/vdb1 2048 419430399 209714176 8e Linux LVM
Disk /dev/mapper/vg_data-lv_data: 214.7 GB, 214744170496 bytes, 419422208 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@srd-code-gerrit-2 ~]# fdisk /dev/vdb
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/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x19260f80
Device Boot Start End Blocks Id System
/dev/vdb1 2048 419430399 209714176 8e Linux LVM
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (419430400-1048575999, default 419430400):
Using default value 419430400
Last sector, +sectors or +size{K,M,G} (419430400-1048575999, default 1048575999):
Using default value 1048575999
Partition 2 of type Linux and of size 300 GiB is set
Command (m for help): p
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x19260f80
Device Boot Start End Blocks Id System
/dev/vdb1 2048 419430399 209714176 8e Linux LVM
/dev/vdb2 419430400 1048575999 314572800 83 Linux
Command (m for help): t
Partition number (1,2, default 2):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x19260f80
Device Boot Start End Blocks Id System
/dev/vdb1 2048 419430399 209714176 8e Linux LVM
/dev/vdb2 419430400 1048575999 314572800 8e Linux LVM
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@srd-code-gerrit-2 ~]# partprobe
[root@srd-code-gerrit-2 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vdb1
VG Name vg_data
PV Size <200.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 51199
Free PE 0
Allocated PE 51199
PV UUID mmVYBe-1OHD-PZSJ-KyBd-IgIM-cMNz-hlYl0y
[root@srd-code-gerrit-2 ~]# pvcreate /dev/vdb2
Physical volume "/dev/vdb2" successfully created.
[root@srd-code-gerrit-2 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_data/lv_data
LV Name lv_data
VG Name vg_data
LV UUID OT7IYK-xaSX-KbPs-k8zb-bjWb-N9od-uNE1oE
LV Write Access read/write
LV Creation host, time srd-code-gerrit-2, 2021-06-17 16:19:12 +0800
LV Status available
# open 1
LV Size <200.00 GiB
Current LE 51199
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
[root@srd-code-gerrit-2 ~]# vgdisplay
--- Volume group ---
VG Name vg_data
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size <200.00 GiB
PE Size 4.00 MiB
Total PE 51199
Alloc PE / Size 51199 / <200.00 GiB
Free PE / Size 0 / 0
VG UUID c3ZqAV-TBt7-nG4W-XYao-d407-sZib-U3QAyc
[root@srd-code-gerrit-2 ~]# vgextend vg_data /dev/vdb2
Volume group "vg_data" successfully extended
[root@srd-code-gerrit-2 ~]# lvextend -l +100%FREE /dev/vg_data/lv_data
Size of logical volume vg_data/lv_data changed from <200.00 GiB (51199 extents) to 499.99 GiB (127998 extents).
Logical volume vg_data/lv_data successfully resized.
[root@srd-code-gerrit-2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 126G 0 126G 0% /dev
tmpfs 126G 0 126G 0% /dev/shm
tmpfs 126G 17M 126G 1% /run
tmpfs 126G 0 126G 0% /sys/fs/cgroup
/dev/vda2 36G 3.6G 30G 11% /
/dev/mapper/vg_data-lv_data 197G 110G 78G 59% /data
sfs-nas1.cn-sz1.internal.ctclouds.com:/share-d5c508dc 1000G 90G 911G 9% /mnt/gerritgit
overlay 197G 110G 78G 59% /data/docker/overlay2/af9b9127e31a43d2fcf827b12169de493a14197d91ddc6c402618e31c1067be2/merged
shm 64M 0 64M 0% /data/docker/containers/0b0d772defa1335aff1e9c0d58f1a81b0a2b7c1fc3635e07d85051941f31321a/shm
tmpfs 26G 0 26G 0% /run/user/0
[root@srd-code-gerrit-2 ~]# resize2fs /dev/vg_data/lv_data
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg_data/lv_data is mounted on /data; on-line resizing required
old_desc_blocks = 25, new_desc_blocks = 63
The filesystem on /dev/vg_data/lv_data is now 131069952 blocks long.
[root@srd-code-gerrit-2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 126G 0 126G 0% /dev
tmpfs 126G 0 126G 0% /dev/shm
tmpfs 126G 17M 126G 1% /run
tmpfs 126G 0 126G 0% /sys/fs/cgroup
/dev/vda2 36G 3.6G 30G 11% /
/dev/mapper/vg_data-lv_data 493G 110G 361G 24% /data
sfs-nas1.cn-sz1.internal.ctclouds.com:/share-d5c508dc 1000G 90G 911G 9% /mnt/gerritgit
overlay 493G 110G 361G 24% /data/docker/overlay2/af9b9127e31a43d2fcf827b12169de493a14197d91ddc6c402618e31c1067be2/merged
shm 64M 0 64M 0% /data/docker/containers/0b0d772defa1335aff1e9c0d58f1a81b0a2b7c1fc3635e07d85051941f31321a/shm
tmpfs 26G 0 26G 0% /run/user/0
[root@srd-code-gerrit-2 ~]#