DEV Community

Ai2th
Ai2th

Posted on

Linxr | Part 9 — Dynamic Storage Expansion & Automatic resize2fs on Boot

In Part 8, we solved network latency for instant terminal typing. Today in Part 9, we explain how we implemented dynamic virtual disk expansion (resize2fs) across reboots without data loss.


The Problem: Hardcoded 1.4 GB Filesystems

In early Linxr builds, setting 30 GB or 50 GB storage in Settings appeared to allocate a larger QCOW2 virtual disk. However, inside Alpine Linux, running df -h still reported only 1.4 GB of usable disk space!

Why?

  1. The base rootfs image was formatted as a 1.4 GB ext4 partition.
  2. Expanding the QCOW2 overlay on Android enlarged the block device, but the guest ext4 filesystem never expanded to fill the new capacity.

The Solution: OpenRC diskexpand Service

To automate seamless filesystem expansion:

  1. Bundling e2fsprogs-extra: Installed resize2fs into the base Alpine Linux rootfs.
  2. Boot-Time Auto-Expansion: Created a dedicated OpenRC init service (/etc/init.d/diskexpand) running before sshd starts:
#!/sbin/openrc-run

depend() {
    need localmount
    before sshd
}

start() {
    ebegin "Expanding ext4 filesystem to fill virtual disk"
    resize2fs /dev/vda2 >/dev/null 2>&1
    eend $?
}
Enter fullscreen mode Exit fullscreen mode

Because resize2fs is a fast online operation, it runs in milliseconds on boot. If the disk cap is unchanged, it returns instantly as a no-op; if the user selects 50 GB in Settings, it expands the filesystem dynamically with zero data loss!


Links

Top comments (0)