百度一圈发现没有一个完整操作适合的教程就记录一下本次成功扩展磁盘的案例
在vmware workstation中对虚拟机进行磁盘扩容(注意,有快照的无法扩容,删除快照后扩展后,再创建快照避免操作失误导致数据没了)
第一步吧扩展后的磁盘空间新建
root@asus:~# fdisk /dev/sda
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (62914559 != 167772159) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
输入N 新建,回车默认默认
Command (m for help): n
Partition number (5-128, default 5):
First sector (62914527-167772126, default 62914560):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (62914560-167772126, default 167772126):
Created a new partition 5 of type 'Linux filesystem' and of size 50 GiB.
输入P查看结果
Command (m for help): p
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: A638BEC5-E54C-4232-AED0-3DB78ADA8443
Device Start End Sectors Size Type
/dev/sda1 2048 1564671 1562624 763M EFI System
/dev/sda2 1564672 4538367 2973696 1.4G Linux filesystem
/dev/sda3 4538368 33552383 29014016 13.9G Linux filesystem
/dev/sda4 33552384 62914526 29362143 14G Linux filesystem
/dev/sda5 62914560 167772126 104857567 50G Linux filesystem
输入w保存
Command (m for help): w
The partition table has been altered.
Syncing disks.
查看LVM卷信息
root@asus:~# vgdisplay
--- Volume group ---
VG Name ubuntu-vg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size <27.83 GiB
PE Size 4.00 MiB
Total PE 7124
Alloc PE / Size 7124 / <27.83 GiB
Free PE / Size 0 / 0
VG UUID wD3NPj-Bgqc-KfU3-Aped-rfUo-yiei-XUqByy
查看VG信息
root@asus:~# vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 2 1 0 wz--n- <27.83g 0
扩展卷空间
root@asus:~# vgextend ubuntu-vg /dev/sda5
Volume group "ubuntu-vg" successfully extended
查看结果
root@asus:~# vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 3 1 0 wz--n- 77.82g <50.00g
查看磁盘挂载情况,发现还没有生效到文件系统
root@asus:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 5.9G 0 5.9G 0% /dev
tmpfs 1.2G 1.2M 1.2G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 28G 24G 2.5G 91% /
tmpfs 5.9G 16K 5.9G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 5.9G 0 5.9G 0% /sys/fs/cgroup
/dev/loop1 64M 64M 0 100% /snap/core20/1822
/dev/sda2 1.4G 206M 1.1G 16% /boot
/dev/sda1 762M 5.3M 757M 1% /boot/efi
/dev/loop2 92M 92M 0 100% /snap/lxd/24061
/dev/loop0 64M 64M 0 100% /snap/core20/1778
/dev/loop3 92M 92M 0 100% /snap/lxd/23991
/dev/loop4 50M 50M 0 100% /snap/snapd/17950
/dev/loop5 50M 50M 0 100% /snap/snapd/18357
tmpfs 1.2G 0 1.2G 0% /run/user/0
扩展(看不懂)
root@asus:~# lvresize -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from <27.83 GiB (7124 extents) to 77.82 GiB (19923 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
root@asus:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 5.9G 0 5.9G 0% /dev
tmpfs 1.2G 1.2M 1.2G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 28G 24G 2.5G 91% /
tmpfs 5.9G 16K 5.9G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 5.9G 0 5.9G 0% /sys/fs/cgroup
/dev/loop1 64M 64M 0 100% /snap/core20/1822
/dev/sda2 1.4G 206M 1.1G 16% /boot
/dev/sda1 762M 5.3M 757M 1% /boot/efi
/dev/loop2 92M 92M 0 100% /snap/lxd/24061
/dev/loop0 64M 64M 0 100% /snap/core20/1778
/dev/loop3 92M 92M 0 100% /snap/lxd/23991
/dev/loop4 50M 50M 0 100% /snap/snapd/17950
/dev/loop5 50M 50M 0 100% /snap/snapd/18357
tmpfs 1.2G 0 1.2G 0% /run/user/0
使其生效
root@asus:~# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 10
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 20401152 (4k) blocks long.
查看文件系统
root@asus:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 5.9G 0 5.9G 0% /dev
tmpfs 1.2G 1.2M 1.2G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 77G 24G 50G 33% /
tmpfs 5.9G 16K 5.9G 1% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 5.9G 0 5.9G 0% /sys/fs/cgroup
/dev/loop1 64M 64M 0 100% /snap/core20/1822
/dev/sda2 1.4G 206M 1.1G 16% /boot
/dev/sda1 762M 5.3M 757M 1% /boot/efi
/dev/loop2 92M 92M 0 100% /snap/lxd/24061
/dev/loop0 64M 64M 0 100% /snap/core20/1778
/dev/loop3 92M 92M 0 100% /snap/lxd/23991
/dev/loop4 50M 50M 0 100% /snap/snapd/17950
/dev/loop5 50M 50M 0 100% /snap/snapd/18357
tmpfs 1.2G 0 1.2G 0% /run/user/0