LVM逻辑卷管理测试——创建逻辑卷

虚拟机里再添加两块硬盘,如下所示:

LVM逻辑卷管理测试——创建逻辑卷

启动系统后,我们可以看到新添加的两块硬盘为/dev/sdb和/dev/sdc.每个2GB。

[root@lxjtest ~]# fdisk -l

Disk /dev/sdb:  MB,  bytes,  sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/sdc: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/sda: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes
Disk label type: dos
Disk identifier: 0x0006ae1e Device Boot Start End Blocks Id System
/dev/sda1 * Linux
/dev/sda2 8e Linux LVM ----这个分区是安装系统过程中创建的逻辑卷 Disk /dev/mapper/rhel-root: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes Disk /dev/mapper/rhel-swap: MB, bytes, sectors
Units = sectors of * = bytes
Sector size (logical/physical): bytes / bytes
I/O size (minimum/optimal): bytes / bytes

下面我们将对这两块新的硬盘先进行创建物理卷操作,可以简单理解成让硬盘设备支持了LVM技术,然后对两块硬盘进行卷组合并,卷组的名称可以由您来自定义,接下来是把合并后的卷组根据需求再切割出一个约为200M的逻辑卷设备,最后把这个逻辑卷设备格式化成ext4文件系统后挂载使用。

第一步:让新添加的两块硬盘设备支持LVM逻辑卷管理器技术,并查看创建的物理卷信息

[root@lxjtest ~]# pvcreate /dev/sdb /dev/sdc
Physical volume "/dev/sdb" successfully created
Physical volume "/dev/sdc" successfully created
[root@lxjtest ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name rhel
PV Size 4.71 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE
Free PE
Allocated PE
PV UUID V3kA1X-l7dr-03p4-HZcu-Ebj3-FRvb-r5vGMd --- Physical volume --- 以下两个是刚创建的物理卷设备
PV Name /dev/sdb
VG Name testVG
PV Size 2.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB --默认情况下,PE大小都为4MB。
Total PE 511 ---PE基本单元的个数
Free PE
Allocated PE
PV UUID InfACr-fq1t-yi95-K1K3-dOHU-uezl-gfiPVa --- Physical volume ---
PV Name /dev/sdc
VG Name testVG
PV Size 2.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE
Free PE
Allocated PE
PV UUID aOtJga-uWop-ldnv-xIcj-TcLE-aq18-SrJO3p

第二步:把两块硬盘加入到testVG卷组中,然后查看卷组信息

[root@lxjtest ~]# vgcreate testVG /dev/sdb /dev/sdc
Volume group "testVG" successfully created
[root@lxjtest ~]# vgdisplay
--- Volume group --- 这个rhel的卷组是在安装系统的过程中自动创建的
VG Name rhel
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 4.70 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size / 4.70 GiB
Free PE / Size /
VG UUID LrU5p2-fp7C-B7cZ-LFxL-g35x-uxrY-W8w93C --- Volume group --- 刚创建的卷组testVG
VG Name testVG
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 3.99 GiB
PE Size 4.00 MiB
Total PE 1022 --总的PE等于上一步中的物理卷/dev/sdb 和/dev/sdc的Total PE之和
Alloc PE / Size /
Free PE / Size / 3.99 GiB
VG UUID b3mykq-kcsp-Hdh4-rAos-vutt-ontI-6AWJ5K

第三步:从卷组testVG中分出一个200MB的逻辑卷设备

在LVM逻辑卷管理器对LV逻辑卷的切割上面有两种计量单位,第一种是常见以-L参数来以容量单位为对象,例如使用-L 200M来生成一个大小为200M的逻辑卷,还可以使用-l参数来指定要使用PE基本单元的个数,默认每个PE的大小为4M,因此允许使用-l 50来生成一个大小为50*4M=200M的逻辑卷:

[root@lxjtest ~]# lvcreate -n fuck_lv1 -L 200M testVG
Logical volume "fuck_lv1" created.
[root@lxjtest ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- .70g
swap rhel -wi-ao---- .00g
fuck_lv1 testVG -wi-a----- 200.00m
[root@lxjtest ~]# lvs testVG
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
fuck_lv1 testVG -wi-a----- 200.00m
[root@lxjtest ~]# lvdisplay testVG
--- Logical volume --- 从下面的信息可以看出,卷组testVG目前只分了一个逻辑卷fuck_lv1
LV Path /dev/testVG/fuck_lv1 --系统会把逻辑卷设备放到/dev/目录下
LV Name fuck_lv1
VG Name testVG
LV UUID RKzHdO-NX2i-Za40-kWNg-RIox-yi9j-z9251R
LV Write Access read/write
LV Creation host, time lxjtest.rusky.com, -- :: -
LV Status available
# open
LV Size 200.00 MiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device :

第四步:把创建好的逻辑卷fuck_lv1格式化后挂载使用:

Linux系统会把LVM逻辑卷管理器中的逻辑卷设备存放在/dev设备目录中(实际上是做了一个符号链接,但读者们无需关心),同时会以卷组的名称来建立一个目录,其中保存有逻辑卷的设备映射文件(即/dev/卷组名称/逻辑卷名称)。

[root@lxjtest ~]# mkfs.ext4 /dev/testVG/fuck_lv1
mke2fs 1.42. (-Dec-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , Allocating group tables: done
Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done [root@lxjtest ~]#
[root@lxjtest ~]# mkdir /testLVM
[root@lxjtest ~]# mount /dev/testVG/fuck_lv1 /testLVM/
[root@lxjtest ~]# df -h

第5步:查看挂载状态,并写入到配置文件永久生效:

[root@lxjtest ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root .7G 896M .9G % /
devtmpfs 910M 910M % /dev
tmpfs 920M 920M % /dev/shm
tmpfs 920M 8.4M 912M % /run
tmpfs 920M 920M % /sys/fs/cgroup
/dev/sda1 297M 114M 184M % /boot
tmpfs 184M 184M % /run/user/
/dev/mapper/testVG-fuck_lv1 190M 1.6M 175M % /testLVM

修改/etc/fstab文件,增加如下一行:

/dev/testVG/fuck_lv1    /testLVM                ext4    defaults               

这样,系统重启后,我们创建的逻辑卷/dev/testVG/fuck_lv1就会自动挂载到/testLVM目录下。

上一篇:Informatica_(4)工作流


下一篇:CentOS下LVM逻辑卷管理技术解释