feat: add auto-grow-root service for live disk resize
Adds systemd service that automatically grows the root filesystem on boot: - Detects partition layout and grows partition if needed (growpart) - Supports both ext4 (resize2fs) and btrfs filesystems - Works with VIRTIO-SCSI disk (/dev/sda) - Enables seamless live disk resize from the hosting platform 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -89,6 +89,38 @@
|
||||
# Enable the OpenSSH daemon.
|
||||
services.openssh.enable = true;
|
||||
|
||||
# Auto-grow root filesystem on boot (for live disk resize support)
|
||||
# Works with VIRTIO-SCSI (/dev/sda) - detects partition layout automatically
|
||||
systemd.services.auto-grow-root = {
|
||||
description = "Auto-grow root filesystem";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "local-fs.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
path = with pkgs; [ cloud-utils parted e2fsprogs btrfs-progs util-linux ];
|
||||
script = ''
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DEV=$(findmnt -n -o SOURCE /)
|
||||
ROOT_DISK=$(lsblk -no PKNAME "$ROOT_DEV" | head -1)
|
||||
|
||||
# If partitioned, grow partition first
|
||||
if [[ "$ROOT_DEV" =~ [0-9]$ ]]; then
|
||||
PART_NUM=$(echo "$ROOT_DEV" | grep -oE '[0-9]+$')
|
||||
growpart "/dev/$ROOT_DISK" "$PART_NUM" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Grow filesystem
|
||||
FSTYPE=$(findmnt -n -o FSTYPE /)
|
||||
case "$FSTYPE" in
|
||||
ext4) resize2fs "$ROOT_DEV" 2>/dev/null || true ;;
|
||||
btrfs) btrfs filesystem resize max / 2>/dev/null || true ;;
|
||||
esac
|
||||
'';
|
||||
};
|
||||
|
||||
|
||||
# This value determines the NixOS release from which the default
|
||||
# settings for stateful data, like file locations and database versions
|
||||
|
||||
Reference in New Issue
Block a user