The Unexpected Expansion
When deploying Ubuntu Server in cloud environments (like AWS, Azure, or DigitalOcean), the operating system often utilizes a utility called cloud-init. This powerful tool handles the initial setup of the virtual machine on its first boot. One of the default tasks cloud-init performs is checking if the underlying virtual disk is larger than the root partition and, if so, automatically resizing the partition (and often the LVM logical volume) to fill the available space. While usually desirable for maximizing storage, this automatic expansion can ruin carefully planned partitioning schemes if you intended to leave that unallocated space for swap files, separate data partitions, or specific database storage configurations.
Disabling Partition Growth in cloud-init
To maintain strict control over your disk geometry and stop Ubuntu from automatically resizing partitions via cloud-init on boot, you must modify the configuration files before or immediately after deployment.
You need to instruct cloud-init to skip the disk setup module. If you are already logged into the server, open a terminal. The configuration is spread across several files in /etc/cloud/. You should create a custom override file rather than editing the defaults. Type sudo nano /etc/cloud/cloud.cfg.d/99-disable-resize.cfg. Inside this new, empty file, add the following YAML configuration exactly: growpart: {mode: off}. Save the file (Ctrl+O, Enter) and exit (Ctrl+X). This tells the growpart module of cloud-init to do nothing. If you are provisioning the server, you can pass this same YAML snippet via the “User Data” field in your cloud provider’s launch console to ensure the partition is never touched during the very first boot.