How to Automatically Grow Filesystems in Ubuntu Using systemd-growfs

In virtualized enterprise clouds, Infrastructure-as-Code (IaC) pipelines, and template-driven server deployments, virtual machine disk volumes frequently expand after initial provisioning. Traditionally, resizing an underlying virtual disk or partition required manual administrator intervention—either by executing offline disk partition tools like parted followed by manual filesystem enlargement commands (such as resize2fs for ext4 or xfs_growfs for XFS), or by deploying complex orchestration scripts.

To automate this process seamlessly during system boot or partition expansion, systemd provides systemd-growfs. Working in close conjunction with systemd-gpt-auto-generator and the kernel online filesystem resize interfaces, systemd-growfs automatically expands mounted filesystems to consume all remaining free space on their underlying block devices without requiring manual commands or unmounting filesystems.

Architecture of systemd-growfs and systemd-makefs

The systemd-growfs utility (located at /usr/lib/systemd/systemd-growfs) operates as an online filesystem resize engine. Its architectural workflow functions as follows:

  • Block Device Expansion: When a cloud hypervisor (such as KVM, VMware, AWS EBS, or Azure Managed Disks) increases a virtual disk size, or when partition repartitioning tools (such as systemd-repart) expand a GPT partition boundary, the underlying block device capacity increases.
  • Service Instantiation: systemd-growfs is invoked through dynamic systemd template units formatted as [email protected], where the instance argument is the escaped mount point path (e.g. [email protected] for root /, or [email protected] for /var).
  • Kernel File System Query: The service inspects the target mount point, determines the underlying filesystem architecture (ext4, XFS, or btrfs), queries the block device geometry, and issues the appropriate filesystem expansion syscall to the Linux kernel while the partition remains mounted and active.

Configuring Declarative Automatic Growing in /etc/fstab

The standard method to enable automatic filesystem resizing in Ubuntu is by declaring the x-systemd.growfs mount option within /etc/fstab.

Open /etc/fstab in your preferred text editor:

sudo nano /etc/fstab

Locate the mount entry for your root partition or secondary data volumes. Append x-systemd.growfs to the comma-separated options column:

# Root partition configured for automatic filesystem growth
UUID=a1b2c3d4-e5f6-7890-abcd-1234567890ab  /        ext4  defaults,noatime,x-systemd.growfs  0  1

# Secondary database volume on XFS
UUID=f6a7b8c9-d0e1-2345-6789-abcdef012345  /var/lib/data  xfs   defaults,noatime,x-systemd.growfs  0  2

Save the file. When systemd parses /etc/fstab during boot (via systemd-fstab-generator), it detects the x-systemd.growfs flag and automatically synthesizes a dependency pulling in systemd-growfs@<mountpoint>.service immediately after the filesystem is mounted.

To reload systemd generator configurations without rebooting, run:

sudo systemctl daemon-reload

Triggering systemd-growfs Manually on Active Mount Points

You do not need to wait for a system reboot to expand a filesystem. If you have recently enlarged a virtual block device or extended a partition on a live server, you can trigger systemd-growfs directly from standard terminal execution.

To invoke systemd-growfs against the root filesystem, pass the mount point path as an argument:

sudo /usr/lib/systemd/systemd-growfs /

For secondary data volumes or dedicated container storage partitions:

sudo /usr/lib/systemd/systemd-growfs /var/lib/data

The utility inspects the underlying block device geometry, verifies available headroom, and expands the volume in real time. If the filesystem already occupies the entire device, systemd-growfs exits cleanly with no modification.

Verifying Systemd Units and Mount Dependencies

To inspect generated growfs service units and audit their execution logs:

Query the status of the root filesystem grow service:

systemctl status [email protected]

For custom mount paths such as /var/log or /data, systemd escapes slashes into dashes (e.g. [email protected]). You can list all active or historical growfs units with:

systemctl list-units "systemd-growfs@*"

To inspect the system journal logs recording the exact byte increase during expansion, execute:

journalctl -u "systemd-growfs@*" --no-pager

A typical journal record outputs:

systemd-growfs[542]: Successfully grown file system '/' to 53687091200 bytes (13107200 blocks of 4096 bytes).

Filesystem Support and Practical Constraints

systemd-growfs natively supports major modern Linux filesystems that expose kernel-level online expansion capabilities:

  • ext4: Expanded using the EXT4_IOC_RESIZE_FS ioctl.
  • XFS: Expanded via the XFS_IOC_FSGROWFSDATA ioctl (identical to the mechanism used by xfs_growfs).
  • btrfs: Expanded using the native BTRFS_IOC_RESIZE ioctl.

Note that systemd-growfs expands the filesystem inside an existing partition boundary. If your cloud provider increases the underlying virtual disk size without expanding the partition table itself, the partition must first be grown (either via cloud-init, systemd-repart, or growpart) before systemd-growfs can expand the filesystem to fill the newly allocated partition space.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.