-
Notifications
You must be signed in to change notification settings - Fork 1
expand-rootfs #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mihai-chiorean
merged 3 commits into
edgeengineer:main
from
StefanaHanc:feature/expand-rootfs
Oct 7, 2025
Merged
expand-rootfs #40
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
meta-edgeos/recipes-support/expand-rootfs/expand-rootfs.bb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| SUMMARY = "First-boot rootfs auto-expansion service" | ||
| DESCRIPTION = "Expands the active root partition and grows the filesystem on first boot." | ||
| LICENSE = "CLOSED" | ||
|
|
||
| PR = "r4" | ||
|
|
||
|
|
||
| SRC_URI = " \ | ||
| file://expand-rootfs.sh \ | ||
| file://expand-rootfs.service \ | ||
| " | ||
|
|
||
| S = "${WORKDIR}" | ||
|
|
||
| inherit systemd | ||
|
|
||
| do_install() { | ||
| install -d ${D}/usr/local/sbin | ||
| install -m 0755 ${WORKDIR}/expand-rootfs.sh ${D}/usr/local/sbin/expand-rootfs.sh | ||
|
|
||
| install -d ${D}${systemd_unitdir}/system | ||
| install -m 0644 ${WORKDIR}/expand-rootfs.service ${D}${systemd_unitdir}/system/expand-rootfs.service | ||
| } | ||
|
|
||
| FILES:${PN} += " \ | ||
| /usr/local/sbin/expand-rootfs.sh \ | ||
| ${systemd_unitdir}/system/expand-rootfs.service \ | ||
| " | ||
|
|
||
| SYSTEMD_SERVICE:${PN} = "expand-rootfs.service" | ||
| SYSTEMD_AUTO_ENABLE = "enable" | ||
|
|
||
| RDEPENDS:${PN} = "bash coreutils util-linux parted e2fsprogs-resize2fs udev gptfdisk" | ||
|
|
17 changes: 17 additions & 0 deletions
17
meta-edgeos/recipes-support/expand-rootfs/files/expand-rootfs.service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [Unit] | ||
| Description=Expand root partition and filesystem (first boot) | ||
| DefaultDependencies=no | ||
| After=local-fs.target systemd-udev-settle.service | ||
| Wants=systemd-udev-settle.service | ||
| ConditionPathExists=!/var/lib/expand-rootfs.done | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/usr/local/sbin/expand-rootfs.sh | ||
| RemainAfterExit=no | ||
| TimeoutSec=0 | ||
| StandardOutput=journal+console | ||
| StandardError=journal+console | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target |
69 changes: 69 additions & 0 deletions
69
meta-edgeos/recipes-support/expand-rootfs/files/expand-rootfs.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| STAMP="/var/lib/expand-rootfs.done" | ||
| LOG="/var/log/expand-rootfs.log" | ||
|
|
||
| # Redirect all output to log file and console | ||
| exec > >(tee -a "$LOG") 2>&1 || true | ||
| echo "[expand-rootfs] Start $(date -Is || true)" | ||
|
|
||
| # Run only once | ||
| if [[ -f "$STAMP" ]]; then | ||
| echo "[expand-rootfs] Stamp file exists; exiting." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Detect root device and filesystem type | ||
| ROOTDEV="$(findmnt -n -o SOURCE /)" | ||
| FSTYPE="$(findmnt -n -o FSTYPE /)" | ||
|
|
||
| if [[ "$ROOTDEV" != /dev/* ]]; then | ||
| echo "[expand-rootfs] Root device is not a physical partition ($ROOTDEV) -> skip." | ||
| mkdir -p "$(dirname "$STAMP")"; touch "$STAMP"; exit 0 | ||
| fi | ||
|
|
||
| # Use sysfs to find partition number and parent disk (portable) | ||
| PART_BASENAME="$(basename "$ROOTDEV")" # e.g. mmcblk0p2 | ||
| PARTNUM="$(cat "/sys/class/block/${PART_BASENAME}/partition")" | ||
| PARENT_SYS="$(readlink -f "/sys/class/block/${PART_BASENAME}/..")" | ||
| DISK="/dev/$(basename "$PARENT_SYS")" # e.g. /dev/mmcblk0 | ||
| echo "[expand-rootfs] RootDEV=$ROOTDEV Disk=$DISK Part=$PARTNUM FS=$FSTYPE" | ||
|
|
||
| # Skip if an A/B rootfs layout is detected (e.g. mender) | ||
| if lsblk -rno PARTLABEL "$DISK" 2>/dev/null | grep -qiE 'root[a-b]'; then | ||
| echo "[expand-rootfs] Detected A/B rootfs layout -> skip." | ||
| mkdir -p "$(dirname "$STAMP")"; touch "$STAMP"; exit 0 | ||
| fi | ||
|
|
||
| # GPT backup header when image is flashed to a larger card | ||
| if command -v sgdisk >/dev/null 2>&1; then | ||
| echo "[expand-rootfs] sgdisk -e $DISK (fix GPT backup at end)" | ||
| sgdisk -e "$DISK" || true | ||
| command -v partprobe >/dev/null 2>&1 && partprobe "$DISK" || true | ||
| udevadm settle || true | ||
| fi | ||
|
|
||
| #Resize root partition to fill the entire disk | ||
| if command -v growpart >/dev/null 2>&1; then | ||
| echo "[expand-rootfs] growpart $DISK $PARTNUM" | ||
| growpart "$DISK" "$PARTNUM" || true | ||
| else | ||
| echo "[expand-rootfs] parted -s $DISK unit % resizepart $PARTNUM 100%" | ||
| parted -s "$DISK" unit % resizepart "$PARTNUM" 100% || true | ||
| fi | ||
|
|
||
| command -v partprobe >/dev/null 2>&1 && partprobe "$DISK" || true | ||
| udevadm settle || true | ||
|
|
||
| #Resize filesystem | ||
| case "$FSTYPE" in | ||
| ext4|ext3|ext2) resize2fs "$ROOTDEV" ;; | ||
| xfs) xfs_growfs / ;; | ||
| btrfs) btrfs filesystem resize max / ;; | ||
| *) echo "[expand-rootfs] Unknown filesystem type: $FSTYPE -> skipping resize." ;; | ||
| esac | ||
|
|
||
| echo "[expand-rootfs] OK" | ||
| mkdir -p "$(dirname "$STAMP")" | ||
| touch "$STAMP" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part will be interesting. we do want to get to an A/B setup, but at that point I think we'll have a separate partition for data so updates to the os don't wipe everything out.