Skip to content

Instantly share code, notes, and snippets.

@huyvometropolis
Last active April 28, 2026 19:15
Show Gist options
  • Select an option

  • Save huyvometropolis/38c18928df563d68e829be36be034534 to your computer and use it in GitHub Desktop.

Select an option

Save huyvometropolis/38c18928df563d68e829be36be034534 to your computer and use it in GitHub Desktop.
Update AIMobile yocto OS on the flight. It checks the active slot, picks the other partition, writes, flips the slot, and reboots — nothing else.
#!/bin/bash
set -euo pipefail
ROOTFS="${1:?Usage: $0 <rootfs.ext4>}"
[ -f "$ROOTFS" ] || { echo "Error: file not found: $ROOTFS"; exit 1; }
ACTIVE=$(/usr/sbin/nvbootctrl get-current-slot)
if [ "$ACTIVE" = "0" ]; then
INACTIVE_PART=/dev/nvme0n1p2
NEXT_SLOT=1
else
INACTIVE_PART=/dev/nvme0n1p1
NEXT_SLOT=0
fi
echo "Active slot: $ACTIVE"
echo "Writing to: $INACTIVE_PART"
dd if="$ROOTFS" of="$INACTIVE_PART" bs=4M conv=fsync status=progress
/usr/sbin/nvbootctrl set-active-boot-slot "$NEXT_SLOT"
echo "Boot slot set to: $NEXT_SLOT — rebooting"
sync && /sbin/reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment