Resize the data disk on Alibaba Cloud ECS

Resize the data disk on Alibaba Cloud ECS



  • Ubuntu 18.04

Data Backup

This is important in case anything unpredicted occurs, so everything can be simply rollbacked. But to save the data for the new partition, manually duplicate the data might be necessary.

In the control panel of Alibaba Cloud, disk snapshot can be created in the Disk section. Following the simple instruction(basically input the name for the snapshot), a snapshot of the data disk will be generated.

Basic Procedures

Unmount the disk

umount /dev/vdb1 // unmount the partition that is being used

Renew the parportion table

fdisk /dev/vdb // start the program to manipulate partition tables

root@localhost:~# fdisk /dev/vdb

Command (m for help): d //delete partition 
Selected partition 1

Command (m for help): n //create new partition
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p //type of partition to create
Partition number (1-4, default 1):
Using default value 1
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199

Command (m for help): wq //write and quit
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

For New Disk

Format the new partition

mkfs.ext3 /dev/vdb1 //format the partition in ext3 format

Write the partition information

echo '/dev/vdb1 /mnt ext3 defaults 0 0'>> /etc/fstab

For Disk With Data

Resize(without losing data)

e2fsck -n /dev/vdb1 # check the file system
resize2fs /dev/vdb1 # resize the file system

Remount the disk back

mount /dev/xvdb1 /mnt

Useful Command

  • Check available disks
    fdisk -l

  • Check a specific disk
    fdisk -lu /dev/vdb1

  • View the mounted disk(partition)
    df -Th


The disk can always rollback with a snapshot. Not only the data will be restored, but the partition detail will also rollback

So to save the original data, the current practice is to backup the data to another disk and then restore it back after the partitioning and formatting.