# 名词解释
# LVM : logical volume manager LVM,基于传统的GPT MBR磁盘分区格式。在传统的GPT MBR分区中,
# 如果分区类型为LVM,即可以被VG使用,LVM分区类型,是专用于VG的一种特殊分区类型
# VG : volume Group 卷组
# PV : Physical volume 物理卷,基于LVM分区类型的一种“虚拟物理卷”
# PE : Physical extent size 物理卷的最小存储单元
# LV : Logical volume 逻辑卷,可以想使用gpt分区一样使用它
# LE : Logical extent size 逻辑卷最小存储单元。类似于linux的block。
######################################
# linux vg 磁盘扩展
######################################
#
#1、先将磁盘创建为LVM分区格式的磁盘
#
sudo fdisk /dev/sdb
# Welcome to fdisk (util-linux 2.34).
# Changes will remain in memory only, until you decide to write them.
# Be careful before using the write command.
#
#
# Command (m for help): d
# Selected partition 1
# Partition 1 has been deleted.
#
# Command (m for help): n
# Partition number (1-128, default 1):
# First sector (2048-7814037134, default 2048):
# Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-7814037134, default 7814037134):
#
# Created a new partition 1 of type 'Linux filesystem' and of size 3.7 TiB.
# Partition #1 contains a ext4 signature.
#
# Do you want to remove the signature? [Y]es/[N]o: y
#
# The signature will be removed by a write command.
#
# Command (m for help): t
# Selected partition 1
# Partition type (type L to list all types): L
# ...
# 31 Linux LVM E6D6D379-F507-44C2-A23C-238F2A3DF928
# ...
# Partition type (type L to list all types): 31
# Changed type of partition 'Linux filesystem' to 'Linux LVM'.
#
# Command (m for help): w
# The partition table has been altered.
# Calling ioctl() to re-read partition table.
# Syncing disks.
sudo fdisk -l
#创建完成后log如下
#
# Disk /dev/sdb: 3.65 TiB, 4000787030016 bytes, 7814037168 sectors
# Disk model: ST4000NM024B-2TF
# Units: sectors of 1 * 512 = 512 bytes
# Sector size (logical/physical): 512 bytes / 4096 bytes
# I/O size (minimum/optimal): 4096 bytes / 4096 bytes
# Disklabel type: gpt
# Disk identifier: 08805955-8CD8-E842-AFF7-FA123FB19DCB
#
# Device Start End Sectors Size Type
# /dev/sdb1 2048 7814037134 7814035087 3.7T Linux LVM
#
# 把分区格式为LVM的/dev/sdb1磁盘,创建为PV并确认
sudo pvcreate /dev/dev/sdb1
sudo pvdisplay
# "/dev/sdb1" is a new physical volume of "<3.64 TiB"
# --- NEW Physical volume ---
# PV Name /dev/sdb1
# VG Name
# PV Size <3.64 TiB
# Allocatable NO
# PE Size 0
# Total PE 0
# Free PE 0
# Allocated PE 0
# PV UUID We0xef-8Fvg-9rDN-x1lm-3Htx-xnfT-hCWQA6
#2、将LVM格式的磁盘追加到VG 中 可以追加到现有VG或者重新创建VG
#2.1 显示当前VG 情况
sudo vgdisplay -v #显示追加前状况
sudo vgextend vgroot /dev/sdb1
sudo vgdisplay -v #显示追加后
#3、为现有的LV 重新定义大小
#3.1 扩展LV磁盘
sudo lvextend -L +4T /dev/vgroot/home
sudo resize2fs -p /dev/vgroot/home
sudo lvextend -L +10G /dev/mapper/vgroot-opt
sudo resize2fs -p /dev/mapper/vgroot-opt