查看扩容前的磁盘信息
目的是把vdb的容量加入到逻辑卷centos-root中
[root@szrx-sjk01 /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 392M 0 rom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 99G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
└─centos-home 253:2 0 45.1G 0 lvm /home
vdb 252:16 0 3T 0 disk
└─vdb1 252:17 0 3T 0 part
对新盘进行分区
小于2T的盘
fdisk /dev/sdb
输入p 查看分区;(新加的硬盘是没有分区的,如果有数据的情况,输入d删除)
输入n 创建新分区;
输入p 创建主分区
输入1 新建xvdc的第一个主分区,(或者回车即可)
回车(默认从开始分)
输入最大的柱面数,也就是磁盘的最大数;或者回车(默认最大的)
选择格式 t
列出格式 l
输入格式 8e
查看 p
输入w 保存退出
大于2T的盘
大于2T的盘也可以用上面的方法进行小于2T的多次分区,然后加入创建多个物理卷,然后分别加入卷组,有逻辑卷来管理容量;过去没有大磁盘时候就是这样搞的,麻烦些。parted命令可以一次把分区建成。
parted命令
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or
a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
分区
[root@szrx-sjk02 ~]# parted /dev/vdb
GNU Parted 3.1
使用 /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
警告: The existing disk label on /dev/vdb will be destroyed and all data on this disk will be lost. Do you want to continue?
是/Yes/否/No? yes
(parted) mkpart part1
文件系统类型? [ext2]? xfs
起始点? 1
结束点? 3T
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 3221GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 1049kB 3221GB 3221GB part1
格式化
[root@szrx-sjk02 ~]# mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1 isize=512 agcount=4, agsize=196607872 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=786431488, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=383999, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
查看扩容前的卷组
有一个卷组centos
[root@szrx-sjk01 /]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size <99.00 GiB
PE Size 4.00 MiB
Total PE 25343
Alloc PE / Size 25342 / 98.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID DnNF3d-mMCq-j6Yo-HLc6-sdlg-fz61-Gdsnrc
查看扩容前的物理卷
有一个物理卷/dev/vda2
[root@szrx-sjk01 /]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size <99.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25343
Free PE 1
Allocated PE 25342
PV UUID bs9tE7-8HSk-iUFI-BQww-fp3d-fYwy-ZRxvu0
创建物理卷
[root@szrx-sjk01 /]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
# 查看创建结果,有两个物理卷,但新物理卷没有加入卷组
[root@szrx-sjk01 /]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size <99.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25343
Free PE 1
Allocated PE 25342
PV UUID bs9tE7-8HSk-iUFI-BQww-fp3d-fYwy-ZRxvu0
"/dev/vdb1" is a new physical volume of "<2.93 TiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size <2.93 TiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID kR9HV8-COty-J1xP-3DKy-Lr9P-3dlU-C2JQKV
将当前创建的物理卷加入到目的卷组
[root@szrx-sjk01 /]# vgextend centos /dev/vdb1
Volume group "centos" successfully extended
再查看物理卷
新的物理卷已经加入卷组centos
```bash
[root@szrx-sjk01 /]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size <99.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25343
Free PE 1
Allocated PE 25342
PV UUID bs9tE7-8HSk-iUFI-BQww-fp3d-fYwy-ZRxvu0
--- Physical volume ---
PV Name /dev/vdb1
VG Name centos
PV Size <2.93 TiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 767999
Free PE 767999
Allocated PE 0
PV UUID kR9HV8-COty-J1xP-3DKy-Lr9P-3dlU-C2JQKV
将卷组剩余空间添加到逻辑卷 /dev/centos/ home下
[root@szrx-sjk01 /]# lvextend -l +100%FREE /dev/centos/home
Size of logical volume centos/home changed from <45.12 GiB (11550 extents) to 2.97 TiB (779550 extents).
Logical volume centos/home successfully resized.
使扩容生效
[root@szrx-sjk01 /]# xfs_growfs /dev/centos/home
meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=2956800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=11827200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=5775, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11827200 to 798259200
如果是ext4系统使用下面命令
sudo resize2fs /dev/centos/home