一:准备工作
在扩展数据盘扩展分区和文件系统前,请提前完成以下工作。
创建快照以备份数据,防止操作失误导致数据丢失。
通过ECS控制台或者API扩容云盘容量。
远程连接ECS实例。连接方式请参见连接方式导航。
确认分区格式和文件系统
1:运行fdisk -lu /dev/vdb
确认数据盘是否分区。
本示例中,原有的数据盘空间已做分区/dev/vdb1。“System”=“Linux"说明数据盘使用的是MBR分区格式,如果"System”="GPT"则说明数据盘使用的是GPT格式。
2:分别运行blkid /dev/vdb1 blkid /dev/vdb2 blkid /dev/vdb3
确认文件系统的类型。
本示例中,/dev/vdb1的文件系统类型为ext4,而/dev/vdb2、/dev/vdb3,不是
(说明 未分区并且未创建文件系统的数据盘,以及已分区但未创建文件系统的数据盘,不会返回结果。)。
分别执行mkfs.ext4 /dev/vdb2 mkfs.ext4 /dev/vdb3
这两个命令确定分区文件系统类型;
3:运行以下命令确认文件系统的状态:
分别执行e2fsck -n /dev/vdb1 e2fsck -n /dev/vdb2 e2fsck -n /dev/vdb3
三个命令确认文件系统状态;警告 :本示例中,三个分区文件系统状态为clean。如果状态不是clean,请排查并修复。
二:具体操作
说明: 为了防止数据丢失,不建议扩容已挂载的分区和文件系统。请先取消挂载(umount)分区,完成扩容并正常使用后,重新挂载(mount)。针对不同的Linux内核版本,推荐以下操作方式:
实例内核版本 < 3.6:先取消挂载该分区,再修改分区表,最后扩容文件系统。
实例内核版本 ≥ 3.6:先修改对应分区表,再通知内核更新分区表,最后扩容文件系统。
1:修改分区表
(1)运行fdisk -lu /dev/vdb,并记录旧分区的起始和结束的扇区位置。
本示例中,/dev/vdb1的起始扇区是2048,结束扇区是41943039。
(2)查看数据盘的挂载路径,根据返回的文件路径卸载分区,直至完全卸载已挂载的分区。
[root@ecshost ~]# mount | grep "/dev/vdb"
/dev/vdb1 on /mnt type ext4 (rw,relatime,data=ordered)
[root@ecshost ~]# umount /dev/vdb1
[root@ecshost ~]# mount | grep "/dev/vdb"
(3)使用fdisk工具删除旧分区,将三个分区全部删除;
[root@1 ~]# fdisk -u /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.
Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 is deleted
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 is deleted
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): p
Disk /dev/vdb: 27.9 GB, 27917287424 bytes, 54525952 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: 0xea45a647
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.
(4)使用fdisk命令新建分区。
[root@1 ~]# fdisk -u /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.
Command (m for help): p
Disk /dev/vdb: 27.9 GB, 27917287424 bytes, 54525952 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: 0xea45a647
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): 1
First sector (2048-54525951, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-54525951, default 54525951):
Using default value 54525951
Partition 1 of type Linux and of size 26 GiB is set
Command (m for help): p
Disk /dev/vdb: 27.9 GB, 27917287424 bytes, 54525952 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: 0xea45a647
Device Boot Start End Blocks Id System
/dev/vdb1 2048 54525951 27261952 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
(5):运行lsblk /dev/vdb
确保分区表已经增加。
(6):运行partprobe /dev/vdb1
或者partx -u /dev/vdb1
,以通知内核数据盘的分区表已经修改,需要同步更新。
(7):执行e2fsck -f /dev/vdb1
运行文件系统
(8):运行resize2fs /dev/vdb1
并重新挂载分区。
(9):执行mount /dev/vdb1 /www
挂载使用;
有图可知,整合成功,且数据都在;