linux分区扩容/缩容 vgextend lvresize
虚拟机是群晖nas系统的VM虚拟机,创建的时候磁盘分配的是50G,然后某天又编辑了一下虚拟机,将磁盘大小直接修改成了100G
然后重启机器,df -h查看/根目录还是50G,而fdisk -l看到的分区大小是100G(这个应该是之前某人操作过的,不然也不会显示成100G,而还是原来的50G,这个文章的记录的操作就是从现在的状态开始的)
参考文章:http://linux.51yip.com/search/lvextend
#查看分区大小(50G)
df -h
#查看PG物理卷
pvscan
PV /dev/sda3 VG ubuntu-vg lvm2 [<99.00 GiB / <49.50 GiB free]
Total: 1 [<99.00 GiB] / in use: 1 [<99.00 GiB] / in no VG: 0 [0 ]
#查看VG容量(可以看到还有12671没有使用呢)
vgdisplay
--- Volume group ---
VG Name ubuntu-vg
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 <99.00 GiB
PE Size 4.00 MiB
Total PE 25343
Alloc PE / Size 12672 / 49.50 GiB
Free PE / Size 12671 / <49.50 GiB
VG UUID hun4gL-bgcZ-KdmW-5rkw-59o5-Miby-2inD5G
#利用 lvresize 的功能來增加LV
lvresize -l +12671 /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 49.50 GiB (12672 extents) to <99.00 GiB (25343 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
#显示LV逻辑卷
lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID KGk7ni-kevv-hLrb-e9QS-DSFl-x0S8-d15jWM
LV Write Access read/write
LV Creation host, time ubuntu-server, 2021-09-18 14:35:53 +0800
LV Status available
# open 1
LV Size <99.00 GiB
Current LE 25343
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
#查看VG容量
vgdisplay
--- Volume group ---
VG Name ubuntu-vg
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 <99.00 GiB
PE Size 4.00 MiB
Total PE 25343
Alloc PE / Size 25343 / <99.00 GiB
Free PE / Size 0 / 0
VG UUID hun4gL-bgcZ-KdmW-5rkw-59o5-Miby-2inD5G
#查看分区大小(还是50G)
df -h
#LV分区重设大小
resize2fs /dev/ubuntu-vg/ubuntu-lv
#查看分区大小(已经是100G了)
df -h
fdisk -l补充:后续又增加了400G,一共有500G了,怎么把新增加的400G加到/分区?
fdisk -l
Disk /dev/sda: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: iSCSI Storage
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: 31F29E60-1C24-4CDD-9855-CD46FB8E21A9
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 209713151 207611904 99G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 98.102 GiB, 106296246272 bytes, 207609856 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
#思路,先分区,然后把分区的空间扩展到现有的VG,然后再增加LV的容量,最后刷新文件系统的分区大小
#先分区
fdisk /dev/sda
m (帮助菜单)
n (创建新分区,一路按几个回车)
w (保存分区表)
q (退出)
#再查看分区
fdisk -l
Disk /dev/sda: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: iSCSI Storage
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: 31F29E60-1C24-4CDD-9855-CD46FB8E21A9
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 209713151 207611904 99G Linux filesystem
/dev/sda4 209713152 1048575966 838862815 400G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 98.102 GiB, 106296246272 bytes, 207609856 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
#将新分区的空间追加到 ubuntu-vg 这个VG上
vgextend ubuntu-vg /dev/sda4
Physical volume "/dev/sda4" successfully created.
Volume group "ubuntu-vg" successfully extended
#可以看到有400G的未使用空间了
pvscan
PV /dev/sda3 VG ubuntu-vg lvm2 [<99.00 GiB / 0 free]
PV /dev/sda4 VG ubuntu-vg lvm2 [<400.00 GiB / <400.00 GiB free]
Total: 2 [498.99 GiB] / in use: 2 [498.99 GiB] / in no VG: 0 [0 ]
#vgdisplay
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 498.99 GiB
PE Size 4.00 MiB
Total PE 127742
Alloc PE / Size 25343 / <99.00 GiB
Free PE / Size 102399 / <400.00 GiB
VG UUID hun4gL-bgcZ-KdmW-5rkw-59o5-Miby-2inD5G
#将空闲的102399个追加到 /dev/ubuntu-vg/ubuntu-lv lv上
lvresize -l +102399 /dev/ubuntu-vg/ubuntu-lv
#lv已经有500G大小了
lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID KGk7ni-kevv-hLrb-e9QS-DSFl-x0S8-d15jWM
LV Write Access read/write
LV Creation host, time ubuntu-server, 2021-09-18 14:35:53 +0800
LV Status available
# open 1
LV Size 498.99 GiB
Current LE 127742
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
#刷新文件系统的分区大小
resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 63
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 130807808 (4k) blocks long.
#已经/目录已经有500G了
df -h
...
/dev/mapper/ubuntu--vg-ubuntu--lv 491G 28G 444G 6% /
...
版权属于:Joyber
本文链接:https://blog.qqvbc.com/default/628.html
转载时须注明出处及本声明