Site icon moneyslow.com

阿里云ecs云盘(磁盘)在线扩容

20210823更新 https://help.aliyun.com/document_detail/113316.htm
官网在线扩容,付费后,执行2条命令即可:

growpart /dev/vdb 1

CHANGED: partition=1 start=2048 old: size=356513759 end=356515807 new: size=377485279,end=377487327

resize2fs /dev/vdb1

resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/vdb1 is mounted on /data; on-line resizing required
old_desc_blocks = 22, new_desc_blocks = 23
The filesystem on /dev/vdb1 is now 47185659 (4k) blocks long.

-----以下旧闻-----

所谓在线扩容,并不是技术为你摆平了一切,需要手动执行一些操作。所以还是建议把需要的云盘umount 掉。
阿里帮助文档位置:
https://help.aliyun.com/document_detail/25452.html
本例子是把一个单独的数据盘进行扩容,所以看这部分:

只对数据盘进行扩容
阿里云在线扩容磁盘

大概步骤是umount掉数据盘/dev/vdb ,利用fdisk进行分区删除,同时记下分区开始和结束位置,利用fdisk重新分区(这里有删除分区的操作,不用担心会丢失数据),利用partprobe通知内核更新分区表,利用resize2fs调整系统分区大小,重新mount即可。以下是详细步骤:

选项一:扩展已有MBR分区
说明 为了防止数据丢失,不建议扩容已挂载的分区和文件系统。请先取消挂载(umount)分区,完成扩容并正常使用后,重新挂载(mount)。针对不同的Linux内核版本,推荐以下操作方式:
实例内核版本小于3.6:先取消挂载该分区,再修改分区表,最后扩容文件系统。
实例内核版本大于等于3.6:先修改对应分区表,再通知内核更新分区表,最后扩容文件系统。
如果新增空间用于扩容已有的MBR分区,按照以下步骤在实例中完成扩容:

修改分区表。
运行以下命令查看分区信息,并记录旧分区的起始和结束的扇区位置。
fdisk -lu /dev/vdb
本示例中,分区/dev/vdb1的起始扇区是2048,结束扇区是41943039。

[root@ecshost ~]# fdisk -lu /dev/vdb
Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47b

Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux
查看数据盘的挂载路径,根据返回的文件路径卸载分区,直至完全卸载已挂载的分区。
[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"
使用fdisk工具删除旧分区。
警告 删除旧分区会一同删除分区内的数据。如有重要数据请备份,例如数据库中的用户数据,避免因删除旧分区而造成数据丢失。
运行fdisk -u /dev/vdb:分区数据盘。
输入p:打印分区表。
输入d:删除分区。
输入p:确认分区已删除。
输入w:保存修改并退出。
[root@ecshost ~]# 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: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47b
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): p
Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47b
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.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
使用fdisk命令新建分区。
运行fdisk -u /dev/vdb:分区数据盘。
输入p:打印分区表。
输入n:新建分区。
输入p:选择分区类型为主分区。
输入<分区号>:选择分区号。本示例选取了1。
警告 新分区的起始位置必须和旧分区的起始位置相同,结束位置必须大于旧分区的结束位置,否则会导致扩容失败。
输入w:保存修改并退出。
本示例中,将/dev/vdb1由20GiB扩容到40GiB。

[root@ecshost ~]# 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: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47b
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-83886079, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):
Partition 1 of type Linux and of size 30 GiB is set
Command (m for help): p
Disk /dev/vdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x9277b47b
Device Boot Start End Blocks Id System
/dev/vdb1 2048 62916607 31457280 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
通知内核更新分区表。
运行partprobe <数据盘设备名>或者partx -u <数据盘设备名>,通知内核数据盘的分区表已经修改,需要同步更新。
运行lsblk /dev/vdb确保分区表已经增加。
运行e2fsck -n /dev/vdb1再次检查文件系统,确认扩容分区后的文件系统状态为clean。
扩容文件系统。
ext*文件系统(例如ext3和ext4):依次运行以下命令调整ext*文件系统大小并重新挂载分区。
[root@ecshost ~]# resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vdb1 to 7864320 (4k) blocks.
The filesystem on /dev/vdb1 is now 7864320 blocks long.
[root@ecshost ~]# mount /dev/vdb1 /mnt
xfs文件系统:依次运行以下命令先重新挂载分区,再调整xfs文件系统大小。
[root@ecshost ~]# mount /dev/vdb1 /mnt/
[root@ecshost ~]# xfs_growfs /dev/vdb1
meta-data=/dev/vdb1              isize=512    agcount=4, agsize=1310720 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=5242880, 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
data blocks changed from 5242880 to 7864320
Exit mobile version