1.公共步骤
增加分区,需要设置类型为linux lvm
[root@131-mysql-slave ~]# fdisk /dev/sda 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): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (104857600-1048575999, default 104857600):
Using default value 104857600
Last sector, +sectors or +size{K,M,G} (104857600-1048575999, default 1048575999):
Using default value 1048575999
Partition 3 of type Linux and of size 450 GiB is set
Command (m for help): t
Partition number (1-3, default 3): Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@131-mysql-slave ~]# partprobe
增加pv
pvcreate /dev/sda3 # 选择之前创建的新分区
2.1扩展逻辑卷
以下步骤是扩展
扩展vg
vgdisplay # 查看vg获得VG NAME
vgextend centos /dev/sda3 # 增加VG容量,第1个参数是想要扩展的vg名
vgdisplay # 查看vg,发现 Free PE / Size 字段会出现或增加
扩展lv
lvdisplay # 查看lv获得LV NAME
lvextend -L +450G -n /dev/centos/root # -n不需要检查文件系统,跟上需要扩的lv,指定扩展的大小
lvextend -l +100%FREE -n /dev/vg-a1/lv1 # 将剩余的卷组所有大小都给目录
根据原来的分区文件系统进行扩展文件系统
lsblk -f # 查看分区文件系统
xfs_growfs /dev/centos/root
# ext用这个命令
resize2fs /dev/centos/root
2.2新建逻辑卷
以下步骤是新建
新建vg
vgcreate data /dev/sdb1 # 第一个参数是设置的vg名
vgdisplay # 查看是否成功创建vg
vgchange -a y data # 激活vg
新建lv
# 将新建的vg全部给到lv,-n后面接新建的lv名,最后接vg名
lvcreate -l +100%FREE -n mysql data
新建文件系统
mkfs.xfs /dev/data/mysql # 确定文件系统,并新建 lsblk -f # 查看新分区
挂载分区至目录
mount /dev/data/mysql /mnt # 挂载新lv分区至/mnt目录
df -h # 查看挂载是否成功
lsblk -f # 查看挂载是否成功且为对应的文件系统
修改fstab文件,开机挂载