0%

centos7中lvm分区的创建与扩展


创建LVM分区

首先,挂载虚拟硬盘到虚拟机上,这里挂了2个1T的硬盘。

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
$ lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 9.8G 0 lvm [SWAP]
└─centos-home 253:2 0 39.2G 0 lvm /home
sdb 8:16 0 1T 0 disk
sdc 8:32 0 1T 0 disk
sr0 11:0 1 1024M 0 rom

// 创建物理卷
$ sudo pvcreate /dev/sdb

Physical volume "/dev/sdb" successfully created.

// 创建卷组
$ sudo vgcreate VG1 /dev/sdb

Volume group "VG1" successfully created

// 查看卷组剩多少PE
$ sudo vgdisplay

...
--- Volume group ---
VG Name VG1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size <2.00 TiB
PE Size 4.00 MiB
Total PE 524286
Alloc PE / Size 262143 / <1024.00 GiB
Free PE / Size 262143 / <1024.00 GiB //剩余空间大小
VG UUID DYPyVN-9ssj-pLxN-bksi-9U0V-m2wQ-aQ3IPe
...

// 将所有剩余空间创建为逻辑卷
$ sudo lvcreate -l 262143 -n MyLvm0 VG1

Logical volume "MyLvm0" created.

// 创建完成
$ lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 9.8G 0 lvm [SWAP]
└─centos-home 253:2 0 39.2G 0 lvm /home
sdb 8:16 0 1T 0 disk
└─VG1-MyLvm0 253:3 0 1024G 0 lvm // 所创建的LVM逻辑卷
sdc 8:32 0 1T 0 disk
sr0 11:0 1 1024M 0 rom

扩展LVM分区

上面使用了一块1T虚拟硬盘,下面将另外一块虚拟硬盘添加到刚才的逻辑卷中,实现扩展。

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
$ lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 9.8G 0 lvm [SWAP]
└─centos-home 253:2 0 39.2G 0 lvm /home
sdb 8:16 0 1T 0 disk
└─VG1-MyLvm0 253:3 0 1024G 0 lvm // 需要扩展的LVM逻辑卷
sdc 8:32 0 1T 0 disk // 额外的空间
sr0 11:0 1 1024M 0 rom

// 创建物理卷
$ sudo pvcreate /dev/sdc

Physical volume "/dev/sdc" successfully created.

// 将它加入到卷组
$ sudo vgextend VG1 /dev/sdc

Volume group "VG1" successfully extended

// 扩展逻辑卷MyLvm0
$ sudo lvextend -l +262142 /dev/VG1/MyLvm0

Size of logical volume VG1/MyLvm0 changed from 1.00 TiB (262144 extents) to <2.00 TiB (524286 extents).
Logical volume VG1/MyLvm0 successfully resized.

// 成功扩展
$ lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 9.8G 0 lvm [SWAP]
└─centos-home 253:2 0 39.2G 0 lvm /home
sdb 8:16 0 1T 0 disk
└─VG1-MyLvm0 253:3 0 2T 0 lvm
sdc 8:32 0 1T 0 disk
└─VG1-MyLvm0 253:3 0 2T 0 lvm
sr0 11:0 1 1024M 0 rom

参考

Linux下添加磁盘创建lvm分区

centos7用lvm扩展xfs文件系统的根分区