Linux LVM 创建 删除 扩展 收缩

创建LVM

查看物理磁盘:

1
2
3
4
5
6
7
[root@localhost ~]# parted -l | grep 'Disk /dev/s' #如果分区表是GPT
[root@localhost ~]# fdisk -l | grep 'Disk /dev/s' #如果分区表是MBR
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sdd: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
[root@localhost ~]#

硬盘初始化

如果磁盘是2T或者2T以内 初始化为MBR

1
2
3
[root@localhost ~]# parted -s /dev/sdb mklabel msdos
[root@localhost ~]# parted -s /dev/sdc mklabel msdos
[root@localhost ~]# parted -s /dev/sdd mklabel msdos

如果磁盘是超过2T 初始化为GPT

1
2
3
[root@localhost ~]# parted -s /dev/sdb mklabel  gpt
[root@localhost ~]# parted -s /dev/sdc mklabel gpt
[root@localhost ~]# parted -s /dev/sdd mklabel gpt

在空闲磁盘上创建PV

1
2
3
4
[root@localhost ~]# pvcreate /dev/sdb
[root@localhost ~]# pvcreate /dev/sdc
[root@localhost ~]# pvcreate /dev/sdd
[root@localhost ~]# pvdisplay #验证上述结果

基于PV上创建VG

1
2
3
4
5
6
[root@localhost ~]# vgcreate VG_chunli /dev/sdb /dev/sdc /dev/sdd #创建名为'VG_chunli'的卷组
[root@localhost ~]# vgdisplay #验证上述结果
[root@localhost ~]# vgs #验证上述结果
VG #PV #LV #SN Attr VSize VFree
VG_chunli 3 0 0 wz--n- 59.99g 59.99g
[root@localhost ~]#

基于VG创建逻辑卷:

1
2
[root@localhost ~]# lvcreate --name Logic_chunli --size 59G   VG_chunli
[root@localhost ~]# lvdisplay

开机自动挂载:

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
[root@localhost ~]# mkfs.ext4 /dev/VG_chunli/Logic_chunli
[root@localhost ~]# mkdir /mnt/mount
[root@localhost ~]# blkid /dev/VG_chunli/Logic_chunli
/dev/VG_chunli/Logic_chunli: UUID="739588df-466a-41c2-a703-8860fe849134" TYPE="ext4"
[root@localhost ~]# vim /etc/fstab #在尾行追加
UUID="739588df-466a-41c2-a703-8860fe849134" /mnt/mount ext4 defaults 1 2
[root@localhost ~]# mount -a
[root@localhost ~]# df -hT #查看挂载信息
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VG_chunli-Logic_chunli ext4 58G 53M 55G 1% /mnt/mount
[root@localhost ~]#



[root@localhost ~]# vgs #查看剩余的VG
VG #PV #LV #SN Attr VSize VFree
VG_chunli 3 1 0 wz--n- 59.99g 1012.00m
[root@localhost ~]#

[root@localhost ~]# pvs #查看剩余的PV
PV VG Fmt Attr PSize PFree
/dev/sdb VG_chunli lvm2 a-- 20.00g 0
/dev/sdc VG_chunli lvm2 a-- 20.00g 0
/dev/sdd VG_chunli lvm2 a-- 20.00g 1012.00m
[root@localhost ~]#

LVM 删除

1
2
3
4
[root@localhost ~]# umount /dev/VG_chunli/LV_chunli
[root@localhost ~]# lvremove /dev/VG_chunli/LV_chunli
[root@localhost ~]# vgremove VG_chunli
[root@localhost ~]# pvremove /dev/sdb

LVM 扩容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@localhost ~]# fdisk -l | grep '/dev/s'
Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 419430399 208665600 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sdd: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sde: 161.1 GB, 161061273600 bytes, 314572800 sectors


[root@localhost ~]# pvcreate /dev/sde
[root@localhost ~]# vgs #查看已经存在的VG
VG #PV #LV #SN Attr VSize VFree
VG_chunli 3 1 0 wz--n- 59.99g 1012.00m
cl 1 3 0 wz--n- 199.00g 4.00m
[root@localhost ~]#
[root@localhost ~]# vgextend cl /dev/sde #扩展cl
[root@localhost ~]# lvextend --size 200G /dev/cl/home
[root@localhost ~]# df -hT
/dev/mapper/cl-home xfs 150G 33M 150G 1% /home
[root@localhost ~]# xfs_growfs /dev/cl/home
[root@localhost ~]# df -hT
/dev/mapper/cl-home xfs 200G 33M 200G 1% /home
[root@localhost ~]#

LVM 收缩

1
未完待续。。。