目录
知识点:
物理卷(physical volume):简称PV
卷组(Volume Group):简称VG
逻辑卷(logical volume):简称LV
常用命令
功能/命令 | 物理卷管理 | 卷组管理 | 逻辑卷管理 |
---|---|---|---|
扫描 | pvscan | vgscan | lvscan |
建立 | pvcreate | vgcreate | lvcreate |
显示 | pvdisplay | vgdisplay | lvdisplay |
删除 | pvremove | vgremove | lvremove |
扩展 | vgextend | lvextend | |
缩小 | vgreduce | lvreduce |
题目:
从新硬盘制作三个分区每个分区都 3GB大小, 将三个分区只作为物理卷,通过这三个物理卷创建卷组 通过卷组生成一个逻辑卷,大小为7G,再将逻辑卷调整到10G
解题:
1)分区
bash
[root@HeHe ~]# lsblk | grep nvme0n2
nvme0n2 259:4 0 20G 0 disk
├─nvme0n2p1 259:5 0 3G 0 part
├─nvme0n2p2 259:6 0 3G 0 part
└─nvme0n2p3 259:7 0 3G 0 part
2)创建物理卷
bash
[root@HeHe ~]# pvcreate /dev/nvme0n2p1 /dev/nvme0n2p2 /dev/nvme0n2p3
WARNING: xfs signature detected on /dev/nvme0n2p1 at offset 0. Wipe it? [y/n]: y
---
3)创建卷组
bash
[root@HeHe ~]# vgcreate vg1 /dev/nvme0n2p1 /dev/nvme0n2p2 /dev/nvme0n2p3
Volume group "vg1" successfully created
---
4)生成逻辑卷 "要带参数 -n"
bash
[root@HeHe ~]# lvcreate -n lv1 -L 7G vg1
Logical volume "lv1" created.
---
检验
lvdisplay /dev/vg1/lv1 "逻辑卷的存放地方"
[root@HeHe ~]# lvdisplay /dev/vg1/lv1
---
LV Size 7.00 GiB
---
5)扩容
bash
[root@HeHe ~]# vgdisplay /dev/vg1 |grep -i size
VG Size <8.99 GiB
PE Size 4.00 MiB
Alloc PE / Size 1792 / 7.00 GiB
Free PE / Size 509 / <1.99 GiB
[root@HeHe ~]# lvdisplay /dev/vg1/lv1 | grep -i size
LV Size 7.00 GiB
#可以看出,要想把逻辑卷的内存添加到10G显然是不可行的(卷组最大是8.99G)所以我们要给卷组扩容------------再重复分区和创建逻辑卷步骤
[root@HeHe ~]# lsblk | grep nvme0n2
nvme0n2 259:4 0 20G 0 disk
├─nvme0n2p1 259:5 0 3G 0 part
├─nvme0n2p2 259:6 0 3G 0 part
└─nvme0n2p3 259:7 0 3G 0 part
#当我们分区完成后却没有更新分区完整信息,我们可以使用partprobe命令更新一下
[root@HeHe ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. "系统默认挂载只读模式"
[root@HeHe ~]# lsblk | grep nvme0n2
nvme0n2 259:4 0 20G 0 disk
├─nvme0n2p1 259:5 0 3G 0 part
├─nvme0n2p2 259:6 0 3G 0 part
├─nvme0n2p3 259:7 0 3G 0 part
└─nvme0n2p4 259:10 0 3G 0 part
#给卷组扩容
[root@HeHe ~]# vgextend --h
vgextend - Add physical volumes to a volume group
[root@HeHe ~]# vgextend vg1 /dev/nvme0n2p4
Volume group "vg1" successfully extended
[root@HeHe ~]# vgdisplay /dev/vg1 |grep -i size
VG Size 11.98 GiB
PE Size 4.00 MiB
Alloc PE / Size 1792 / 7.00 GiB
Free PE / Size 1276 / 4.98 GiB
#逻辑卷扩容
再给逻辑卷增加到10G
[root@HeHe ~]# lvextend -L 10G /dev/vg1/lv1
Size of logical volume vg1/lv1 changed from 7.00 GiB (1792 extents) to 10.00 GiB (2560 extents).
Logical volume vg1/lv1 successfully resized.
也可以用+3G表示
[root@HeHe ~]# lvextend -L +3G /dev/vg1/lv1
Size of logical volume vg1/lv1 changed from 7.00 GiB (1792 extents) to 10.00 GiB (2560 extents).
Logical volume vg1/lv1 successfully resized.
[root@HeHe ~]# lvdisplay /dev/vg1/lv1 |grep -i size
LV Size 10.00 GiB
6)格式化(添加文件系统)
bash
跟磁盘格式化一样
[root@HeHe ~]# mkfs.xfs /dev/vg1/lv1
meta-data=/dev/vg1/lv1 isize=512 agcount=4, agsize=655360 blks
---
7)挂载
bash
muont --临时挂载
vim /etc/fstab --可以实现开机自动挂载 "挂载的话可以编辑fstab、.bashrc、.bash_profile文件;Linux推荐编辑fstab文件,编辑好了重启一下就好了"
16 /dev/mapper/vg1-lv1 /mnt/nmve2_xfs_growfs_lv1 xfs defaults 0 0
8)检验
bash
[root@HeHe ~]# df -h |grep lv1
/dev/mapper/vg1-lv1 10G 104M 9.9G 2% /mnt/nmve2_xfs_growfs_lv1