Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This repository builds two base images for Exordos Core project. The images cont
The key features are:

- [Universal Agent](https://github.com/infraguys/gcl_sdk/wiki/universal_agent) service.
- Exordos root autoresize service. Tries to perform resize of the root partition at every boot if it's possible.
- Exordos autoresize service. Grows partitions and filesystems (ext2/3/4 and xfs) up to the disk size, at every boot and, via a udev rule, when the hypervisor enlarges a disk of a running machine.
- Exordos bootstrap service. Runs the bootstrap scripts.

## 🛠️ Build
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[Unit]
Description=Exordos root autoresize one shot unit
DefaultDependencies=no
Description=Exordos disk autoresize one shot unit
Conflicts=shutdown.target
Before=local-fs.target shutdown.target
After=local-fs.target
Before=shutdown.target

[Service]
Type=oneshot
Expand All @@ -12,7 +12,7 @@ RestartSec=5s
TimeoutStopSec=5
RemainAfterExit=yes
StandardOutput=journal
ExecStart=/usr/bin/root_autoresize.sh
ExecStart=/usr/bin/exordos_autoresize.sh

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Exordos disk autoresize for /dev/%i
Conflicts=shutdown.target
Before=shutdown.target

[Service]
Type=oneshot
StandardOutput=journal
ExecStart=/usr/bin/exordos_autoresize.sh /dev/%i
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The kernel emits a "change" uevent with RESIZE=1 when the hypervisor
# enlarges a disk of a running machine. Grow the partitions and filesystems
# on that disk so the new space becomes usable without a reboot.
ACTION=="change", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", ENV{RESIZE}=="1", \
ENV{SYSTEMD_WANTS}+="exordos-autoresize@%k.service"
111 changes: 111 additions & 0 deletions exordos/images/exordos_base/exordos_autoresize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env bash

# Copyright 2025-2026 Genesis Corporation
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

# Grow partitions and filesystems up to the size of the underlying disk.
#
# Usage:
# exordos_autoresize.sh grow every mounted partition
# exordos_autoresize.sh <disk> grow the mounted partitions of one disk
#
# The first form runs once at boot and covers disks that were enlarged while
# the machine was off. The second form is triggered by udev when the
# hypervisor enlarges a disk of a running machine.

set -eu
set -x
set -o pipefail

log() {
echo "[exordos-autoresize] $*"
}

wait_for_rw_root() {
while [[ "$(findmnt / -o options -n | grep -E "^ro,|,ro,|,ro$")" != "" ]]
do
log "Waiting for root partition to be in RW mode"
sleep 2
done
}

# List "<partition> <mount point>" pairs of mounted partitions.
# Args:
# $1 - (optional) disk to limit the listing to, e.g. /dev/vda
list_mounted_partitions() {
local disk="${1:-}"

# shellcheck disable=SC2086
lsblk -nr -o PATH,TYPE,MOUNTPOINT ${disk:+"$disk"} \
| awk '$2 == "part" && $3 != "" && $3 != "[SWAP]" {print $1, $3}'
}

# Grow a single mounted partition and the filesystem on it.
# Args:
# $1 - partition device, e.g. /dev/vda1
# $2 - mount point of that partition, e.g. /
grow_partition() {
local part="$1"
local mount_point="$2"
local disk partition_number fstype

fstype="$(findmnt -n -o FSTYPE "$mount_point")"

# Partitions we cannot grow are expected here: the sweep walks every mounted
# partition, and images ship an EFI system partition among them.
case "$fstype" in
ext2|ext3|ext4|xfs) ;;
*)
log "Filesystem '$fstype' on $part is not growable; skipping"
return 0
;;
esac

disk="/dev/$(lsblk -no PKNAME "$part")"
partition_number="$(cat "/sys/class/block/$(basename "$part")/partition")"

log "Growing $part ($fstype) on disk $disk, partition $partition_number, mounted at $mount_point"

# growpart exits non-zero when the partition is already the last one and
# occupies the whole disk, so failures here are not fatal.
growpart "$disk" "$partition_number" || true

case "$fstype" in
ext2|ext3|ext4)
resize2fs "$part"
;;
xfs)
# XFS grows by mount point, not by device
xfs_growfs "$mount_point"
Comment thread
phantomii marked this conversation as resolved.
;;
esac
}

DISK="${1:-}"

if [[ -n "$DISK" && ! -b "$DISK" ]]; then
log "Disk $DISK does not exist; nothing to grow"
exit 0
fi

wait_for_rw_root

RC=0
while read -r PART MOUNT_POINT; do
grow_partition "$PART" "$MOUNT_POINT" || RC=1
done < <(list_mounted_partitions "$DISK")

exit "$RC"
8 changes: 5 additions & 3 deletions exordos/images/exordos_base/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@ sudo ln -sf "$AGENT_PATH/.venv/bin/exordos-universal-agent" "/usr/bin/exordos-un
# Install stuff for bootstrap procedure and systemd services
sudo mkdir -p "$WORK_DIR/bootstrap/scripts/"
sudo cp "$IMG_ARTS_PATH/bootstrap.sh" "$WORK_DIR/bootstrap/"
sudo cp "$IMG_ARTS_PATH/root_autoresize.sh" "/usr/bin/"
sudo cp "$IMG_ARTS_PATH/exordos_autoresize.sh" "/usr/bin/"
sudo cp "$IMG_ARTS_PATH/etc/systemd/exordos-bootstrap.service" $SYSTEMD_SERVICE_DIR
sudo cp "$IMG_ARTS_PATH/etc/systemd/exordos-root-autoresize.service" $SYSTEMD_SERVICE_DIR
sudo cp "$IMG_ARTS_PATH/etc/systemd/exordos-autoresize.service" $SYSTEMD_SERVICE_DIR
sudo cp "$IMG_ARTS_PATH/etc/systemd/exordos-autoresize@.service" $SYSTEMD_SERVICE_DIR
sudo cp "$IMG_ARTS_PATH/etc/systemd/exordos-universal-agent.service" $SYSTEMD_SERVICE_DIR
sudo cp "$IMG_ARTS_PATH/etc/udev/90-exordos-autoresize.rules" /etc/udev/rules.d/
sudo mkdir -p "/usr/local/lib/exordos/"
sudo cp -a "$IMG_ARTS_PATH/lib/." "/usr/local/lib/exordos/"

# Enable exordos core services
sudo systemctl enable exordos-bootstrap exordos-root-autoresize exordos-universal-agent
sudo systemctl enable exordos-bootstrap exordos-autoresize exordos-universal-agent

# Commented out because we don't need Alloy for now and we are going to change monitoring solution
# Install Alloy
Expand Down
54 changes: 0 additions & 54 deletions exordos/images/exordos_base/root_autoresize.sh

This file was deleted.