Tuesday, September 15, 2020

How to Resize Partition without Losing Data in Ubuntu?

Today I encounter an issue relates to the disk storage with my server in Alibaba Cloud. I am hosting blockchain node on the server, and the storage utilization grow over time. Therefore, I write this blog is to share with you how to resize a disk online with Alibaba Cloud, then resize the partition without losing data.

First of all, login to your Alibaba Cloud console or any other cloud provider, select the data disk that you want to resize.

Key in the storage size that you want to increase, then make sure to select Online Resizing option.

After resizing the disk, you need to increase the existing partition, otherwise, the new storage size is still not usable.

Login to your Ubuntu server, then use the df command to check your existing disk space:

I have only one data disk in my server. Hence, my data disk is /dev/vdb, I suppose yours should be the same. You also can refer to my other post on how to mount data disk to your server.

Now, in order to resize the partition, we need to remove the existing one and then create a new one with the new size. Not to worry about the "remove" keyword, it will not remove your file. It mean delete the partition information only.

Run the fdisk command:

fdisk /dev/vdb

d = delete the selected partition
n = create new partition
p = primary partition

In order to maximize the partition, just simply press Enter to select the default partition, first sector and last sector. 

WARNING: You will be prompted Partition #1 contains a ext4 signature.
This is the most important step, make sure you key in NO to maintain the signature file, otherwise you will lose all your data.

The signature partition is to inform you that there is something in the partition, this warning only happen when it is not empty.

Once you are done, enter wq command to write the change.

If you run the ls command, you will notice your data is still around. Now, resize the partition by running the following command:

resize2fs /dev/vdb1

Now your data disk partition new available storage has been increased effectively. You can verify it by executing the df command.

Cheers!

Send Transactional SMS with API

This post cover how to send transactional SMS using the Alibaba Cloud Short Message Service API. Transactional SMS usually come with One Tim...