#查看磁盘相关分区、所属关系以及lvm情况
[root@localhost data_bak]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sr0 11:0 1 6.4M 0 rom
vda 252:0 0 2T 0 disk
|-vda1 252:1 0 500M 0 part /boot
`-vda2 252:2 0 2T 0 part
|-centos-root 253:0 0 50G 0 lvm /
|-centos-swap 253:1 0 4G 0 lvm [SWAP]
`-centos-home 253:2 0 1.9T 0 lvm /home
vdb 252:16 0 500G 0 disk
#查看磁盘状态,有个vdb 500G硬盘未挂载使用
[root@localhost data_bak]# fdisk -l
Disk /dev/vda: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0x00071fa9
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1026047 512000 83 Linux
/dev/vda2 1026048 4194303999 2096638976 8e Linux LVM
Disk /dev/mapper/centos-root: 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/mapper/centos-swap: 4294 MB, 4294967296 bytes, 8388608 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/mapper/centos-home: 2088.9 GB, 2088910192640 bytes, 4079902720 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/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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
#使用fdisk命令创建分区
[root@localhost data_bak]# 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 0xf619a647.
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-1048575999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999):
Using default value 1048575999
Partition 1 of type Linux and of size 500 GiB is set
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): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#使用fdisk命令查看创建分区情况
[root@localhost data_bak]# fdisk -l
Disk /dev/vda: 2147.5 GB, 2147483648000 bytes, 4194304000 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: 0x00071fa9
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1026047 512000 83 Linux
/dev/vda2 1026048 4194303999 2096638976 8e Linux LVM
Disk /dev/mapper/centos-root: 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/mapper/centos-swap: 4294 MB, 4294967296 bytes, 8388608 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/mapper/centos-home: 2088.9 GB, 2088910192640 bytes, 4079902720 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/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0xf619a647
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1048575999 524286976 8e Linux LVM
#格式化新磁盘
[root@localhost data_bak]# mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1 isize=256 agcount=4, agsize=32767936 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=131071744, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=63999, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
#查看格式化结果
[root@localhost data_bak]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
fd0
sr0
vda
|-vda1 xfs f9bb6548-f289-4306-be2f-575acb4fb053 /boot
`-vda2 LVM2_member fmFQO2-O0Sg-Omjv-ea32-vexY-0Bd7-vFlPiB
|-centos-root xfs ea594948-655d-4e79-8a18-5ceb55f10930 /
|-centos-swap swap e8e03e42-be17-4a77-a2fd-1c6e47133466 [SWAP]
`-centos-home xfs 87dab031-22cc-4ac8-aeb5-edce91f563e7 /home
vdb
`-vdb1 xfs 9e7bd7b7-37ef-422a-b710-ba29c08d99aa
#将新磁盘转化为物理卷
[root@localhost data_bak]#pvcreate /dev/vdb1
#将新的物理卷扩展到卷组即VG纳入新PV
[root@localhost data_bak]# vgextend centos /dev/vdb1
#扩容LV
方法一:
#使用lvextend命令将/dev/vdb1全部扩展到/dev/mapper/centos-home中
[root@localhost data_bak]#lvextend /dev/mapper/centos-home /dev/sdb1
方法二:
#使用lvresize指定将/dev/vdb1指定容量扩容到/dev/mapper/centos-home中
[root@localhost data_bak]#lvresize -l +100%FREE /dev/mapper/centos-home
#将新的空间纳入到xfs中
[root@localhost data_bak]#xfs_growfs /dev/mapper/centos-home
#检查扩容结果
[root@localhost data_bak]#df -h