From f8b5d82ac50697aab97703e57e1deccccd68d140 Mon Sep 17 00:00:00 2001 From: c0de Date: Thu, 15 Dec 2022 22:52:52 -0600 Subject: [PATCH] Add ability to grow root partition + filesystem --- arch.pkr.hcl | 14 ++++++++++++++ files/grow-root | 16 ++++++++++++++++ files/grow-root.service | 9 +++++++++ scripts/install_system.sh | 4 ++-- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 files/grow-root create mode 100644 files/grow-root.service diff --git a/arch.pkr.hcl b/arch.pkr.hcl index 9d590a6..7a19bc0 100644 --- a/arch.pkr.hcl +++ b/arch.pkr.hcl @@ -82,6 +82,20 @@ build { destination = "/mnt/etc/systemd/network/99-dhcp-wildcard.network" } + provisioner "file" { + source = "files/grow-root" + destination = "/usr/local/sbin/grow-root" + } + + provisioner "shell" { + inline = ["chmod +x /usr/local/sbin/grow-root"] + } + + provisioner "file" { + source = "files/grow-root.service" + destination = "/etc/systemd/system/grow-root.service" + } + provisioner "shell" { pause_before = "10s" scripts = [ diff --git a/files/grow-root b/files/grow-root new file mode 100644 index 0000000..5329434 --- /dev/null +++ b/files/grow-root @@ -0,0 +1,16 @@ +#!/bin/bash + +dev="$(findmnt -nfvo SOURCE -- "/")" + +# If it's a partition, expand that first using growpart. +if [ "$(lsblk -ndo TYPE -- "$dev")" = part ]; then + disk="$(lsblk -ndpo PKNAME -- "$dev")" + partnum="${dev##*[!0-9]}" + growpart "$disk" "$partnum" || { [ $? -ne 1 ] && exit 1; } +fi + +# Inform kernel of new partition +partprobe + +# Expand the filesystem. +resize2fs -- "$dev" || exit 1 diff --git a/files/grow-root.service b/files/grow-root.service new file mode 100644 index 0000000..d657857 --- /dev/null +++ b/files/grow-root.service @@ -0,0 +1,9 @@ +[Unit] +Description=Grows the root partition and filesystem to match disk size + +[Service] +Type=oneshot +ExecStart=/usr/local/sbin/grow-root + +[Install] +WantedBy=multi-user.target diff --git a/scripts/install_system.sh b/scripts/install_system.sh index d7df110..8deee3d 100644 --- a/scripts/install_system.sh +++ b/scripts/install_system.sh @@ -4,8 +4,8 @@ set -eux pacman-key --init # Install the system -pacstrap -K /mnt base linux linux-firmware rng-tools grub sudo \ - openssh ufw git vim python-pip nomad nomad-driver-nspawn +pacstrap -K /mnt base linux linux-firmware rng-tools grub parted sudo \ + openssh ufw git vim cloud-utils python-pip nomad nomad-driver-nspawn # Clear the cache arch-chroot /mnt pacman -Scc --noconfirm