0%

Ubuntu 22.04上向现有的逻辑卷管理(LVM)中添加额外的磁盘

Add new disk on LVM for Ubuntu 22.04 LTS

这些说明将帮助您在Ubuntu 22.04上向现有的逻辑卷管理(LVM)中添加额外的磁盘。LVM可以帮助您轻松地扩展存储空间跨多个物理磁盘设备。

用于向当前磁盘扩展空间

  1. 找出要分配给LVM的磁盘
1
2
3
4
sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda3 ubuntu-vg lvm2 a-- <8.25g 0
/dev/vdb ubuntu-vg lvm2 a-- <50.00g 0

查看详细信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ sudo pvdisplay
--- Physical volume ---
PV Name /dev/vda3
VG Name ubuntu-vg
PV Size <8.25 GiB / not usable 0
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2111
Free PE 0
Allocated PE 2111
PV UUID 96Cnvs-1rYe-xWk8-lB2V-cLSd-ALqk-4ujiPc

--- Physical volume ---
PV Name /dev/vdb
VG Name ubuntu-vg
PV Size 50.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 12799
Free PE 0
Allocated PE 12799
PV UUID Hle3gv-3FNW-jkoe-dRFf-CwWd-pdJx-MWy3Ad
  1. 获取LVM的路径
1
2
3
$ sudo lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv

省略了其他信息

  1. 找到要添加的新磁盘
1
2
3
4
5
6
7
8
9
10
$ sudo fdisk -l | grep '^Disk /dev/'
Disk /dev/loop0: 63.24 MiB, 66314240 bytes, 129520 sectors
Disk /dev/loop1: 63.23 MiB, 66301952 bytes, 129496 sectors
Disk /dev/loop2: 79.95 MiB, 83832832 bytes, 163736 sectors
Disk /dev/loop3: 102.98 MiB, 107986944 bytes, 210912 sectors
Disk /dev/loop4: 49.62 MiB, 52031488 bytes, 101624 sectors
Disk /dev/vda: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk /dev/vdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk /dev/vdc: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 558.24 GiB, 599403790336 bytes, 1170710528 sectors

在本例中,它将是/dev/vdc,因为我向这个实例添加了一个500GB的磁盘驱动器。

  1. 在新的磁盘驱动器上创建物理卷
1
2
$ sudo pvcreate /dev/vdc
Physical volume "/dev/vdc" successfully created.
  1. 扩展现有卷组以包含这个新的磁盘驱动器
1
2
$ sudo vgextend ubuntu-vg /dev/vdc
Volume group "ubuntu-vg" successfully extended
  1. 扩展LV大小以包含100%的新磁盘
1
2
3
$ sudo lvm lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 58.24 GiB (14910 extents) to <558.24 GiB (142909 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
  1. 现在需要调整文件系统的大小以匹配新的大小
1
2
3
4
5
$ sudo resize2fs -p /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 8, new_desc_blocks = 70
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 146338816 (4k) blocks long.
  1. 现在可以用df -kh来验证
1
2
3
4
5
6
7
8
9
$ df -kh
Filesystem Size Used Avail Use% Mounted on
tmpfs 9.9G 1.6M 9.9G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 550G 8.9G 519G 2% /
tmpfs 50G 0 50G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 50G 0 50G 0% /run/qemu
/dev/vda2 1.7G 247M 1.4G 16% /boot
tmpfs 9.9G 4.0K 9.9G 1% /run/user/1000

参考: