ubuntu的ubuntu--vg-ubuntu--lv磁盘扩容

发布于:2025-04-01 ⋅ 阅读:(16) ⋅ 点赞:(0)

在我们安装ubuntu时,如果选择的是自动分区,就会按照逻辑卷的形式来分区,并且只分配100G其余的并不会被分配,这对我们大多数情况来说都是不合理的,所以,如何扩充呢

下面以一个小的案例来说明如何扩充

问题

磁盘空间已满

Usage of /: 99.8% of 9.75GB

df、fdisk查看磁盘占用情况

df -h
root@summergao:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                                16G     0   16G   0% /dev
tmpfs                              3.2G  2.2M  3.2G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   98G   97G   0G  100% /
tmpfs                               16G     0   16G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                               16G     0   16G   0% /sys/fs/cgroup
/dev/loop0                          64M   64M     0 100% /snap/core20/1828
/dev/loop2                          50M   50M     0 100% /snap/snapd/18357
/dev/loop1                          92M   92M     0 100% /snap/lxd/24061
/dev/sda2                          2.0G  112M  1.7G   7% /boot
/dev/sda1                          1.1G  6.1M  1.1G   1% /boot/efi
tmpfs                              3.2G     0  3.2G   0% /run/user/0
root@summergao:~# 
fdisk -l
root@summergao:~# fdisk -l
Disk /dev/loop0: 63.29 MiB, 66359296 bytes, 129608 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 /dev/loop1: 91.85 MiB, 96292864 bytes, 188072 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 /dev/loop2: 49.86 MiB, 52260864 bytes, 102072 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 /dev/sda: 9.1 TiB, 10000294477824 bytes, 19531825152 sectors
Disk model: PERC H330 Mini  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: FCB82ED5-B67D-4AF4-914E-1045C910D2E7

Device       Start         End     Sectors  Size Type
/dev/sda1     2048     2203647     2201600  1.1G EFI System
/dev/sda2  2203648     6397951     4194304    2G Linux filesystem
/dev/sda3  6397952 19531823103 19525425152  9.1T Linux filesystem




Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
root@summergao:~#

查看磁盘挂载情况

lsblk
root@summergao:~# lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0                       7:0    0 63.3M  1 loop /snap/core20/1828
loop1                       7:1    0 91.9M  1 loop /snap/lxd/24061
loop2                       7:2    0 49.9M  1 loop /snap/snapd/18357
sda                         8:0    0  9.1T  0 disk 
├─sda1                      8:1    0  1.1G  0 part /boot/efi
├─sda2                      8:2    0    2G  0 part /boot
└─sda3                      8:3    0  9.1T  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0  100G  0 lvm  /
sr0                        11:0    1 1024M  0 rom  
root@summergao:~# 

可以看到sda3有9.1T,但是只分配了100G。

命令vgdisplay可以查看lvm卷组的信息

root@summergao:~# 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               9.09 TiB
  PE Size               4.00 MiB
  Total PE              2383474
  Alloc PE / Size       25600 / 100.00 GiB
  Free  PE / Size       2357874 / 8.99 TiB
  VG UUID               tsCO25-L5Rx-2qGn-2l1e-6vl0-fjJl-HaweHl
   
root@summergao:~#

如果看到 Free PE / Size > 0,表示还有扩容空间。

Free  PE / Size       2357874 / 8.99 TiB 这是还可以扩容的大小 。

解决办法

使用命令进行磁盘扩容

扩容指令示例如下:

#lvextend -L +10G /dev/mapper/ubuntu--vg-ubuntu--lv          //增加10G
#lvreduce -L -10G /dev/mapper/ubuntu--vg-ubuntu--lv          //减小10G
#lvresize -l  +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv    //按百分比扩

这里选择将所有空闲磁盘全部用来扩容

lvresize -l  +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
root@summergao:~# lvresize -l  +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from 100.00 GiB (25600 extents) to 9.09 TiB (2383474 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
root@summergao:~# 

执行resize2fs使扩容生效 (注意:不执行这个命令以上修改是不会生效的!)

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
root@summergao:~# 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 = 13, new_desc_blocks = 1164
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 2440677376 (4k) blocks long.

root@summergao:~# 

查看扩容结果

再次查看LVM卷组的信息,以及分区空间大小

vgdisplay
root@summergao:~# 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               9.09 TiB
  PE Size               4.00 MiB
  Total PE              2383474
  Alloc PE / Size       2383474 / 9.09 TiB
  Free  PE / Size       0 / 0   
  VG UUID               tsCO25-L5Rx-2qGn-2l1e-6vl0-fjJl-HaweHl

可以看到此时Free PE / Size 已经为0了

df -h 
root@summergao:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                                16G     0   16G   0% /dev
tmpfs                              3.2G  2.2M  3.2G   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  9.0T   11G  8.6T   1% /
tmpfs                               16G     0   16G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                               16G     0   16G   0% /sys/fs/cgroup
/dev/loop0                          64M   64M     0 100% /snap/core20/1828
/dev/loop2                          50M   50M     0 100% /snap/snapd/18357
/dev/loop1                          92M   92M     0 100% /snap/lxd/24061
/dev/sda2                          2.0G  112M  1.7G   7% /boot
/dev/sda1                          1.1G  6.1M  1.1G   1% /boot/efi
tmpfs                              3.2G     0  3.2G   0% /run/user/0
root@summergao:~# 

查看当前磁盘大小已经扩容到9.0T了

参考

ubuntu的ubuntu--vg-ubuntu--lv磁盘扩容 - 厚礼蝎 - 博客园

ubuntu server版 虚拟机根目录磁盘扩容_ubuntu--vg-ubuntu--lv只有100g-CSDN博客