下图以100GB的磁盘为例展示了Ubuntu安装程序默认创建的LVM结构:
LVM(Logical Volume Manager)是一个存在于物理(或虚拟)磁盘和Linux文件系统(如ext4)之间的抽象框架,用于将单独的块设备(分区)组合成Volume Group(VG),然后将这些VG分成逻辑块设备或逻辑卷Logical Volume(LV),LV是文件系统所在的抽象块设备。下面是一个示例,5个不同磁盘每个磁盘都有一个映射到物理卷(PV)的分区,所有这些PV都被分组到一个卷组(VG)中,卷组又被分成两个不同的逻辑卷(LV),每个LV用于一个文件系统:
先看基本挂载情况:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
root@amd:~# df -h Filesystem Size Used Avail Use% Mounted on udev 498G 0 498G 0% /dev tmpfs 100G 16M 100G 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 196G 11G 176G 6% / tmpfs 498G 4.0K 498G 1% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 498G 0 498G 0% /sys/fs/cgroup /dev/nvme0n1p2 1.5G 111M 1.3G 8% /boot /dev/nvme0n1p1 1.1G 5.3M 1.1G 1% /boot/efi /dev/loop0 62M 62M 0 100% /snap/core20/1328 /dev/mapper/ubuntu--vg-lv--1 1.5T 77M 1.4T 1% /home /dev/loop1 68M 68M 0 100% /snap/lxd/21835 /dev/loop2 44M 44M 0 100% /snap/snapd/14978 tmpfs 100G 0 100G 0% /run/user/1000 root@amd:~# free -h total used free shared buff/cache available Mem: 995Gi 1.5Gi 993Gi 16Mi 373Mi 989Gi Swap: 207Gi 0B 207Gi |
我们要挂载一块新磁盘扩展/home的大小。
然后看分区表:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
root@amd:~# 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/nvme1n1: 1.88 TiB, 2048408248320 bytes, 4000797360 sectors Disk model: HP SSD FX900 Pro 2TB 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: BA520F45-CA9F-433B-BD18-8B0C284366C9 Device Start End Sectors Size Type /dev/nvme1n1p1 2048 4000779403 4000777356 1.9T Microsoft basic data Disk /dev/nvme0n1: 1.88 TiB, 2048408248320 bytes, 4000797360 sectors Disk model: HP SSD FX900 Pro 2TB 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: F24FA021-CA6B-49F8-AA4B-6C5B6164B1AD Device Start End Sectors Size Type /dev/nvme0n1p1 2048 2203647 2201600 1.1G EFI System /dev/nvme0n1p2 2203648 5349375 3145728 1.5G Linux filesystem /dev/nvme0n1p3 5349376 4000794623 3995445248 1.9T Linux filesystem Disk /dev/sda: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors Disk model: Colorful SL500 4 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/md127: 14.93 TiB, 16386680160256 bytes, 32005234688 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 524288 bytes / 2097152 bytes Disk /dev/sdc: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors Disk model: Colorful SL500 4 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/sdd: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors Disk model: Colorful SL500 4 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/sdb: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors Disk model: Colorful SL500 4 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/mapper/ubuntu--vg-ubuntu--lv: 200 GiB, 214748364800 bytes, 419430400 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/mapper/ubuntu--vg-lv--0: 200 GiB, 214748364800 bytes, 419430400 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/mapper/ubuntu--vg-lv--1: 1.48 TiB, 1616170188800 bytes, 3156582400 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 |
其中的/dev/nvme1n1是要新加入的磁盘。
查看vg:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
root@amd:~# 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 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 1.86 TiB PE Size 4.00 MiB Total PE 487725 Alloc PE / Size 487725 / 1.86 TiB Free PE / Size 0 / 0 VG UUID k2CByu-s70e-Uv8H-nO8U-XayI-Q09e-cMqbz0 |
查看lv(Ubuntu安装时创建的):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
root@amd:~# lvdisplay --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID L5TsVy-4r3X-iQaE-tLmM-d2jc-w7Bz-YKg18k LV Write Access read/write LV Creation host, time ubuntu-server, 2022-08-24 14:28:08 +0000 LV Status available # open 1 LV Size 200.00 GiB Current LE 51200 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/ubuntu-vg/lv-0 LV Name lv-0 VG Name ubuntu-vg LV UUID X1LpBQ-lMs6-3yOH-GdcP-pP6N-4aIx-hzmegc LV Write Access read/write LV Creation host, time ubuntu-server, 2022-08-24 14:28:10 +0000 LV Status available # open 2 LV Size 200.00 GiB Current LE 51200 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/ubuntu-vg/lv-1 LV Name lv-1 VG Name ubuntu-vg LV UUID mVnswZ-qKoT-gPzF-wUEC-GSEI-pWs7-ml60Xr LV Write Access read/write LV Creation host, time ubuntu-server, 2022-08-24 14:28:11 +0000 LV Status available # open 1 LV Size <1.47 TiB Current LE 385325 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 |
查看软RAID:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
root@amd:~# mdadm /dev/md127 /dev/md127: 15261.29GiB raid0 4 devices, 0 spares. Use mdadm --detail for more detail. root@amd:~# mdadm --detail /dev/md127 /dev/md127: Version : 1.2 Creation Time : Tue Aug 23 09:31:13 2022 Raid Level : raid0 Array Size : 16002617344 (15261.29 GiB 16386.68 GB) Raid Devices : 4 Total Devices : 4 Persistence : Superblock is persistent Update Time : Tue Aug 23 09:31:13 2022 State : clean Active Devices : 4 Working Devices : 4 Failed Devices : 0 Spare Devices : 0 Layout : -unknown- Chunk Size : 512K Consistency Policy : none Name : amd:0 (local to host amd) UUID : bde4c9c3:9ec6ebf3:bb09406f:cc6f9ce2 Events : 0 Number Major Minor RaidDevice State 0 8 0 0 active sync /dev/sda 1 8 16 1 active sync /dev/sdb 2 8 32 2 active sync /dev/sdc 3 8 48 3 active sync /dev/sdd |
在新磁盘上创建pv:
1 2 3 4 5 6 7 8 |
root@amd:~# pvcreate /dev/nvme1n1 WARNING: gpt signature detected on /dev/nvme1n1 at offset 512. Wipe it? [y/n]: y Wiping gpt signature on /dev/nvme1n1. WARNING: gpt signature detected on /dev/nvme1n1 at offset 2048408247808. Wipe it? [y/n]: y Wiping gpt signature on /dev/nvme1n1. WARNING: PMBR signature detected on /dev/nvme1n1 at offset 510. Wipe it? [y/n]: y Wiping PMBR signature on /dev/nvme1n1. Physical volume "/dev/nvme1n1" successfully created. |
然后查看(会提示新的pv):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
root@amd:~# pvdisplay --- Physical volume --- PV Name /dev/nvme0n1p3 VG Name ubuntu-vg PV Size 1.86 TiB / not usable 0 Allocatable yes (but full) PE Size 4.00 MiB Total PE 487725 Free PE 0 Allocated PE 487725 PV UUID wuzoZj-ZHVb-WcpD-Q7P6-0lRC-WdWt-Mv7gcC "/dev/nvme1n1" is a new physical volume of "1.86 TiB" --- NEW Physical volume --- PV Name /dev/nvme1n1 VG Name PV Size 1.86 TiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID jlJflE-U79a-wvsc-kWtv-DpNB-f5Uh-LCXfsb |
此时vg是没有变化的(Free还是0):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
root@amd:~# 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 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 1.86 TiB PE Size 4.00 MiB Total PE 487725 Alloc PE / Size 487725 / 1.86 TiB Free PE / Size 0 / 0 VG UUID k2CByu-s70e-Uv8H-nO8U-XayI-Q09e-cMqbz0 |
vg扩容(注意参数中的/dev/nvme1n1是pv的名字),扩容后的Free变大了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
root@amd:~# vgextend ubuntu-vg /dev/nvme1n1 Volume group "ubuntu-vg" successfully extended root@amd:~# vgdisplay --- Volume group --- VG Name ubuntu-vg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 2 Act PV 2 VG Size 3.72 TiB PE Size 4.00 MiB Total PE 976103 Alloc PE / Size 487725 / 1.86 TiB Free PE / Size 488378 / 1.86 TiB VG UUID k2CByu-s70e-Uv8H-nO8U-XayI-Q09e-cMqbz0 |
lv扩容:
1 2 3 |
root@amd:~# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-lv--1 Size of logical volume ubuntu-vg/lv-1 changed from <1.47 TiB (385325 extents) to 3.33 TiB (873703 extents). Logical volume ubuntu-vg/lv-1 successfully resized. |
此时能够看到lv的大小变大了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
root@amd:~# lvdisplay --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID L5TsVy-4r3X-iQaE-tLmM-d2jc-w7Bz-YKg18k LV Write Access read/write LV Creation host, time ubuntu-server, 2022-08-24 14:28:08 +0000 LV Status available # open 1 LV Size 200.00 GiB Current LE 51200 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/ubuntu-vg/lv-0 LV Name lv-0 VG Name ubuntu-vg LV UUID X1LpBQ-lMs6-3yOH-GdcP-pP6N-4aIx-hzmegc LV Write Access read/write LV Creation host, time ubuntu-server, 2022-08-24 14:28:10 +0000 LV Status available # open 2 LV Size 200.00 GiB Current LE 51200 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/ubuntu-vg/lv-1 LV Name lv-1 VG Name ubuntu-vg LV UUID mVnswZ-qKoT-gPzF-wUEC-GSEI-pWs7-ml60Xr LV Write Access read/write LV Creation host, time ubuntu-server, 2022-08-24 14:28:11 +0000 LV Status available # open 1 LV Size 3.33 TiB Current LE 873703 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 |
此时的分区表:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
root@amd:~# 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/nvme0n1: 1.88 TiB, 2048408248320 bytes, 4000797360 sectors Disk model: HP SSD FX900 Pro 2TB 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: F24FA021-CA6B-49F8-AA4B-6C5B6164B1AD Device Start End Sectors Size Type /dev/nvme0n1p1 2048 2203647 2201600 1.1G EFI System /dev/nvme0n1p2 2203648 5349375 3145728 1.5G Linux filesystem /dev/nvme0n1p3 5349376 4000794623 3995445248 1.9T Linux filesystem Disk /dev/nvme1n1: 1.88 TiB, 2048408248320 bytes, 4000797360 sectors Disk model: HP SSD FX900 Pro 2TB 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/sdc: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors Disk model: Colorful SL500 4 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/sdb: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors Disk model: Colorful SL500 4 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: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors Disk model: Colorful SL500 4 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/md127: 14.93 TiB, 16386680160256 bytes, 32005234688 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 524288 bytes / 2097152 bytes Disk /dev/sdd: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors Disk model: Colorful SL500 4 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/mapper/ubuntu--vg-ubuntu--lv: 200 GiB, 214748364800 bytes, 419430400 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/mapper/ubuntu--vg-lv--0: 200 GiB, 214748364800 bytes, 419430400 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/mapper/ubuntu--vg-lv--1: 3.34 TiB, 3664575987712 bytes, 7157374976 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 |
注意到/dev/nvme1n1上看不出pv的分区。
然而,df看到/home的大小并未变化:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
root@amd:~# df -h Filesystem Size Used Avail Use% Mounted on udev 498G 0 498G 0% /dev tmpfs 100G 16M 100G 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 196G 11G 176G 6% / tmpfs 498G 4.0K 498G 1% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 498G 0 498G 0% /sys/fs/cgroup /dev/nvme0n1p2 1.5G 111M 1.3G 8% /boot /dev/nvme0n1p1 1.1G 5.3M 1.1G 1% /boot/efi /dev/loop0 62M 62M 0 100% /snap/core20/1328 /dev/mapper/ubuntu--vg-lv--1 1.5T 77M 1.4T 1% /home /dev/loop1 68M 68M 0 100% /snap/lxd/21835 /dev/loop2 44M 44M 0 100% /snap/snapd/14978 tmpfs 100G 0 100G 0% /run/user/1000 |
使用resize2fs扩容文件系统:
转载时请保留出处,违法转载追究到底:进城务工人员小梅 » Ubuntu 20.04 vg扩容(增加新磁盘)