All our servers come with a Cloud Init service. This service takes care of several tasks, such as changing passwords, updating the hostname and extending the partition when the disk is resized.
If you have migrated your server from another platform or have removed the Cloud Init service, you will need to extend the partition manually after resizing. In this article we explain how to do it on Linux; for Windows, see the Windows article. For a pfSense server, the process is different; click here to see it.
How to extend partitions on Linux
To extend the partition, connect to your server via SSH and run:
# growpart /dev/sda 1 The command above extends the partition; it does not change the filesystem. If it shows a message like:
NOCHANGE: partition 1 is size 2048. it cannot be grown
you can move on to the next step (extending the filesystem). On the other hand, if you see:
mkdir: cannot create directory ‘/tmp/growpart.35060’: No space left on device
you will need to free up some space first (Not enough space to extend the partition).
You can check that the partition size has increased by running:
# sfdisk -lIt will return output 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 LinuxTo check which filesystem you have, run the following command:
# df -hThis will show the following:
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/0Here you can see that the device is /dev/sda1. With this, run the following command to extend the filesystem:
# resize2fs /dev/sda1 # Extends the filesystemImportant
If your device is different, run the command with the device shown by the previous command. For example, if your device is /dev/sda2, you should run:
# resize2fs /dev/sda2
You can check that the filesystem size has increased by running:
# df -hIt will return output 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/0How to extend the partition on pfSense or FreeBSD
To extend the partition on a pfSense server, you can use the growfs service directly:
# service growfs onestartIt will carry out the extension automatically when it starts.
Error cases
Partition system errors
If you get errors while extending the partition, there is most likely a problem with your server's partition. To fix it, run fsck to check for and repair errors.
For example, on Linux you may come across 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 filesystemIn that case, follow the instructions in Check and repair the file system with FSCK.
Not enough space to extend the partition
It may also happen that there is not enough free space on the partition and the extension cannot run, showing the following message:
mkdir: cannot create directory ‘/tmp/growpart.35060’: No space left on device
FAILED: failed to make temp dirIn that case, you will need to free up some space first. You can run a cleanup with the package manager and remove obsolete packages:
# apt autoclean && apt autoremoveOnce done, you should have enough space to extend the partition.
We hope this article has helped you. If you have any questions about this or any other matter related to your servers at Clouding, write to us at soporte@clouding.io. We're here to help! 😉