在阿里云ECS控制台中,选择你要扩容的那个服务器,进行扩容。扩容完成后,重启服务器,并创建快照以备份数据。
yum install cloud-utils-growpart
apt install cloud-guest-utils
[root@izwz9e66hx6no4074nle2lz ~]# uname -a
Linux izwz9e66hx6no4074nle2lz 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@izwz9e66hx6no4074nle2lz ~]#
3.10.0,就是我的服务器内核版本。
[root@localhost ~]# fdisk -l
Disk /dev/vda: 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: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 41943039 20970496 83 Linux
示例返回磁盘(/dev/vda)容量是100 GiB,但是分区容量只有20G。
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 19G 0G 100% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 344K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0`
[root@localhost ~]# growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=41940992 end=41943040 new: size=209710462,end=209712510
命令表示:为系统盘的第一个分区扩容,即4.2步骤中的第一个分区。
[root@localhost ~]# resize2fs /dev/vda1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 7
The filesystem on /dev/vda1 is now 26213807 blocks long.
命令表示:为系统盘的/dev/vda1分区扩容文件系统。
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 100G 19G 80G 25% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 344K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
以CentOS 6操作系统为例演示分区扩展的步骤
[root@AliYunOS ~]# yum install -y dracut-modules-growroot
[root@AliYunOS ~]# dracut -f
[root@AliYunOS ~]# fdisk -l
Disk /dev/vda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003a7b4
Device Boot Start End Blocks Id System
/dev/vda1 * 1 2611 20970496 83 Linux
[root@AliYunOS ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 1.1G 18G 6% /
tmpfs 7.8G 0 7.8G 0% /dev/shm
[root@AliYunOS ~]# growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=41940992 end=41943040 new: size=209710462,end=209712510
命令表示:为系统盘的第一个分区扩容。
[root@AliYunOS ~]# reboot
[root@AliYunOS ~]# resize2fs /dev/vda1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vda1 is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 7
Performing an on-line resize of /dev/vda1 to 26213807 (4k) blocks.
The filesystem on /dev/vda1 is now 26213807 blocks long.
[root@AliYunOS ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 1.1G 93G 2% /
tmpfs 7.8G 0 7.8G 0% /dev/shm