ESXI中开启了LVM的Linux磁盘扩容

ESXI中安装了一个Ubuntu Server,安装的时候选择了LVM

desktop版:

安装后发现,明明ESXI中置备了32GB的磁盘,实际可使用只有20GB

通过 df -h 命令,发现/dev/mapper/ubuntu–vg-ubuntu–lv分区确实只有20G空间,已经用了17G,只剩下2G空间了。

~$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               941M     0  941M   0% /dev
tmpfs                              198M  2.1M  195M   2% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   20G   17G  2.0G  90% /
tmpfs                              986M     0  986M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              986M     0  986M   0% /sys/fs/cgroup
/dev/sda2                          974M  308M  600M  34% /boot
/dev/loop0                          56M   56M     0 100% /snap/core18/2785
/dev/loop2                          64M   64M     0 100% /snap/core20/1974
/dev/loop1                          56M   56M     0 100% /snap/core18/2790
/dev/loop3                          64M   64M     0 100% /snap/core20/2015
/dev/loop4                          92M   92M     0 100% /snap/lxd/24061
/dev/loop5                          92M   92M     0 100% /snap/lxd/23991
/dev/sda1                          511M  6.1M  505M   2% /boot/efi
/dev/loop6                          41M   41M     0 100% /snap/snapd/20092
/dev/loop7                          41M   41M     0 100% /snap/snapd/20290
tmpfs                              198M     0  198M   0% /run/user/1000

通过 lsblk 命令发现实际上这个磁盘是有30G空间的,只是划分了20G

~$ lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0                       7:0    0 55.7M  1 loop /snap/core18/2785
loop1                       7:1    0 55.7M  1 loop /snap/core18/2790
loop2                       7:2    0 63.5M  1 loop /snap/core20/1974
loop3                       7:3    0 63.5M  1 loop /snap/core20/2015
loop4                       7:4    0 91.9M  1 loop /snap/lxd/24061
loop5                       7:5    0 91.8M  1 loop /snap/lxd/23991
loop6                       7:6    0 40.9M  1 loop /snap/snapd/20092
loop7                       7:7    0 40.9M  1 loop /snap/snapd/20290
sda                         8:0    0   32G  0 disk 
├─sda1                      8:1    0  512M  0 part /boot/efi
├─sda2                      8:2    0    1G  0 part /boot
└─sda3                      8:3    0 30.5G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0   20G  0 lvm  /

通过 vgdisplay 命令查看是否可以扩容

~$ sudo vgdisplay
[sudo] password for adam: 
  --- 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               <30.50 GiB
  PE Size               4.00 MiB
  Total PE              7807
  Alloc PE / Size       5120 / 20.00 GiB
  Free  PE / Size       2687 / <10.50 GiB
  VG UUID               qt7jFa-URZd-eoFV-E3uc-zmS1-f1e2-YWQIEj

Free PE / Size 2687 / <10.50 GiB,可见可以扩容。通过 lvextend -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv 命令实现扩容

命令的用法是:

lvextend -L 10G /dev/mapper/ubuntu--vg-ubuntu--lv      //增大或减小至10G
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   //按百分比扩容

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv            //执行调整
~$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from 20.00 GiB (5120 extents) to <30.50 GiB (7807 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

通过 resize2fs 命令刷新

~$ sudo 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 = 3, new_desc_blocks = 4
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 7994368 (4k) blocks long.

再次通过 df -h 查看,可见变成了30G

~$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               941M     0  941M   0% /dev
tmpfs                              198M  2.1M  195M   2% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   30G   17G   12G  59% /
tmpfs                              986M     0  986M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              986M     0  986M   0% /sys/fs/cgroup
/dev/sda2                          974M  308M  600M  34% /boot
/dev/loop0                          56M   56M     0 100% /snap/core18/2785
/dev/loop2                          64M   64M     0 100% /snap/core20/1974
/dev/loop1                          56M   56M     0 100% /snap/core18/2790
/dev/loop3                          64M   64M     0 100% /snap/core20/2015
/dev/loop4                          92M   92M     0 100% /snap/lxd/24061
/dev/loop5                          92M   92M     0 100% /snap/lxd/23991
/dev/sda1                          511M  6.1M  505M   2% /boot/efi
/dev/loop6                          41M   41M     0 100% /snap/snapd/20092
/dev/loop7                          41M   41M     0 100% /snap/snapd/20290
tmpfs                              198M     0  198M   0% /run/user/1000

ESXI中也变了:

参考文献:

https://blog.csdn.net/qq_39718408/article/details/118699328

https://www.cnblogs.com/ericdee/p/14025692.html

https://zhuanlan.zhihu.com/p/639128042

Share

You may also like...

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注