Solve the problem of insufficient disk space in Linux /dev/mapper/ubuntu--vg-ubuntu--lv

  • Before installing Ubuntu Server in VMware , I chose LVM for the disk partition, so the default disk size occupied by the system root directory is only 4G. When installing the software, I found that the disk space of 4G is not enough, so I need to use LVM to expand the disk capacity .
  • View file system disk space usage
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

It can be found that /dev/mapper/ubuntu--vg-ubuntu--lvthe root directory space of the virtual machine is only 3.9G, 93% of which is used.

  • View information about LVM volume groups
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, this is the size that can be expanded

  • Use commands to expand disk capacity
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            //重新调整逻辑卷大小
  • The specific operation is as follows
// 按百分比进行磁盘扩容
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-PCIFSe

A brief introduction to the operation commands involved:

  • View block device information [-f]: Display the file system type (such as ext4, NTFS, FAT32, etc.) of each block device and the label of the file system (if any).
root@ubuntu:/home/michael# lsblk -f
NAME FSTYPE FSVER LABEL UUID                                   FSAVAIL FSUSE% MOUNTPOINTS
loop0
     squash 4.0                                                      0   100% /snap/chromium/2497
loop1
     squash 4.0                                                      0   100% /snap/chromium/2529
loop2
     squash 4.0                                                      0   100% /snap/core20/1950
loop3
     squash 4.0                                                      0   100% /snap/core20/1974
loop4
     squash 4.0                                                      0   100% /snap/core22/806
loop5
     squash 4.0                                                      0   100% /snap/bare/5
loop6
     squash 4.0                                                      0   100% /snap/core22/817
loop7
     squash 4.0                                                      0   100% /snap/cups/974
loop8
     squash 4.0                                                      0   100% /snap/cups/980
loop9
     squash 4.0                                                      0   100% /snap/firefox/2908
loop10
     squash 4.0                                                      0   100% /snap/firefox/2850
loop11
     squash 4.0                                                      0   100% /snap/lxd/22753
loop12
     squash 4.0                                                      0   100% /snap/gnome-3-38-2004/140
loop13
     squash 4.0                                                      0   100% /snap/gtk-common-themes/1535
loop14
     squash 4.0                                                      0   100% /snap/gnome-3-38-2004/143
loop15
     squash 4.0                                                      0   100% /snap/snapd/19361
loop16
     squash 4.0                                                      0   100% /snap/lxd/24061
loop17
     squash 4.0                                                      0   100% /snap/snapd/19457
sda                                                                           
├─sda1
│    ext2   1.0         0c16e136-b08b-48e6-beb1-27379362182b    417.3M    37% /boot
├─sda2
└─sda5
     LVM2_m LVM2        qjGstm-EyqI-EL1p-tm6H-TZkq-tQt2-0Asw5u                
  ├─ubuntu--vg-root
  │  ext4   1.0         02df78f3-9fac-45f6-a163-bc25f8477529     19.2G    79% /var/snap/firefox/common/host-hunspell
  │                                                                           /
  └─ubuntu--vg-swap_1
     swap   1           f1afd974-2f40-42f3-b9bc-a89da3b559d8                  [SWAP]
sr0                                                                           
  • Display the detailed information of the physical volume, including the name, size, volume group, status, etc. of the physical volume.
root@ubuntu:/home/michael# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               ubuntu-vg
  PV Size               119.28 GiB / not usable 0   
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              30536
  Free PE               0
  Allocated PE          30536
  PV UUID               qjGstm-EyqI-EL1p-tm6H-TZkq-tQt2-0Asw5u
   
  • Display the detailed information of the volume group, including the name of the volume group, the number of physical volumes, the number of logical volumes, the total size, free space, etc.
root@ubuntu:/home/michael# vgdisplay 
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               119.28 GiB
  PE Size               4.00 MiB
  Total PE              30536
  Alloc PE / Size       30536 / 119.28 GiB
  Free  PE / Size       0 / 0   
  VG UUID               xwbdQH-DBvq-qdzk-DQ3H-ofgA-0Y4B-Sl3FwF
   
  • Display the detailed information of the logical volume, such as the name, size, path, status, etc. of the logical volume.
root@ubuntu:/home/michael# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/root
  LV Name                root
  VG Name                ubuntu-vg
  LV UUID                zIloDt-sa12-qqXk-7fKM-6Veu-09Pq-aedUBb
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2022-06-29 11:28:04 +0800
  LV Status              available
  # open                 1
  LV Size                <118.33 GiB
  Current LE             30292
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/swap_1
  LV Name                swap_1
  VG Name                ubuntu-vg
  LV UUID                di3eEs-oTyG-4u4z-JlVF-2P7a-6ke0-x6tIqx
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2022-06-29 11:28:04 +0800
  LV Status              available
  # open                 2
  LV Size                976.00 MiB
  Current LE             244
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  • Show filesystem usage 
  • [-h]: Display the file system size in an easy-to-read manner, converting byte units to the more common kilobytes, megabytes, and gigabytes.
  • [-T]: Display the file system type in the output.
root@ubuntu:/home/michael# df -hT
Filesystem                  Type   Size  Used Avail Use% Mounted on
tmpfs                       tmpfs  791M  3.6M  787M   1% /run
/dev/mapper/ubuntu--vg-root ext4   117G   92G   20G  83% /
tmpfs                       tmpfs  3.9G     0  3.9G   0% /dev/shm
tmpfs                       tmpfs  5.0M  4.0K  5.0M   1% /run/lock
/dev/sda1                   ext2   719M  265M  418M  39% /boot
tmpfs                       tmpfs  791M  116K  791M   1% /run/user/1000

Guess you like

Origin blog.csdn.net/FLM19990626/article/details/131888427