Centos7创建LVM磁盘管理
转载请注明出处,谢谢。
环境介绍
在centos7下需要挂载两个新的磁盘。为了方便后续的扩容方便,决定将这其设置为LVM管理的方式。
查看一下当前有哪些新增的数据盘,如下:
[root@runsdata-test-0004 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.4G 36G 4% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 328K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@runsdata-test-0004 ~]# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@runsdata-test-0004 ~]#
可以从上面看出,目前有三块硬盘。
系统盘:40G
另外还有两块50G的硬盘,需要挂载。我以其中一块硬盘作为示例。
LVM管理基本概念
LVM管理概念图- 1、 物理卷-----PV(Physical Volume)
物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个 物理硬盘。 - 2、 卷组--------VG(Volumne Group)
卷组建立在物理卷之上,一个卷组中至少要包括一个物理卷,在卷组建立之后可 动态添加物理卷到卷组中。一个逻辑卷管理系统工程中可以只有一个卷组,也可以 拥有多个卷组。 - 3、 逻辑卷-----LV(Logical Volume)
逻辑卷建立在卷组之上,卷组中的未分配空间可以用于建立新的逻辑卷,逻辑卷建立 后可以动态地扩展和缩小空间。系统中的多个逻辑卷要以属于同一个卷组,也可以 属于不同的多个卷组。 - 4、 物理区域--PE(Physical Extent)
物理区域是物理卷中可用于分配的最小存储单元,物理区域的大小可根据实际情况在 建立物理卷时指定。物理区域大小一旦确定将不能更改,同一卷组中的所有物理卷 的物理区域大小需要一致。 - 5、 逻辑区域—LE(Logical Extent)
逻辑区域是逻辑卷中可用于分配的最小存储单元,逻辑区域的大小取决于逻辑卷所在 卷组中的物理区域的大小。 - 6、 卷组描述区域-----(Volume Group Descriptor Area)
卷组描述区域存在于每个物理卷中,用于描述物理卷本身、物理卷所属卷组、卷组中的 逻辑卷及逻辑卷中物理区域的分配等所有信息,卷组描述区域是在使用pvcreate 建立物理卷时建立的。
目标 - LVM管理拓扑
本篇章以此拓扑进行逐步部署。
给硬盘分区
选择其中一块50G的数据盘进行分区,只要将50G都设置一个分区即可,无需考虑设置多个分区。
配置步骤如下:
使用命令:fdisk -l |grep dev,查看添加的硬盘是否存在。
[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
[root@runsdata-test-0004 ~]#
fdisk是分区工具:fdisk /dev/vdb,进入分区工具设置。
[root@runsdata-test-0004 ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x051e2cc7.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):
输入m命令,则是查看有哪些命令可以使用。其中可以先看看这个数据盘有什么分区了。
输入p
命令,查看该数据盘已经有哪些分区
Command (m for help): p
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x051e2cc7
Device Boot Start End Blocks Id System
Command (m for help):
可以看出这块数据盘暂时还没有任何分区,那么下面我先来进行分区。
下面进入分区,‘n’选一个分区类型,如没有其他设置可按默认下到返回m for help处。最后按'w'保存设置。
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
此时,再次查看一下数据盘,应该已经有一个50G的分区了。那么下一步,将其改为Linux LVM格式分区。
设置磁盘分区为Linux LVM格式分区
Command (m for help): p
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x051e2cc7
Device Boot Start End Blocks Id System
/dev/vdb1 2048 104857599 52427776 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x051e2cc7
Device Boot Start End Blocks Id System
/dev/vdb1 2048 104857599 52427776 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
根据上面的步骤,再对另一个数据盘进行分区,执行如下:
分区:
[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
/dev/vdb1 2048 104857599 52427776 8e Linux LVM
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# fdisk /dev/vdc
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x420d8007.
Command (m for help): p
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x420d8007
Device Boot Start End Blocks Id System
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
设置为LVM
[root@runsdata-test-0004 ~]# fdisk /dev/vdc
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x420d8007
Device Boot Start End Blocks Id System
/dev/vdc1 2048 104857599 52427776 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x420d8007
Device Boot Start End Blocks Id System
/dev/vdc1 2048 104857599 52427776 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
创建物理卷 PV
安装pv系列命令, yum install lvm2 -y
阿里云的服务器默认没有安装pv的相关命令的。
[root@runsdata-test-0004 ~]# pvcreate
-bash: pvcreate: command not found
[root@runsdata-test-0004 ~]#
需要安装一下lvm2的工具如下:
[root@server81 ~]# rpm -qa | grep lvm
lvm2-2.02.171-8.el7.x86_64
lvm2-libs-2.02.171-8.el7.x86_64
[root@server81 ~]#
安装如下:
[root@runsdata-test-0004 ~]# yum install lvm2 -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package lvm2.x86_64 7:2.02.180-10.el7_6.2 will be installed
.... 省略 ....
Installed:
lvm2.x86_64 7:2.02.180-10.el7_6.2
Dependency Installed:
device-mapper-event.x86_64 7:1.02.149-10.el7_6.2
device-mapper-event-libs.x86_64 7:1.02.149-10.el7_6.2
device-mapper-persistent-data.x86_64 0:0.7.3-3.el7
libaio.x86_64 0:0.3.109-13.el7
lvm2-libs.x86_64 7:2.02.180-10.el7_6.2
Dependency Updated:
device-mapper.x86_64 7:1.02.149-10.el7_6.2 device-mapper-libs.x86_64 7:1.02.149-10.el7_6.2
Complete!
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# rpm -qa | grep lvm
lvm2-libs-2.02.180-10.el7_6.2.x86_64
lvm2-2.02.180-10.el7_6.2.x86_64
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pv
pv pvck pvdisplay pvremove pvs
pvchange pvcreate pvmove pvresize pvscan
[root@runsdata-test-0004 ~]# pv
从上面可以看出已经安装好了lvm所需要的工具了。那么下面来继续配置。
创建物理卷:选择自己要创建的分区
[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
/dev/vdb1 2048 104857599 52427776 8e Linux LVM
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvcreate /dev/vdb
vdb vdb1
[root@runsdata-test-0004 ~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]#
查看创建好的物理卷
[root@runsdata-test-0004 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 lvm2 --- <50.00g <50.00g
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvdisplay
"/dev/vdb1" is a new physical volume of "<50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size <50.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID oMzorH-1mfB-0VEy-eZDB-HHU3-UM9C-0EoPTU
[root@runsdata-test-0004 ~]#
-
PE(physical extent)
:物理区域是物理卷中可用于分配的最小存储单元,物理区域大小在建立卷组时指定,一旦确定不能更改,同一卷组所有物理卷的物理区域大小需一致,新的pv加入到vg后,pe的大小自动更改为vg中定义的pe大小。 -
LE(logical extent)
:逻辑区域是逻辑卷中可用于分配的最小存储单元,逻辑区域的大小取决于逻辑卷所在卷组中的物理区域的大小。 -
卷组描述区域:卷组描述区域存在于每个物理卷中,用于描述物理卷本身、物理卷所属卷组、卷组中逻辑卷、逻辑卷中物理区域的分配等所有信息,它是在使用pvcreate建立物理卷时建立的。
根据上面的步骤,再给另一个数据盘创建PV
[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
/dev/vdb1 2048 104857599 52427776 8e Linux LVM
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
/dev/vdc1 2048 104857599 52427776 8e Linux LVM
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvcreate /dev/vdc1
Physical volume "/dev/vdc1" successfully created.
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 vgdocker lvm2 a-- <50.00g <50.00g
/dev/vdc1 lvm2 --- <50.00g <50.00g
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vdb1
VG Name vgdocker
PV Size <50.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12799
Free PE 12799
Allocated PE 0
PV UUID oMzorH-1mfB-0VEy-eZDB-HHU3-UM9C-0EoPTU
"/dev/vdc1" is a new physical volume of "<50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdc1
VG Name
PV Size <50.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID nzkwWq-h4KK-2g64-aAqT-3Ugz-qvrj-bq4GR3
[root@runsdata-test-0004 ~]#
创建卷组,用于管理PV以及LV
vg系列命令
[root@runsdata-test-0004 ~]# vg
vgcfgbackup vgconvert vgextend vgmknodes vgs
vgcfgrestore vgcreate vgimport vgreduce vgscan
vgchange vgdisplay vgimportclone vgremove vgsplit
vgck vgexport vgmerge vgrename
[root@runsdata-test-0004 ~]# vg
创建卷组VG
,名字可以随意起
这个卷组我是专门给docker以及data存储数据使用的,那么就命名为vgdata
。
下面就创建一个vgdata
的卷组,然后使用vgs
以及vgdisplay
查看一下创建后的信息。
[root@runsdata-test-0004 ~]# vgcreate vgdocker /dev/vdb1 ## 测试创建一下
Volume group "vgdocker" successfully created
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# vgremove vgdocker ## 删除之前创建的
Volume group "vgdocker" successfully removed
## 将前面的两个PV创建到vgdata的逻辑组中。
[root@runsdata-test-0004 ~]# vgcreate vgdata /dev/vdc1 /dev/vdb1
Volume group "vgdata" successfully created
[root@runsdata-test-0004 ~]#
## 查看vg的信息
[root@runsdata-test-0004 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vgdata 2 0 0 wz--n- 99.99g 99.99g
[root@runsdata-test-0004 ~]#
## 查看vg的详细信息
[root@runsdata-test-0004 ~]# vgdisplay
--- Volume group ---
VG Name vgdata
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 99.99 GiB
PE Size 4.00 MiB
Total PE 25598
Alloc PE / Size 0 / 0
Free PE / Size 25598 / 99.99 GiB
VG UUID 52PHwY-0a16-1yPo-EYNE-YUv0-4LJx-CWZsZS
[root@runsdata-test-0004 ~]#
创建好了卷组之后,下面就要创建逻辑卷了。
创建逻辑卷LV
首先查看一下lvcreate的相关命令参数
[root@runsdata-test-0004 ~]# lvcreate --help
lvcreate - Create a logical volume
现在我打算给docker使用的逻辑卷使用50G左右,data目录使用逻辑卷50G左右。那么就需要创建两个50G大小的逻辑卷。
## 创建大小50G名称docker的lv ,-L 指定大小,-n指定名称
[root@runsdata-test-0004 ~]# lvcreate -L 50G -n docker vgdata
Logical volume "docker" created.
[root@runsdata-test-0004 ~]#
## 再创建一个50G的data逻辑卷报错,提示空间不足了,因为逻辑组只有 < 99G 的大小
[root@runsdata-test-0004 ~]# lvcreate -L 50G -n data vgdata
Volume group "vgdata" has insufficient free space (12798 extents): 12800 required.
[root@runsdata-test-0004 ~]#
## 那么就创建一个49G的data逻辑卷LV
[root@runsdata-test-0004 ~]# lvcreate -L 49G -n data vgdata
Logical volume "data" created.
[root@runsdata-test-0004 ~]#
查看逻辑卷LV的信息
[root@runsdata-test-0004 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vgdata/docker
LV Name docker
VG Name vgdata
LV UUID XWcgud-iAYP-j2Mo-x8kq-SjQ2-edP2-Usa4RZ
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:57:01 +0800
LV Status available
# open 0
LV Size 50.00 GiB
Current LE 12800
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
--- Logical volume ---
LV Path /dev/vgdata/data
LV Name data
VG Name vgdata
LV UUID HVfQpR-Zs81-RFiZ-rAFC-lBMk-bMhe-MTB1zl
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:58:36 +0800
LV Status available
# open 0
LV Size 49.00 GiB
Current LE 12544
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:1
[root@runsdata-test-0004 ~]#
那么这时候已经有docker、data两个逻辑卷了,下面就是进行格式化,目录的挂载了。
逻辑卷格式化
- 执行
lvdisplay
查看逻辑卷信息,获取逻辑卷LV的Path - 对逻辑卷进行格式化
mkfs.ext4 /dev/vgdata/docker
## 查看lv的详细信息
[root@runsdata-test-0004 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vgdata/docker
LV Name docker
VG Name vgdata
LV UUID XWcgud-iAYP-j2Mo-x8kq-SjQ2-edP2-Usa4RZ
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:57:01 +0800
LV Status available
# open 0
LV Size 50.00 GiB
Current LE 12800
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
--- Logical volume ---
LV Path /dev/vgdata/data
LV Name data
VG Name vgdata
LV UUID HVfQpR-Zs81-RFiZ-rAFC-lBMk-bMhe-MTB1zl
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:58:36 +0800
LV Status available
# open 0
LV Size 49.00 GiB
Current LE 12544
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:1
## 对逻辑卷进行ext4格式化
[root@runsdata-test-0004 ~]# mkfs.ext4 /dev/vgdata/docker
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
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
400 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, 1605632, 2654208,
4096000, 7962624, 11239424
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
## 对逻辑卷进行ext4格式化
[root@runsdata-test-0004 ~]# mkfs.ext4 /dev/vgdata/data
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
3211264 inodes, 12845056 blocks
642252 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
392 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, 1605632, 2654208,
4096000, 7962624, 11239424
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@runsdata-test-0004 ~]#
挂载文件目录
[root@runsdata-test-0004 ~]# cd /
[root@runsdata-test-0004 /]# ls
bin dev home lib64 media opt root sbin sys usr
boot etc lib lost+found mnt proc run srv tmp var
[root@runsdata-test-0004 /]# mkdir docker
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# mount /dev/vgdata/docker docker
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# mkdir data
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# mount /dev/vgdata/data data
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.5G 36G 4% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 352K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/vgdata-docker 50G 53M 47G 1% /docker
/dev/mapper/vgdata-data 49G 53M 46G 1% /data
[root@runsdata-test-0004 /]#
可以看到 /docker 和 /data 目录已经使用上了。
测试写入文件看看。
[root@runsdata-test-0004 /]# cd /docker/
[root@runsdata-test-0004 docker]# pwd
/docker
[root@runsdata-test-0004 docker]# ls
lost+found
[root@runsdata-test-0004 docker]#
[root@runsdata-test-0004 docker]# echo 123 > 1.txt
[root@runsdata-test-0004 docker]# ls
1.txt lost+found
[root@runsdata-test-0004 docker]# cat 1.txt
123
[root@runsdata-test-0004 docker]#
好了,写到这里基本上已经可以了,但是如果服务器重启的话,是无法自动挂载上/docker和/data目录的。
下面来设置一下磁盘开机的自动挂载。
设置磁盘开机自动挂载,配置/etc/fstab文件
需要让系统开机自动挂载,需要将挂载信息写入到/etc/fstab
文件中。
[root@runsdata-test-0004 docker]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Oct 15 15:19:00 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=eb448ab..省略...6a31 / ext4 defaults 1 1
/dev/mapper/vgdata-docker /docker ext4 defaults 1 1
/dev/mapper/vgdata-data /data ext4 defaults 1 1
然后进行重启reboot
测试一下。
LVM管理的好处就是灵活得扩容、管理磁盘,后续可以再写一个扩容磁盘的篇章。
参考文献
CentOS 7.2 添加磁盘并创建新区
CentOS7下LVM的简单创建
LVM基础详细说明及动态扩容lvm逻辑卷的操作记录
关注微信公众号,回复【资料】、Python、PHP、JAVA、web,则可获得Python、PHP、JAVA、前端等视频资料。