系统相关
首页 > 系统相关> > 解决 Linux /dev/mapper/ubuntu--vg-ubuntu--lv 磁盘空间不足的问题

解决 Linux /dev/mapper/ubuntu--vg-ubuntu--lv 磁盘空间不足的问题

作者:互联网

之前在 VMware 安装 Ubuntu Server 的时候 磁盘分区 选择了 LVM,所以系统根目录默认占用磁盘大小只有默认大小(10G),在安装软件时发现磁盘空间已经无法满足,所以需要利用 LVM 对磁盘进行扩容。

root@ubuntu:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               451M     0  451M   0% /dev
tmpfs                               97M  1.3M   96M   2% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  3.9G  3.4G  287M  93% /
tmpfs                              482M     0  482M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              482M     0  482M   0% /sys/fs/cgroup
/dev/loop0                          92M   92M     0 100% /snap/core/8689
/dev/loop1                          90M   90M     0 100% /snap/core/8268
/dev/sda2                          976M   77M  832M   9% /boot
tmpfs                               97M     0   97M   0% /run/user/0

可以发现 /dev/mapper/ubuntu--vg-ubuntu--lv 虚拟机根目录空间只有3.9G,使用了93%

root@ubuntu:~# 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               <19.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       1024 / 4.00 GiB
  Free  PE / Size       3839 / <15.00 GiB
  VG UUID               hZPoxm-kSBU-fmKs-2yXD-hHoe-3T7e-PCIFSe

  Free PE / Size 3839 / <15.00 GiB,这是还可以扩充的大小

lvextend -L 10G /dev/mapper/ubuntu--vg-ubuntu--lv      //增大或减小至19G
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            //执行调整
// 按百分比进行磁盘扩容
root@ubuntu:~# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from 4.00 GiB (1024 extents) to <19.00 GiB (4863 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.
  
// 刷新分区 
root@ubuntu:~# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv 
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 4979712 (4k) blocks long.

// 查看文件系统磁盘空间的使用情况(发现此时已经扩容到19G)
root@ubuntu:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               451M     0  451M   0% /dev
tmpfs                               97M  1.3M   96M   2% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   19G  3.9G   14G  22% /
tmpfs                              482M     0  482M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              482M     0  482M   0% /sys/fs/cgroup
/dev/loop0                          92M   92M     0 100% /snap/core/8689
/dev/loop1                          90M   90M     0 100% /snap/core/8268
/dev/sda2                          976M   77M  832M   9% /boot
tmpfs                               97M     0   97M   0% /run/user/0

// 再次查看LVM卷组的信息(可扩容的空间已经成为0)
root@ubuntu:~# vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  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               <19.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               hZPoxm-kSBU-fmKs-2yXD-hHoe-3T7e-PCIFSec

copy了原文的内容,抄也要认真抄

全文引用自:https://blog.csdn.net/Fly_1213/article/details/105142427 

标签:mapper,vg,--,dev,lv,ubuntu
来源: https://www.cnblogs.com/gcc2020/p/16601857.html