更多扩展方法参考:https://help.aliyun.com/document_detail/25452.html
这里从200G扩容到300G
查看现有情况
fdisk -l /dev/sdb
Disk /dev/sdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
外部添加磁盘
直接修改硬盘2的大小,保存即可。
命令通知内核更新分区表
partprobe /dev/vdb
查看磁盘已经变大。
fdisk -l /dev/sdb
Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 sectors
开始扩容
确认分区表格式和文件系统
1、确定格式
[root@localhost /]# fdisk -lu /dev/sdb
Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x2b9cd776
Device Boot Start End Blocks Id System
/dev/sdb1 2048 419430399 209714176 83 Linux
如果System为Linux,说明数据盘使用的是MBR分区表格式。
如果System为GPT,说明数据盘使用的是GPT分区表格式。
这里为MBR
2、文件类型
[root@localhost /]# blkid /dev/sdb1
/dev/sdb1: UUID="51202885-a1c4-48ee-9daa-2824c1c8262c" TYPE="xfs"
这里为xfs
3、运行以下命令确认文件系统的状态。
ext*文件系统:e2fsck -n /dev/sdb1
xfs文件系统:xfs_repair -n /dev/sdb1
扩展已有MBR分区
必须取消挂载(umount)数据盘。
1、使用fdisk工具删除旧分区。
p d p w
[root@localhost /]# fdisk -u /dev/sdb
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): p
Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x2b9cd776
Device Boot Start End Blocks Id System
/dev/sdb1 2048 419430399 209714176 83 Linux
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): p
Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x2b9cd776
Device Boot Start End Blocks Id System
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2、使用fdisk命令新建分区。
p n p w
[root@localhost /]# fdisk -u /dev/sdb
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): p
Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x2b9cd776
Device Boot Start End Blocks Id System
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):
First sector (2048-629145599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599):
Using default value 629145599
Partition 1 of type Linux and of size 300 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3、命令通知内核更新分区表。
partprobe /dev/sdb
4、运行以下命令确保分区表已经增加。
[root@localhost /]# lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 300G 0 disk
└─sdb1 8:17 0 300G 0 part /data
扩容文件系统
ext文件系统(例如ext3和ext4):依次运行以下命令调整ext文件系统大小并重新挂载分区。
# 调整ext*文件系
resize2fs /dev/sdb1
xfs文件系统:依次运行以下命令先重新挂载分区,再调整xfs文件系统大小。
# 分区挂载到/mnt。
mount /dev/vdb1 /mnt
#调整xfs文件系统大小。
xfs_growfs /mnt
挂载磁盘查看
[root@localhost /]# mount -a
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 300G 1.6G 299G 1% /data
查看扩容情况
[root@localhost /]# xfs_growfs /data/
meta-data=/dev/sdb1 isize=512 agcount=9, agsize=6553536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=52428544, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=12799, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 52428544 to 78642944
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 300G 1.6G 299G 1% /data
sdb1 已经正常识别容量了。