First check that you have the cloud-guest-utils
package installed:
dpkg -l | grep cloud-guest-utils
If it is not installed, you can install it with:
sudo apt update && sudo apt install cloud-guest-utils
Next, check the current disk size and the partition layout:
lsblk
If you see that the disk size is larger than the partition size, you can resize the partition with:
Assuming that your disk is
/dev/sda
and the partition you want to resize is1
. Adjust the device and partition number as necessary.
sudo growpart /dev/sda 1
After resizing the partition, you can resize the filesystem with:
If your partition is different, replace
/dev/sda1
with the appropriate partition identifier.
sudo resize2fs /dev/sda1
Finally, verify that the filesystem has been resized successfully:
df -h
This command will show you the disk usage and confirm that the partition size has been updated to reflect the new disk size.
BONUS:
When using docker containers the overlay filesystem may double the size of the disk usage reported by df -h
. To see the actual disk usage, you can use:
df -h --total -x overlay -x tmpfs -x devtmpfs
If everything looks good, you have successfully resized the volume of your Ubuntu cloud instance.
- Make sure to back up any important data before resizing partitions or filesystems, as these operations can potentially lead to data loss if something goes wrong.
- The
growpart
command is part of thecloud-guest-utils
package, which is specifically designed for resizing partitions in cloud environments. - The
resize2fs
command is used for resizing ext2/ext3/ext4 filesystems, which is commonly used in Ubuntu. - If you are using a different filesystem type (e.g., XFS), you would use a different command to resize the filesystem (e.g.,
sudo xfs_growfs /dev/sda1
). - If you are using Scaleway, ensure that you have resized the volume from the Scaleway console or API before performing these steps, as the resizing of the partition and filesystem only works if the underlying volume has been expanded.
- If you are using a different cloud provider, the steps may vary slightly, but the general process should be similar. Always refer to your cloud provider's documentation for specific instructions on resizing volumes.