Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions board/aarch64/linux_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ CONFIG_JUMP_LABEL=y
# CONFIG_GCC_PLUGINS is not set
CONFIG_MODULES=y
CONFIG_MODULE_UNLOAD=y
CONFIG_PARTITION_ADVANCED=y
# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
# CONFIG_COMPAT_BRK is not set
CONFIG_KSM=y
Expand Down
138 changes: 138 additions & 0 deletions board/common/rootfs/usr/libexec/infix/mnt
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,140 @@ factory_reset()
sync
}

is_rpi()
{
[ -r /sys/firmware/devicetree/base/model ] || return 1

model=$(cat /sys/firmware/devicetree/base/model 2>/dev/null | tr -d '\0')
echo "$model" | grep -q "^Raspberry Pi"
}

wait_mmc()
{
# Try up to 50 times with 0.2s sleep = 10 second timeout
for _ in $(seq 50); do
if ls /dev/mmcblk* >/dev/null 2>&1; then
logger $opt -p user.notice -t "$nm" "MMC device available after delay"
return 0
fi
sleep .2
done

logger $opt -p user.warn -t "$nm" "Timeout waiting for MMC device"
return 1
}

# This early on we don't have the luxury of /dev/disk/by-label/$1
find_partition_by_label()
{
label="$1"

for diskpath in /sys/class/block/*; do
devname=$(basename "$diskpath")
[ -f "$diskpath/partition" ] && continue

disk="/dev/$devname"
result=$(sgdisk -p "$disk" 2>/dev/null | awk -v label="$label" -v devname="$devname" '
/^ *[0-9]/ {
if ($7 == label) {
if (devname ~ /^(mmcblk|nvme|loop)/) {
print devname "p" $1
} else {
print devname $1
}
exit 0
}
}
')

if [ -n "$result" ]; then
echo "$result"
return 0
fi
done
return 1
}

# Expand the given partition to fill up the rest of storage (sdcard)
resize_by_label()
{
label="$1"

devname=$(find_partition_by_label "$label")
if [ -z "$devname" ]; then
logger $opt -p user.err -t "$nm" "Label \"$label\" not found"
return 1
fi

part="/dev/$devname"
diskname=$(basename "$(readlink -f "/sys/class/block/$devname/..")")
disk="/dev/$diskname"
partnum="${devname##*[^0-9]}"

logger $opt -p user.notice -t "$nm" "Found partition $part (partition $partnum on $disk)"

start=$(sgdisk -i "$partnum" "$disk" 2>/dev/null | grep "First sector:" | awk '{print $3}')
if [ -z "$start" ]; then
logger $opt -p user.err -t "$nm" "Could not determine start sector for partition $partnum"
return 1
fi

printf "\r\033[K[ ⋯ ] Resizing /var partition on sdcard, please wait ..." > /dev/console
logger $opt -p user.notice -t "$nm" "Expanding partition $partnum from sector $start to end of disk"

if ! sgdisk -e "$disk" 2>&1 | logger $opt -p user.notice -t "$nm"; then
logger $opt -p user.warn -t "$nm" "Failed expanding GPT on $disk"
return 1
fi

if ! sgdisk -d "$partnum" "$disk" >/dev/null 2>&1; then
logger $opt -p user.warn -t "$nm" "Failed deleting partition $partnum on $disk"
return 1
fi

if ! sgdisk -n "$partnum:$start:0" "$disk" >/dev/null 2>&1; then
logger $opt -p user.warn -t "$nm" "Failed recreating partition $partnum on $disk"
return 1
fi

if ! sgdisk -t "$partnum:8300" "$disk" >/dev/null 2>&1; then
logger $opt -p user.warn -t "$nm" "Failed setting partition type on $disk"
return 1
fi

if ! sgdisk -c "$partnum:$label" "$disk" >/dev/null 2>&1; then
logger $opt -p user.warn -t "$nm" "Failed setting partition label on $disk"
return 1
fi

logger $opt -p user.notice -t "$nm" "Partition table updated on $disk"
partprobe "$disk" 2>/dev/null

logger $opt -p user.notice -t "$nm" "Resizing filesystem on $part"
if ! resize2fs "$part" 2>&1 | logger $opt -p user.notice -t "$nm"; then
logger $opt -p user.warn -t "$nm" "Failed resizing filesystem on $part"
return 1
fi

tune2fs -O resize_inode "$part" 2>/dev/null
printf "\r\033[K[ \033[32mOK\033[0m ] Resizing /var partition on sdcard, done. Rebooting ...\n" > /dev/console
logger $opt -p user.notice -t "$nm" "Partition expanded, rebooting to complete filesystem resize"

reboot -f
}

mount_rw()
{
# If something is already setup, leave it be.
mountpoint -q "/$1" && return 0

if [ "$1" = "var" ]; then
if is_rpi && [ ! -e /mnt/aux/resized ] ; then
touch /mnt/aux/resized
resize_by_label "$1"
fi
fi

# TODO: Also look for UBI partitions
mount LABEL="$1" 2>/dev/null && return 0

Expand Down Expand Up @@ -103,6 +232,15 @@ if ! logger -? |grep -q "Log to kernel"; then
opt="-c"
fi


# On Raspberry Pi, MMC controller may probe slowly, in particular if we
# netboot (ram load) the devcice wait for it
if is_rpi && ! ls /dev/mmcblk* >/dev/null 2>&1; then
wait_mmc
fi

# The aux partition must be mounted before everything else since it's used
# for internal bookkeeping.
if ! mount_rw aux >/dev/null 2>&1; then
logger $opt -p user.warn -t "$nm" \
"No auxiliary partition found, software updates not supported."
Expand Down
5 changes: 5 additions & 0 deletions doc/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ All notable changes to the project are documented in this file.
- Upgrade Linux kernel to 6.12.50 (LTS)
- Extend NETCONF and RESTCONF scripting documentation with operational
data examples, discovery patterns, and common workflow examples, issue #1156
- Initial support for a zone-based firewall, based on `firewalld`, issue #448
- Automatically expand `/var` partition on SD card at first boot on RPi

### Fixes

- Fix #1194: CLI `text-editor` command does not do proper input sanitation
- Fix #1197: RPi4 no longer boots after BPi-R3 merge, introduced in v25.09

[v25.09.0][] - 2025-09-30
-------------------------
Expand Down Expand Up @@ -1656,6 +1660,7 @@ Supported YANG models in addition to those used by sysrepo and netopeer:

[buildroot]: https://buildroot.org/
[UNRELEASED]: https://github.com/kernelkit/infix/compare/v25.09.0...HEAD
[v25.10.0]: https://github.com/kernelkit/infix/compare/v25.09.0...v26.10.0
[v25.09.0]: https://github.com/kernelkit/infix/compare/v25.08.0...v26.09.0
[v25.08.0]: https://github.com/kernelkit/infix/compare/v25.06.1...v26.08.0
[v25.06.0]: https://github.com/kernelkit/infix/compare/v25.05.1...v26.06.0
Expand Down
72 changes: 0 additions & 72 deletions doc/TODO.org

This file was deleted.

Loading
Loading