LVM can "combine" the total space of two disks and mount them to the same directory
Demand scenario
"Merge" the two 18T data disk spaces of the MySQL host and mount them to / MySQL_ In the data directory, the file system is required to be formatted as xfs; The existing key information is summarized as follows:
- Data disk to be mounted
- /dev/sdb: 18T
- /dev/sdc: 18T
- File system: xfs
- Mount Directory: / mysql_data
Operating system environment
- OS version: CentOS 7.5
- LVM version: lvm2
Implementation method
To achieve this requirement, LVM logical volume management can be used.
Implementation steps
Disk partition -- this step is not required
Before using a disk or disk partition as a physical volume (PV), you need to initialize it, that is, partition the disk; Because the disk partition requirement is greater than 2T, fdisk cannot be managed. You need to use the parted command for disk partition management; For detailed usage of parted, please refer to previous blogs of bloggers: Use the parted command to partition the disk
- /dev/sdb
# The new disk label type of / dev/sdb is GPT [root@MYSQL-SERVER ~]# parted /dev/sdb mklabel gpt # Allocate the entire space of / dev/sdb to the same partition [root@MYSQL-SERVER ~]# parted /dev/sdb mkpart primary 0 100% Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? I Information: You may need to update /etc/fstab.
- /dev/sdc
# The new disk label type of / dev/sdc is GPT [root@MYSQL-SERVER ~]# parted /dev/sdc mklabel gpt # Allocate the entire space of / dev/sdc to the same partition [root@MYSQL-SERVER ~]# parted /dev/sdc mkpart primary 0 100% Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? I Information: You may need to update /etc/fstab.
Create physical volume
The command to create a physical volume is pvcreate; Use this command to create all partitions or disks that you want to add to the volume group as physical volumes;
Create partitions / dev/sdb1 and / dev/sdc1 as physical volumes:
[root@MYSQL-SERVER ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. [root@MYSQL-SERVER ~]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created.
Create volume group
The command to create a volume group is vgcreate; Use this command to create the physical volume created by pvcreate as a complete volume group;
Create the physical volume / dev/sdb1 as a volume group named vgmysql:
[root@MYSQL-SERVER ~]# vgcreate vgmysql /dev/sdb1 Volume group "vgmysql" successfully created
Add a new physical volume to the volume group
This step is the key step to combine the two disk spaces into one; When a new disk or a new physical volume is added to the system and you want to add it to an existing volume group, you can use the vgextend command;
Add the physical volume / dev/sdc1 to the vgmysql volume group:
[root@MYSQL-SERVER ~]# vgextend vgmysql /dev/sdc1 Volume group "vgmysql" successfully extended
Viewing volume groups
View vgs for volume groups:
[root@MYSQL-SERVER ~]# vgs VG #PV #LV #SN Attr VSize VFree vgmysql 2 0 0 wz--n- 32.74t 32.74t vgroot 1 4 0 wz--n- 264.00g 4.00m
From the echo result of the vgs command, the volume group vgmysql is successfully added, and its total space is the total size of the two physical disks (not the exact 38T due to different conversion units).
Create logical volume
The command to create a logical volume is lvcreate; Use this command to create a logical volume on the volume group established with vgcreate;
Create a logical volume named lvmysql on the volume group vgmysql, with a starting size of 32.7T;
- -n: Specifies the logical volume name
- -50: Specifies the logical volume size
[root@MYSQL-SERVER ~]# lvcreate -L 32.7T -n lvmysql vgmysql Rounding up size to full physical extent 32.70 TiB Logical volume "lvmysql" created.
Format logical volumes
Format the created lvmysql logical volume as xfs
[root@MYSQL-SERVER ~]# mkfs -t xfs /dev/vgmysql/lvmysql meta-data=/dev/vgmysql/lvmysql isize=512 agcount=33, agsize=268435328 blks = sectsz=4096 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=0, rmapbt=0, reflink=0 data = bsize=4096 blocks=8777839616, imaxpct=5 = sunit=64 swidth=64 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=521728, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
Create a mount directory and mount
- Create mount directory / mysql_data
[root@MYSQL-SERVER ~]# mkdir /mysql_data
- mount
[root@MYSQL-SERVER ~]# mount /dev/vgmysql/lvmysql /mysql_data/
- Do boot auto mount
echo ' /dev/mapper/vgmysql-lvmysql /mysql_data xfs defaults 0 0' >/etc/fstab
Check whether the mount is successful
[root@MYSQL-SERVER ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgroot-lv_root 40G 1.8G 36G 5% /
devtmpfs 126G 0 126G 0% /dev
tmpfs 126G 0 126G 0% /dev/shm
tmpfs 126G 1.1M 126G 1% /run
tmpfs 126G 0 126G 0% /sys/fs/cgroup
/dev/sda1 976M 197M 713M 22% /boot
/dev/mapper/vgroot-lv_var 59G 197M 56G 1% /var
/dev/mapper/vgroot-lv_home 99G 5.6G 88G 6% /home
tmpfs 26G 0 26G 0% /run/user/0
/dev/mapper/vgmysql-lvmysql 33T 34M 33T 1% /mysql_data
[root@MYSQL-SERVER ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 446.1G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 264G 0 part
│ ├─vgroot-lv_root 253:0 0 40G 0 lvm /
│ ├─vgroot-lv_swap 253:1 0 64G 0 lvm [SWAP]
│ ├─vgroot-lv_var 253:2 0 60G 0 lvm /var
│ └─vgroot-lv_home 253:3 0 100G 0 lvm /home
└─sda3 8:3 0 64M 0 part
sdb 8:16 0 16.4T 0 disk
└─sdb1 8:17 0 16.4T 0 part
└─vgmysql-lvmysql 253:4 0 32.7T 0 lvm /mysql_data
sdc 8:32 0 16.4T 0 disk
└─sdc1 8:33 0 16.4T 0 part
└─vgmysql-lvmysql 253:4 0 32.7T 0 lvm /mysql_data
nvme0n1 259:0 0 1.5T 0 disk
[root@MYSQL-SERVER ~]# blkid
/dev/sda1: UUID="5a350fc9-d3d2-44c7-9574-30bf9a9dd0d3" TYPE="ext4"
/dev/sda2: UUID="Sum0Mm-6ShR-6ajh-cYQO-091c-r7QI-zfbDpm" TYPE="LVM2_member"
/dev/sda3: UUID="2019-05-24-11-39-22-00" LABEL="config-2" TYPE="iso9660"
/dev/mapper/vgroot-lv_root: UUID="df07731a-5e56-4cc3-95ab-b723b5979332" TYPE="ext4"
/dev/mapper/vgroot-lv_swap: UUID="7b5cd64d-d316-430d-8a83-aca89c4708d2" TYPE="swap"
/dev/mapper/vgroot-lv_var: UUID="025cb128-de8f-4bca-8206-5c1601e79715" TYPE="ext4"
/dev/mapper/vgroot-lv_home: UUID="7bd155b6-9200-442a-a61a-32076c0e4b7e" TYPE="ext4"