Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x2f5191a8.
Command (m for help): g Created a new GPT disklabel (GUID: 8B7DFDAA-0514-0146-9F52-1FDCF9F3D6E5).
Command (m for help): n Partition number (1-128, default 1): 1 First sector (2048-41943006, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943006, default 41943006):
Created a new partition 1 of type 'Linux filesystem' and of size 20 GiB.
Command (m for help): t Selected partition 1 Partition type (type L to list all types): L
Partition type (type L to list all types): 31 Changed type of partition 'Linux filesystem' to 'Linux LVM'.
Command (m for help): p Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors Disk model: VMware Virtual S 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: 8B7DFDAA-0514-0146-9F52-1FDCF9F3D6E5
Device Start End Sectors Size Type /dev/sdb1 2048 41943006 41940959 20G Linux LVM
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
linux-wugz:/home/lengqing # vgs VG #PV #LV #SN Attr VSize VFree VG1 1 0 0 wz--n- 20.00g 20.00g system 1 1 0 wz--n- 15.99g 0 linux-wugz:/home/lengqing # vgdisplay --- Volume group --- VG Name system 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 15.99 GiB PE Size 4.00 MiB Total PE 4093 Alloc PE / Size 4093 / 15.99 GiB Free PE / Size 0 / 0 VG UUID BfPwXl-TBTe-N6Rd-NaJT-xU2T-Ce0V-HqIN8L
--- Volume group --- VG Name VG1 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 20.00 GiB PE Size 4.00 MiB Total PE 5119 Alloc PE / Size 0 / 0 Free PE / Size 5119 / 20.00 GiB VG UUID ojpEne-jsFm-uB6R-azHU-zJmt-wP46-JvFeNc
linux-wugz:/home/lengqing # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert LV1 VG1 -wi-a----- 20.00g root system -wi-ao---- 15.99g linux-wugz:/home/lengqing # lvdisplay --- Logical volume --- LV Path /dev/system/root LV Name root VG Name system LV UUID fsZvJJ-NCk9-rHvR-rSOh-80tK-9GxZ-H5BRSw LV Write Access read/write LV Creation host, time install, 2019-10-04 00:06:45 +0800 LV Status available # open 1 LV Size 15.99 GiB Current LE 4093 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 1024 Block device 254:0
--- Logical volume --- LV Path /dev/VG1/LV1 LV Name LV1 VG Name VG1 LV UUID xAccOh-PRJd-jtuR-jx7F-F9Qr-N3nw-Cxm7yh LV Write Access read/write LV Creation host, time linux-wugz, 2019-12-02 02:22:10 +0800 LV Status available # open 0 LV Size 20.00 GiB Current LE 5119 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 1024 Block device 254:1
Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0xe5b9393b.
Command (m for help): g Created a new GPT disklabel (GUID: F8A76081-C61D-6A41-A62E-F39B89C0D886).
Command (m for help): n Partition number (1-128, default 1): First sector (2048-41943006, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943006, default 41943006):
Created a new partition 1 of type 'Linux filesystem' and of size 20 GiB.
Command (m for help): t Selected partition 1 Partition type (type L to list all types): 31 Changed type of partition 'Linux filesystem' to 'Linux LVM'.
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
linux-wugz:/home/lengqing # fdisk /dev/sdc -l Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 sectors Disk model: VMware Virtual S 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: F8A76081-C61D-6A41-A62E-F39B89C0D886
Device Start End Sectors Size Type /dev/sdc1 2048 41943006 41940959 20G Linux LVM linux-wugz:/home/lengqing # pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created. linux-wugz:/home/lengqing # vgextend VG1 /dev/sdc1 Volume group "VG1" successfully extended
linux-wugz:/home/lengqing # vgs VG #PV #LV #SN Attr VSize VFree VG1 2 1 0 wz--n- 39.99g 20.00g system 1 1 0 wz--n- 15.99g 0 linux-wugz:/home/lengqing # vgdisplay --- Volume group --- VG Name system 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 15.99 GiB PE Size 4.00 MiB Total PE 4093 Alloc PE / Size 4093 / 15.99 GiB Free PE / Size 0 / 0 VG UUID BfPwXl-TBTe-N6Rd-NaJT-xU2T-Ce0V-HqIN8L
--- Volume group --- VG Name VG1 System ID Format lvm2 Metadata Areas 2 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 2 Act PV 2 VG Size 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE / Size 5119 / 20.00 GiB Free PE / Size 5119 / 20.00 GiB VG UUID ojpEne-jsFm-uB6R-azHU-zJmt-wP46-JvFeNc
将剩余空间分配到逻辑卷LV1,注意+不能省,加号代表加空间,而不带加号代表就分配这么多
1 2 3
linux-wugz:/home/lengqing # lvextend -l +5119 /dev/VG1/LV1 Size of logical volume VG1/LV1 changed from 20.00 GiB (5119 extents) to 39.99 GiB (10238 extents). Logical volume VG1/LV1 successfully resized.
linux-wugz:/home/lengqing # lvreduce -L 15G /dev/VG1/LV1 -t TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated. WARNING: Reducing active logical volume to 15.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce VG1/LV1? [y/n]: y Size of logical volume VG1/LV1 changed from 39.99 GiB (10238 extents) to 15.00 GiB (3840 extents). Logical volume VG1/LV1 successfully resized.
linux-wugz:/home/lengqing # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert LV1 VG1 -wi-ao---- 39.99g root system -wi-ao---- 15.99g linux-wugz:/home/lengqing # lvdisplay --- Logical volume --- LV Path /dev/system/root LV Name root VG Name system LV UUID fsZvJJ-NCk9-rHvR-rSOh-80tK-9GxZ-H5BRSw LV Write Access read/write LV Creation host, time install, 2019-10-04 00:06:45 +0800 LV Status available # open 1 LV Size 15.99 GiB Current LE 4093 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 1024 Block device 254:0
--- Logical volume --- LV Path /dev/VG1/LV1 LV Name LV1 VG Name VG1 LV UUID xAccOh-PRJd-jtuR-jx7F-F9Qr-N3nw-Cxm7yh LV Write Access read/write LV Creation host, time linux-wugz, 2019-12-02 02:22:10 +0800 LV Status available # open 1 LV Size 39.99 GiB Current LE 10238 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 1024 Block device 254:1
首先调整文件系统,先缩减逻辑卷到比文件系统小,文件系统大概也保不住
1 2 3 4
linux-wugz:/home/lengqing # resize2fs /dev/mapper/VG1-LV1 15G resize2fs 1.43.8 (1-Jan-2018) Resizing the filesystem on /dev/mapper/VG1-LV1 to 3932160 (4k) blocks. The filesystem on /dev/mapper/VG1-LV1 is now 3932160 (4k) blocks long.
linux-wugz:/home/lengqing # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert LV1 VG1 -wi-a----- 15.00g root system -wi-ao---- 15.99g linux-wugz:/home/lengqing # lvdisplay --- Logical volume --- LV Path /dev/system/root LV Name root VG Name system LV UUID fsZvJJ-NCk9-rHvR-rSOh-80tK-9GxZ-H5BRSw LV Write Access read/write LV Creation host, time install, 2019-10-04 00:06:45 +0800 LV Status available # open 1 LV Size 15.99 GiB Current LE 4093 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 1024 Block device 254:0
--- Logical volume --- LV Path /dev/VG1/LV1 LV Name LV1 VG Name VG1 LV UUID xAccOh-PRJd-jtuR-jx7F-F9Qr-N3nw-Cxm7yh LV Write Access read/write LV Creation host, time linux-wugz, 2019-12-02 02:22:10 +0800 LV Status available # open 0 LV Size 15.00 GiB Current LE 3840 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 1024 Block device 254:1
linux-wugz:/home/lengqing # vgdisplay --- Volume group --- VG Name system 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 15.99 GiB PE Size 4.00 MiB Total PE 4093 Alloc PE / Size 4093 / 15.99 GiB Free PE / Size 0 / 0 VG UUID BfPwXl-TBTe-N6Rd-NaJT-xU2T-Ce0V-HqIN8L
--- Volume group --- VG Name VG1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 39.99 GiB PE Size 4.00 MiB Total PE 10238 Alloc PE / Size 3840 / 15.00 GiB Free PE / Size 6398 / 24.99 GiB VG UUID ojpEne-jsFm-uB6R-azHU-zJmt-wP46-JvFeNc