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

작성자

카테고리:

← 피드로
DEV Community · Ai2th · 2026-08-05 개발(SW)

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

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다