How to extend partitions manually

All our servers have a Cloud Init service included, this service is responsible for various tasks such as changing passwords, updating hostname, etc. It also takes care of extending our partition when a disk resize is done. If you have migrated your server from another platform or have deleted the Cloud Init service, when resizing, you must extend the partition manually, in this article we explain how to do it both in Linux and Windows.

How to extend partitions on Linux

In order to extend the partition, enter your server through SSH and execute:
# growpart /dev/sda 1 # Extiende partición; no cambia el filesystem

You can check that the size of the partition has increased by executing:
# sfdisk -l

It will return a result similar to:

Disk /dev/sda: 100 GiB, 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
Disklabel type: dos
Disk identifier: 0x566d4019
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 209715166 209713119 100G 83 Linux

To extend the filesystem
#resize2fs /dev/sda1 # Extiende el filesystem

You can check that the size of the filesystem has increased by executing:
df -h
It will return a result similar to:
Filesystem Size Used Avail Use% Mounted on
udev 487M 0 487M 0% /dev
tmpfs 100M 9.1M 91M 10% /run
/dev/sda1 99G 1.1G 94G 2% /
tmpfs 496M 0 496M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 496M 0 496M 0% /sys/fs/cgroup
tmpfs 100M 0 100M 0% /run/user/0

How to extend partitions on Windows

To extend the partition on a Windows server, access by remote desktop and go to “Computer manager> Disk management”. Select the partition “C:” and click with the right button to select “Extend Volume”:

On the following screens, press “next” without changing any values until you reach the end, then click on “finish”. Your partition has been extended:

Error cases

If during the process of extending the partition, you get errors, there is probably a problem with the partition of your server. In order to fix it, execute “fsck” to check and repair errors.

For example, on Linux you might encounter this error:
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 7
resize2fs: Permission denied to resize filesystem

To write a comment on this article, fill out the form below. Fields marked with an asterisk (*) are required.