假设我的EBS卷刚开始使用的时候为100GB,而且未格式化!!
[root@ip-172-31-43-57 ~]# fdisk -l
Disk /dev/nvme0n1: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000b956b
Device Boot Start End Blocks Id System
/dev/nvme0n1p1 * 2048 209715166 104856559+ 83 Linux
#这个是EBS卷 100GB的
Disk /dev/nvme1n1: 107.4 GB, 107374182400 bytes, 209715200 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
#/dev/nvme1n1卷100GB
[root@ip-172-31-43-57 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 100G 0 disk
└─nvme0n1p1 259:1 0 100G 0 part /
nvme1n1 259:2 0 100G 0 disk
#新添加EBS卷未格式的,显示data
[root@ip-172-31-43-57 ~]# file -s /dev/nvme1n1
/dev/nvme1n1: data
#nvme0n1是根目录的卷,已经格式化是这样的
[root@ip-172-31-43-57 ~]# file -s /dev/nvme0n1
/dev/nvme0n1: x86 boot sector; partition 1: ID=0x83, active, starthead 0, startsector 2048, 209713119 sectors, code offset 0x63
#创建/data目录
[root@ip-172-31-43-57 ~]# mkdir /data
#安装xfsprogs
[root@ip-172-31-43-57 ~]#yum install xfsprogs -y
#格式化新EBS卷
root@ip-172-31-43-57 ~]# mkfs -t xfs /dev/nvme1n1
meta-data=/dev/nvme1n1 isize=512 agcount=4, agsize=6553600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=26214400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=12800, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@ip-172-31-43-57 ~]# mount /dev/nvme1n1 /data/
[root@ip-172-31-43-57 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p1 100G 955M 100G 1% /
devtmpfs 3.7G 0 3.7G 0% /dev
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 3.7G 17M 3.7G 1% /run
tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
tmpfs 747M 0 747M 0% /run/user/1000
tmpfs 747M 0 747M 0% /run/user/0
/dev/nvme1n1 100G 33M 100G 1% /data
下面开始进行对卷扩容,把100GB扩展为200GB容量
然后过几分钟,看到已经为200GB容量,但是还需要扩展的系统分区
[root@ip-172-31-43-57 /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:0 0 100G 0 disk
└─nvme0n1p1 259:1 0 100G 0 part /
nvme1n1 259:2 0 200G 0 disk /data
确认数据盘的类型类型为xfs
[root@ip-172-31-43-57 /]# blkid
/dev/nvme0n1p1: UUID="f41e390f-835b-4223-a9bb-9b4xxxxx8d" TYPE="xfs"
/dev/nvme0n1: PTTYPE="dos"
/dev/nvme1n1: UUID="219eb6ff-97a6-4f79-87b8-exxxxx6c01c" TYPE="xfs"
注意:我这儿是xfs类型···,ext4需要参考其他文档了
说了那么多废话,其实就是一台命令进行扩容而已········
#语法 xfs_growfs -d 挂载点
[root@ip-172-31-43-57 /]# xfs_growfs -d /data
meta-data=/dev/nvme1n1 isize=512 agcount=4, agsize=6553600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=26214400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=12800, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 26214400 to 52428800
扩容成功!!!
[root@ip-172-31-43-57 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/nvme0n1p1 100G 956M 100G 1% /
devtmpfs 3.7G 0 3.7G 0% /dev
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 3.7G 17M 3.7G 1% /run
tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
tmpfs 747M 0 747M 0% /run/user/1000
tmpfs 747M 0 747M 0% /run/user/0
/dev/nvme1n1 200G 33M 200G 1% /data
添加开机自动挂载
sudo cp /etc/fstab /etc/fstab.orig
sudo blkid
sudo vim /etc/fstab
#添加这行
UUID=aebf131c-6957-451e-8d34-ec978d9581ae /data xfs defaults,nofail 0 2
附加
如果上面无法扩容,可能你还需要操作多一个步骤再执行上面的命令
extend-linux-file-system
最后整理了一下,优化了整个流程首先是扩展分区(如果有必要的话),再扩展文件系统 (注意这里的xfs文件系统)
[[email protected] ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 30G 0 disk
└─xvda1 202:1 0 8G 0 part /
#扩展分区
#请注意,设备名称和分区编号之间有空格。
[[email protected] ~]# growpart /dev/xvda 1
CHANGED: partition=1 start=4096 old: size=16773087 end=16777183 new: size=62910431,end=62914527
[[email protected] ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 30G 0 disk
└─xvda1 202:1 0 30G 0 part /
#扩展文件系统
[[email protected] ~]# xfs_growfs -d /
meta-data=/dev/xvda1 isize=512 agcount=4, agsize=524159 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1 spinodes=0
data = bsize=4096 blocks=2096635, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 979M 0 979M 0% /dev
tmpfs 996M 0 996M 0% /dev/shm
tmpfs 996M 672K 996M 1% /run
tmpfs 996M 0 996M 0% /sys/fs/cgroup
/dev/xvda1 30G 5.6G 25G 19% /