当前位置: 首页 > 工具软件 > vg > 使用案例 >

如何扩大ubuntu的ubuntu--vg-ubuntu--lv空间

韶镜
2023-12-01

在使用virtualbox安装ubuntu时,默认被选中了lvm安装根分区,且根分区比较小。因此磁盘不够用。

扩大ubuntu的ubuntu–vg-ubuntu–lv空间

1 查看根分区空间:
root@jack:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               948M     0  948M   0% /dev
tmpfs                              199M  1.1M  198M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  9.8G  4.2G  5.1G  45% /
tmpfs                              992M     0  992M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              992M     0  992M   0% /sys/fs/cgroup
/dev/loop0                          62M   62M     0 100% /snap/core20/1328
/dev/loop1                          68M   68M     0 100% /snap/lxd/21835
/dev/sda2                          1.5G  110M  1.3G   8% /boot
/dev/loop2                          44M   44M     0 100% /snap/snapd/14978
tmpfs                              199M     0  199M   0% /run/user/0
root@jack:~# 
2 查看磁盘分区列表:
root@jack:~# fdisk -l
Disk /dev/loop0: 61.93 MiB, 64917504 bytes, 126792 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: 67.25 MiB, 70508544 bytes, 137712 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: 43.6 MiB, 45703168 bytes, 89264 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: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VBOX HARDDISK   
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: 58535BBF-9B80-4893-8549-607CF682F850

Device       Start      End  Sectors  Size Type
/dev/sda1     2048     4095     2048    1M BIOS boot
/dev/sda2     4096  3149823  3145728  1.5G Linux filesystem
/dev/sda3  3149824 41940991 38791168 18.5G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 10 GiB, 10737418240 bytes, 20971520 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
root@jack:~# 
3 增加根分区:

lvextend -L 20G /dev/mapper/ubuntu–vg-ubuntu–lv //增大或减小至20G
lvextend -L +20G /dev/mapper/ubuntu–vg-ubuntu–lv //增加20G
lvreduce -L -20G /dev/mapper/ubuntu–vg-ubuntu–lv //减小20G
lvresize -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv //按百分比扩容

resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv //执行调整

root@jack:~# lvextend -L 18.5G /dev/ubuntu-vg/ubuntu-lv 
  Insufficient free space: 10 extents needed, but only 9 available
root@jack:~# 
root@jack:~# 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 = 3
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 4848640 (4k) blocks long.

root@jack:~# 
4 查看lvm卷组的信息
root@jack:~# 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               <18.50 GiB
  PE Size               4.00 MiB
  Total PE              4735
  Alloc PE / Size       4735 / <18.50 GiB
  Free  PE / Size       0 / 0   
  VG UUID               xtesDm-VI8n-5Kzs-bFjF-UHQx-NjTM-XmGxIh
   
root@jack:~# 
5 再次查看根分区:
root@jack:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               948M     0  948M   0% /dev
tmpfs                              199M  1.1M  198M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   19G  4.2G   14G  25% /
tmpfs                              992M     0  992M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              992M     0  992M   0% /sys/fs/cgroup
/dev/loop0                          62M   62M     0 100% /snap/core20/1328
/dev/loop1                          68M   68M     0 100% /snap/lxd/21835
/dev/sda2                          1.5G  110M  1.3G   8% /boot
/dev/loop2                          44M   44M     0 100% /snap/snapd/14978
tmpfs                              199M     0  199M   0% /run/user/0
root@jack:~# 
root@jack:~# 
root@jack:~#
 类似资料: