ops(nh3-dev): grow root into the 378 GB disk online; swap moved to /swapfile

Prime grew VM 102's scsi0 from 250 to 378 GB after the root alert hit 85%
twice in 14 h. The swap partition sat right after sda1 and blocked growth,
so the playbook moves swap to a 4 GB /swapfile, deletes sda5/sda2, grows
sda1 in place (start sector unchanged) and ext4 online, and sets initramfs
RESUME=none so boots don't wait for the vanished swap. Root is 372 GB, 58%.
This commit is contained in:
vh
2026-10-02 07:33:36 -07:00
parent 01c356e7fb
commit 6ec76bf35c
3 changed files with 112 additions and 0 deletions
+104
View File
@@ -0,0 +1,104 @@
# Grow nh3-dev's root filesystem into space added to its disk in Proxmox (VM 102 on nh3-pve).
# First used 2026-10-02: Prime grew scsi0 250G -> 378G after the 85% root alert fired twice in 14 h.
#
# The obstacle: the Debian installer put swap (sda5, inside extended sda2) right AFTER sda1, so
# sda1 cannot grow until that swap partition is gone. This playbook moves swap to /swapfile, deletes
# sda5 and sda2, grows sda1 in place (start sector unchanged) and grows ext4 online. No reboot.
#
# Take a VM snapshot on nh3-pve FIRST (qm snapshot 102 <name>). The partition table is also dumped to
# /var/backups/nh3-dev-rootgrow-<stamp>/sda-ptable.sfdisk, which `sfdisk /dev/sda < dump` restores (sda1's data is untouched
# either way: only its end moves).
#
# RESUME: initramfs-tools points resume-from-hibernation at the old swap UUID. With that partition
# gone, every boot would wait ~30 s for it, so RESUME is set to none and all initrds are rebuilt.
#
# scripts/elway infra-ops@10.100.10.50 --playbook playbooks/nh3-dev-grow-root.yaml
vars:
stamp: "20261002"
old_swap_uuid: 97bca850-bf72-4881-ae33-23d9b68315b6
swapfile_size: 4G
steps:
- name: Back up the partition table, fstab and the resume config
sudo: true
shell: |
set -e
install -d -m 755 /var/backups/nh3-dev-rootgrow-{{ stamp }}
cp -p /etc/fstab /etc/initramfs-tools/conf.d/resume /var/backups/nh3-dev-rootgrow-{{ stamp }}/
/usr/sbin/sfdisk -d /dev/sda > /var/backups/nh3-dev-rootgrow-{{ stamp }}/sda-ptable.sfdisk
# guards run as infra-ops, so the marker lives where infra-ops can see it (not under /root)
creates: /var/backups/nh3-dev-rootgrow-{{ stamp }}/sda-ptable.sfdisk
- name: Install growpart (cloud-guest-utils)
sudo: true
shell: DEBIAN_FRONTEND=noninteractive apt-get install -y -q cloud-guest-utils
creates: /usr/bin/growpart
- name: Create and enable /swapfile ({{ swapfile_size }}) BEFORE dropping the swap partition
sudo: true
shell: |
set -e
fallocate -l {{ swapfile_size }} /swapfile
chmod 600 /swapfile
/usr/sbin/mkswap /swapfile
/usr/sbin/swapon /swapfile
creates: /swapfile
- name: Add /swapfile to fstab
sudo: true
shell: echo '/swapfile none swap sw 0 0' >> /etc/fstab
when: "! grep -q '^/swapfile ' /etc/fstab"
- name: Turn off the old swap partition (its pages move to RAM or /swapfile)
sudo: true
shell: /usr/sbin/swapoff /dev/sda5
when: "/usr/sbin/swapon --show=NAME --noheadings | grep -qx /dev/sda5"
- name: Drop the old swap partition from fstab
sudo: true
shell: sed -i '/^UUID={{ old_swap_uuid }} /d' /etc/fstab
when: "grep -q '^UUID={{ old_swap_uuid }} ' /etc/fstab"
- name: Point initramfs resume at nothing and rebuild every initrd
sudo: true
shell: |
set -e
echo 'RESUME=none' > /etc/initramfs-tools/conf.d/resume
update-initramfs -u -k all
when: "! grep -qx 'RESUME=none' /etc/initramfs-tools/conf.d/resume"
- name: Delete partitions 5 (old swap) and 2 (the extended partition holding it)
sudo: true
shell: |
set -e
/usr/sbin/sfdisk --no-reread --force --delete /dev/sda 5
/usr/sbin/sfdisk --no-reread --force --delete /dev/sda 2
partx -d --nr 5 /dev/sda || true
partx -d --nr 2 /dev/sda || true
when: "sudo -n /usr/sbin/sfdisk -d /dev/sda | grep -q '^/dev/sda2 '"
- name: Grow partition 1 to the end of the disk (start sector unchanged)
sudo: true
shell: growpart /dev/sda 1
when: "sudo -n growpart --dry-run /dev/sda 1 >/dev/null 2>&1"
- name: Grow the ext4 filesystem online
sudo: true
shell: /usr/sbin/resize2fs /dev/sda1
verify:
- name: Only sda1 remains, still starting at sector 2048
sudo: true
shell: |
test "$(/usr/sbin/sfdisk -d /dev/sda | grep -c '^/dev/sda')" = 1 && /usr/sbin/sfdisk -d /dev/sda | grep -q '^/dev/sda1 : start= *2048,'
changed_when: "false"
- name: Root filesystem is now over 350 GB
shell: test "$(df -BG --output=size / | tail -1 | tr -dc 0-9)" -gt 350
changed_when: "false"
- name: /swapfile is the active swap and the old partition is gone from fstab
sudo: true
shell: /usr/sbin/swapon --show=NAME --noheadings | grep -qx /swapfile && ! grep -q '{{ old_swap_uuid }}' /etc/fstab
changed_when: "false"
- name: Root is still mounted by its UUID in fstab
shell: grep -q '^UUID=689f8c0c-1230-43a5-93c2-6baf76867d70 / ' /etc/fstab
changed_when: "false"