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?
- The base rootfs image was formatted as a 1.4 GB ext4 partition.
- 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:
-
Bundling e2fsprogs-extra: Installed
resize2fsinto the base Alpine Linux rootfs. -
Boot-Time Auto-Expansion: Created a dedicated OpenRC init service (
/etc/init.d/diskexpand) running beforesshdstarts:
#!/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 $?
}
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
- 📲 Google Play: https://play.google.com/store/apps/details?id=com.ai2th.linxr
- 🌐 Website: https://ai2th.github.io/linxr.html
Top comments (0)