0. 逻辑卷的介绍
https://www.jianshu.com/p/a1bb79824b15
1. 准备磁盘
准备将整块磁盘sdc和磁盘分区sdb1制作成一个卷组
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 5G 0 part
└─sdb2 8:18 0 5G 0 part
sdc 8:32 0 20G 0 disk
2. 制作物理卷
[root@centos7 ~]# pvcreate /dev/sdb1 /dev/sdc
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdc" successfully created.
[root@centos7 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 5.00g 5.00g
/dev/sdc lvm2 --- 20.00g 20.00g
[root@centos7 ~]# pvdisplay
"/dev/sdc" is a new physical volume of "20.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 20.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID KiBce4-GWc0-hIr0-MyWG-FzXy-oqmi-YNWgvc
"/dev/sdb1" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID kqh9OO-9H6p-JCg3-Glwy-P9FT-tvKV-s83P7j
3. 制作卷组
[root@centos7 ~]# vgcreate -s 4M myvg1 /dev/sdc /dev/sdb1
Volume group "myvg1" successfully created
[root@centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg1 2 0 0 wz--n- 24.99g 24.99g
[root@centos7 ~]# vgdisplay
--- Volume group ---
VG Name myvg1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 24.99 GiB
PE Size 4.00 MiB
Total PE 6398
Alloc PE / Size 0 / 0
Free PE / Size 6398 / 24.99 GiB
VG UUID bmpKGY-UiP5-VR9T-xiCQ-UilE-ZRzP-JIs6H5
[root@centos7 ~]# blkid
/dev/sr0: UUID="2019-09-11-18-50-31-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sda1: UUID="a089259d-63ba-4099-966f-d0e753e08650" TYPE="xfs"
/dev/sda2: UUID="78e8f470-86be-4e06-9d7a-7f0cc1862827" TYPE="xfs"
/dev/sda3: UUID="95ef2603-1f60-459d-b931-16bc81a213f6" TYPE="xfs"
/dev/sda5: UUID="36751366-63ee-42ff-bad6-7517bffe6747" TYPE="swap"
/dev/sdb1: UUID="kqh9OO-9H6p-JCg3-Glwy-P9FT-tvKV-s83P7j" TYPE="LVM2_member"
/dev/sdc: UUID="KiBce4-GWc0-hIr0-MyWG-FzXy-oqmi-YNWgvc" TYPE="LVM2_member"
4. 制作逻辑卷
[root@centos7 ~]# lvcreate -n mvlv1 -L 5G myvg1
Logical volume "mvlv1" created.
[root@centos7 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mvlv1 myvg1 -wi-a----- 5.00g
[root@centos7 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg1/mvlv1
LV Name mvlv1
VG Name myvg1
LV UUID 7jMEkK-zzLy-CrTy-ect1-waFq-ZKhP-MkwXm8
LV Write Access read/write
LV Creation host, time centos7, 2020-04-06 14:59:52 +0800
LV Status available
# open 0
LV Size 5.00 GiB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg1 2 1 0 wz--n- 24.99g 19.99g
NOTE:从名称为myvg1的卷组中划分出逻辑卷,设置名称为mylv1,大小为5G左右。
LV的路径为/dev/myvg1/mylv1,这是一个软链接,另一个软链接路路径是/dev/mapper/myvg1-mylv1,它们的实际路径为/dev/dm-0。在创建LV时,要考虑到VG的剩余空间的大小,避免创建LV是VG的空间不足。
[root@centos7 dev]# ll /dev/myvg1/mvlv1
lrwxrwxrwx. 1 root root 7 Apr 6 14:59 /dev/myvg1/mvlv1 -> ../dm-0
[root@centos7 dev]# ll /dev/mapper/myvg1-mvlv1
lrwxrwxrwx. 1 root root 7 Apr 6 14:59 /dev/mapper/myvg1-mvlv1 -> ../dm-0
5. 创建ext4文件系统
[root@centos7 ~]# mkfs.ext4 /dev/myvg1/mvlv1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@centos7 ~]# blkid
/dev/sda5: UUID="36751366-63ee-42ff-bad6-7517bffe6747" TYPE="swap"
/dev/sdb1: UUID="kqh9OO-9H6p-JCg3-Glwy-P9FT-tvKV-s83P7j" TYPE="LVM2_member"
/dev/sdc: UUID="KiBce4-GWc0-hIr0-MyWG-FzXy-oqmi-YNWgvc" TYPE="LVM2_member"
/dev/mapper/myvg1-mvlv1: UUID="7f9d131e-ce66-4bda-8f08-47b69a38d713" TYPE="ext4"
6. 创建开机挂载
[root@centos7 ~]# mkdir /mnt/mvlvm
[root@centos7 ~]# mount /dev/mapper/myvg1-mvlv1 /mnt/mvlvm
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 5G 0 part
└─sdb2 8:18 0 5G 0 part
sdc 8:32 0 20G 0 disk
└─myvg1-mvlv1 253:0 0 5G 0 lvm /mnt/mvlvm
[root@centos7 ~]# umount /mnt/mvlvm
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 5G 0 part
└─sdb2 8:18 0 5G 0 part
sdc 8:32 0 20G 0 disk
└─myvg1-mvlv1 253:0 0 5G 0 lvm
[root@centos7 ~]# vim /etc/fstab
/dev/myvg1/mvlv1 /mnt/mvlvm ext4 defaults 0 0
[root@centos7 ~]# mount -a
[root@centos7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sr0 4.4G 4.4G 0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/myvg1-mvlv1 4.8G 20M 4.6G 1% /mnt/mvlvm
7. 扩展逻辑卷
扩展LV时,要分两种情况:情况一,当VG有足够空间时可直接扩展LV;情况二,当VG没有足够空间,需要先扩展VG,才能在扩展LV。
本次就以情况二为例,进行扩展:以此前剩下的sdb2进行创建。
7.1 创建PV
[root@centos7 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 myvg1 lvm2 a-- <5.00g <5.00g
/dev/sdc myvg1 lvm2 a-- <20.00g <15.00g
[root@centos7 ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created.
[root@centos7 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 myvg1 lvm2 a-- <5.00g <5.00g
/dev/sdb2 lvm2 --- 5.00g 5.00g
/dev/sdc myvg1 lvm2 a-- <20.00g <15.00g
[root@centos7 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdc
VG Name myvg1
PV Size 20.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 5119
Free PE 3839
Allocated PE 1280
PV UUID KiBce4-GWc0-hIr0-MyWG-FzXy-oqmi-YNWgvc
--- Physical volume ---
PV Name /dev/sdb1
VG Name myvg1
PV Size 5.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1279
Free PE 1279
Allocated PE 0
PV UUID kqh9OO-9H6p-JCg3-Glwy-P9FT-tvKV-s83P7j
"/dev/sdb2" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID RqssYJ-L6Cv-n3vD-Dymv-BQmM-rYWq-ZdVzUd
7.2 扩展VG
[root@centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg1 2 1 0 wz--n- 24.99g 19.99g
[root@centos7 ~]# vgextend myvg1 /dev/sdb2
Volume group "myvg1" successfully extended
[root@centos7 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
myvg1 3 1 0 wz--n- <29.99g <24.99g
[root@centos7 ~]# vgdisplay
--- Volume group ---
VG Name myvg1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size <29.99 GiB
PE Size 4.00 MiB
Total PE 7677
Alloc PE / Size 1280 / 5.00 GiB
Free PE / Size 6397 / <24.99 GiB
VG UUID bmpKGY-UiP5-VR9T-xiCQ-UilE-ZRzP-JIs6H5
7.3 扩展LV并重置文件系统大小
[root@centos7 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mvlv1 myvg1 -wi-ao---- 5.00g
[root@centos7 ~]# lvextend -r -L +23G /dev/myvg1/mvlv1
Size of logical volume myvg1/mvlv1 changed from 5.00 GiB (1280 extents) to 28.00 GiB (7168 extents).
Logical volume myvg1/mvlv1 successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/myvg1-mvlv1 is mounted on /mnt/mvlvm; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 4
The filesystem on /dev/mapper/myvg1-mvlv1 is now 7340032 blocks long.
[root@centos7 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mvlv1 myvg1 -wi-ao---- 28.00g
[root@centos7 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg1/mvlv1
LV Name mvlv1
VG Name myvg1
LV UUID 7jMEkK-zzLy-CrTy-ect1-waFq-ZKhP-MkwXm8
LV Write Access read/write
LV Creation host, time centos7, 2020-04-06 14:59:52 +0800
LV Status available
# open 1
LV Size 28.00 GiB
Current LE 7168
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@centos7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 182M 36K 182M 1% /run/user/0
/dev/sr0 4.4G 4.4G 0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/myvg1-mvlv1 28G 28M 27G 1% /mnt/mvlvm
NOTE:逻辑卷除了扩展,还可以进行缩减,以及从LVM系统中移除硬盘,跨主机迁移逻辑卷,甚至是快照功能。在此就不一一示范,有需要可自行百度。
网友评论