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.
Command (m for help): p #查看扇区,记录sda3起始扇区号
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: 7F13220A-DDDB-44AD-BC0D-E3F369DDE708
Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 3149823 3145728 1.5G Linux filesystem /dev/sda3 3149824 83884031 80734208 38.5G Linux filesystem #扇区起始号为3149824
Command (m for help): d #删除分区 Partition number (1-3, default 3): 3 #删除3号分区
Partition 3 has been deleted.
Command (m for help): n #新建分区 Partition number (3-128, default 3): 3 #分区号为3,与之前的保持一致 First sector (3149824-167772126, default 3149824): 3149824 #扇区起始号,与之前的保持一致 Last sector, +/-sectors or +/-size{K,M,G,T,P} (3149824-167772126, default 167772126): #结束扇区,这里直接回车默认使用所有
Created a new partition 3 of type 'Linux filesystem' and of size 78.5 GiB. Partition #3 contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o: n #这里一定要选n,不然原来存在的lvm卷就会被干掉
Command (m for help): w #最后输入w,保存退出
The partition table has been altered. Syncing disks.
lvm> vgdisplay --- Volume group --- VG Name vgubuntu System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 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 <38.50 GiB PE Size4.00 MiB Total PE 9855 Alloc PE / Size9855 / <38.50 GiB Free PE / Size0 / 0 #可用空间为0 VG UUID giBEa4-0pAc-zwzz-N916-Cwlz-bo5L-MqwWey
接着折腾lvm物理卷,使用pvresize命令对物理卷大小进行调整
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
lvm> vgs #查看空间 VG #PV #LV #SN Attr VSize VFree ubuntu-vg 110 wz--n- <38.50g 0 lvm> pvresize -t /dev/sda3#先测试一下 TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated. Physical volume "/dev/sda3" changed 1 physical volume(s) resized or updated /0 physical volume(s) not resized lvm> pvresize /dev/sda3#测试成功去掉 -t 执行 Physical volume "/dev/sda3" changed 1 physical volume(s) resized or updated /0 physical volume(s) not resized lvm> pvs #再次查看空间大小已经更改 PV VG Fmt Attr PSize PFree /dev/sda3 vgubuntu lvm2 a-- <78.50g 40.00g
root@ubuntu22:~# vgdisplay vgubuntu --- Volume group --- VG Name vgubuntu System ID Format lvm2 Metadata Areas 1 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 1 Act PV 1 VG Size <78.50 GiB PE Size4.00 MiB Total PE 20095 Alloc PE / Size9855 / <38.50 GiB Free PE / Size10240 / 40.00 GiB #这里可用空间已经增加 VG UUID giBEa4-0pAc-zwzz-N916-Cwlz-bo5L-MqwWey
这里还需要将可用的物理卷空间扩容至逻辑卷
1 2 3 4 5 6 7 8 9
root@ubuntu22:~# lvextend -l +100%FREE /dev/vgubuntu/root #将可用空间全部给逻辑卷 Size of logical volume vgubuntu/root changed from <38.50 GiB (9855 extents) to <78.50 GiB (20095 extents). Logical volume vgubuntu/root successfully resized.
root@ubuntu22:~# resize2fs /dev/vgubuntu/root #重新调整一下大小 resize2fs1.45.5 (07-Jan-2020) Filesystem at /dev/vgubuntu/root is mounted on /; on-line resizing required old_desc_blocks = 5, new_desc_blocks = 10 The filesystem on /dev/vgubuntu/root is now 20577280 (4k) blocks long.