Please indicate the source of reprint, thank you.

Environment introduction

Two new disks need to be mounted under centos7. In order to facilitate the subsequent expansion, it is decided to set the LVM management mode.

View the newly added data disks as follows:

[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 -lDisk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors Units = sectors of 1 * 512 = 512 Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk labeltype: 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 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 Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes [root@runsdata-test-0004 ~]#
Copy the code

As you can see from above, there are currently three hard drives. System disk: 40 GB Two other 50 GB hard disks need to be mounted. I’ll use one of the hard drives as an example.

Basic concepts of LVM management

  • 1. Physical Volume —– Physical Volume (PV) A Physical Volume is the lowest level of logical Volume management. It can be a partition on a Physical disk or the entire Physical disk.
  • 2. Volume Group ——–VG (Volumne Group) A volume Group is built on top of physical volumes. A volume Group must contain at least one physical volume. A logical volume management system project can have only one volume group or multiple volume groups.
  • —– Logical Volume (LV) Logical volumes are created on top of Volume groups. Unallocated space in a Volume group can be used to create new Logical volumes. After a Logical Volume is created, the space can be dynamically expanded or reduced. Multiple logical volumes in the system must belong to the same volume group or to different volume groups.
  • 4. Physical area – Physical Extent (PE) A Physical area is the smallest storage unit that can be allocated to a Physical volume. The size of a Physical area can be specified when creating a Physical volume. The physical area size cannot be changed once it is determined. All physical volumes in a volume group must have the same physical area size.
  • 5. Logical area – A Logical Extent (LE) Logical area is the smallest storage unit that can be allocated to a Logical volume. The size of a Logical area depends on the size of the physical area in the volume group to which the Logical volume belongs.
  • 6. Volume Group Description Area —– (Volume Group Descriptor Area) Volume Group description Area exists in each physical Volume. It describes all information about the physical Volume itself, the Volume Group to which the physical Volume belongs, the logical volumes in the Volume Group, and the allocation of physical areas in the logical Volume. The volume group description area is created when a physical volume is created using PVCreate.

Target-lvm management topology

This chapter deploys the topology step by step.

Partition the hard drive

Select one 50GB data disk for partition, as long as 50GB is set to a partition, do not need to consider setting multiple partitions. The configuration procedure is as follows:

Using the command: fdisk -l | grep dev, see if add hard disk.

[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 ~]# 
Copy the code

If fdisk is a partition tool, run the fdisk /dev/vdb command to go to the partition tool Settings.

[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 mprint 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):Copy the code

Enter the m command to view the available commands. Which can take a look at the data disk has what partition.

The inputpCommand to view partitions on the data disk

Command (m for help): p Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk labeltype: dos
Disk identifier: 0x051e2cc7

   Device Boot      Start         End      Blocks   Id  System

Command (m for help) :Copy the code

It can be seen that this data disk does not have any partitions for the time being, so I will partition it first.

Enter the partition, ‘n’ select a partition type, if no other Settings can be returned to m for help by default. Finally, press ‘w’ to save the Settings.

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 ~]# 
Copy the code

At this point, if you look at the data disk again, you should already have a 50GB partition. Next, change it to a Linux LVM format partition.

Set the disk partition to Linux LVM format

Command (m for help): p Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk labeltype: 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 Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk labeltype: 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 ~]# 
Copy the code

Perform the following steps to partition another data disk:

Partitions:

[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 Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk labeltype: 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 ~]# 
Copy the code

Set to 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 Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk labeltype: 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 Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk labeltype: 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 ~]# 
Copy the code

Create a physical volume PV

Install pv series commands,yum install lvm2 -y

Ali cloud server does not install pv related commands by default.

[root@runsdata-test-0004 ~]# pvcreate
-bash: pvcreate: command not found
[root@runsdata-test-0004 ~]# 
Copy the code

To install LVM2, you need the following tools:

[root@server81 ~]# rpm -qa | grep lvmLvm2 2.02.171-8. El7. X86_64 lvm2 - libs - 2.02.171-8 el7. X86_64 / root @ server81 ~# 
Copy the code

The installation is as follows:

[root@runsdata-test-0004 ~]# yum install lvm2 -yLoaded 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.... Omit... Lvm2.x86_64 7:2.02.180-10.EL7_6.2 Dependency Installed: LVM2.x86_64 7:2.02.180-10.el7_6. 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 LVM2-libs.x86_64 7:2.02.180-10.el7_6  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 lvmLvm2 - 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
Copy the code

You can see from the above that you have installed the tools required for LVM. So let’s continue with the configuration.

Create a physical volume: Select a partition to be created

[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 ~]# 
Copy the code

View the created physical volume

[root@runsdata-test-0004 ~]# pvsVG Fmt Attr PSize PFree /dev/vdb1 LVM2 -- < lvm2 -- [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 -- 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 ~]# 
Copy the code
  • Physical extent (PE) : A physical area is the smallest storage unit that can be allocated to a physical volume. The size of a physical area is specified when creating a volume group. If the size cannot be changed, all physical volumes in a volume group must have the same physical area size.

  • Logical extent (LE) : A logical area is the smallest storage unit that can be allocated to a logical volume. The size of a logical area depends on the size of the physical area in the volume group to which the logical volume belongs.

  • Volume group description area: A volume group description area exists in each physical volume and describes all information about the physical volume, the volume group to which the physical volume belongs, the logical volumes in the volume group, and the allocation of physical areas in the logical volume. It is created when a physical volume is created using PVCreate.

Repeat the preceding steps to create a PV for another data disk

[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 ~]# pvsPV VG Fmt Attr PSize PFree /dev/vdb1 vgdocker LVM2A -- < lvm2G -- < LVM2g /dev/vdc1 LVM2 -- < LVM2g [root@runsdata-test-0004 ~]# 
[root@runsdata-test-0004 ~]# pvdisplay -- 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 -- NEW Physical volume -- PV Name /dev/vdC1 VG Name PV Size <50.00 GiB Allocatable NO PE Size 0 Allocated PE 0 PV UUID nzkwWq-h4KK-2g64-aAqT-3Ugz-qvrj-bq4GR3
   
[root@runsdata-test-0004 ~]# 
Copy the code

Create a volume group to manage PVVS and LVS

Vg series commands

[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
Copy the code

Create a volume groupVGYou can choose any name you like

This volume group is specifically used by Docker and data storage data, so it will be named vgData. Let’s create a vgData volume group and use VGS and vgdisplay to see what we have created.

[root@runsdata-test-0004 ~]# vgcreate vgdocker /dev/vdb1 #
  Volume group "vgdocker" successfully created
[root@runsdata-test-0004 ~]# 
[root@runsdata-test-0004 ~]# vgremove vgDocker ## Delete previously created
  Volume group "vgdocker" successfully removed

Create the first two PVS into the logical group of vgData.
[root@runsdata-test-0004 ~]# vgcreate vgdata /dev/vdc1 /dev/vdb1  
  Volume group "vgdata" successfully created
[root@runsdata-test-0004 ~]# 

## Check vg information
[root@runsdata-test-0004 ~]# vgs
  VG     #PV #LV #SN Attr VSize VFreeVgdata 2 00 wz-- n-99.99g 99.99g [root@runsdata-test-0004 ~]# 

## Check vg details
[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 ~]# 
Copy the code

With the volume group created, it’s time to create the logical volume.

Creating a Logical VolumeLV

First take a look at the command parameters for lvcreate

[root@runsdata-test-0004 ~]# lvcreate --help
  lvcreate - Create a logical volume
Copy the code

Now I plan to use about 50GB of logical volume for docker and 50GB of logical volume for data directory. Then you need to create two 50GB logical volumes.

-l specifies the size and -n specifies the name of the docker lv
[root@runsdata-test-0004 ~]# lvcreate -L 50G -n docker vgdata
  Logical volume "docker" created.
[root@runsdata-test-0004 ~]# 
## Create volume (50 GB) from data logical volume (size < 99 GB
[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 ~]# 
Create a 49GB data logical volume LV
[root@runsdata-test-0004 ~]# lvcreate -L 49G -n data vgdata
  Logical volume "data" created.
[root@runsdata-test-0004 ~]# 
Copy the code

View information about the LOGICAL volume 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 0LV Size 50.00 GiB Current LE 12800 Segments 2 Allocation Inherit Read ahead sectors auto-currentlyset 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 0LV Size 49.00 GiB Current LE 12544 Segments 1 Allocation inherit Read ahead sectors auto-currentlyset to     8192
  Block device           252:1
   
[root@runsdata-test-0004 ~]# 
Copy the code

So this time has docker, data two logical volumes, the following is to format, directory mount.

Logical volume formatting

  • performlvdisplayView the logical volume information and obtain the Path of the logical volume
  • Format the logical volumemkfs.ext4 /dev/vgdata/docker

## Check lv details
[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 0LV Size 50.00 GiB Current LE 12800 Segments 2 Allocation Inherit Read ahead sectors auto-currentlyset 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 0LV Size 49.00 GiB Current LE 12544 Segments 1 Allocation inherit Read ahead sectors auto-currentlyset to     8192
  Block device           252:1
   
Ext4 format the logical volume
[root@runsdata-test-0004 ~]# mkfs.ext4 /dev/vgdata/docker Mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OStype: Linux
Block size=4096 (log=2)
Fragment size=4096 (logStride=0 blocks, width=0 blocks 3276800 inodes, 13107200 blocks 655360 blocks (5.00%) Reservedfor 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 format the logical volume
[root@runsdata-test-0004 ~]# mkfs.ext4 /dev/vgdata/data Mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OStype: Linux
Block size=4096 (log=2)
Fragment size=4096 (logStride=0 blocks, width=0 blocks 3211264 inodes, 12845056 blocks 642252 blocks (5.00%) Reservedfor 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 ~]# 
Copy the code

Mount file directories

[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 /]# 
Copy the code

You can see that the /docker and /data directories are already in use.

Test write file to see.

[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]# 
Copy the code

Ok, this is basically enough, but if the server restarts, the /docker and /data directories will not be automatically mounted.

Let’s set up automatic mount for disk boot.

Configure automatic disk mounting upon startup and configure the /etc/fstab file

You need to enable the system to mount automatically upon startup. You need to write the mounting information to the /etc/fstab file.

[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.. Omit... 6a31 / ext4 defaults 1 1 /dev/mapper/vgdata-docker /docker ext4 defaults 1 1 /dev/mapper/vgdata-data /data ext4 defaults 1 1Copy the code

Then test the reboot.

The advantage of LVM management is that you can flexibly expand and manage disks. You can write another chapter about expanding disks later.

reference

CentOS 7.2 Adding a Disk and Creating a New Zone

Simple creation of LVM in CentOS7

LVM basic description and records of dynamically expanding LVM logical volumes