Last active
January 23, 2026 04:28
-
-
Save raghavauppuluri13/1b9cd1149132f6eff0d6296cee4ab5b7 to your computer and use it in GitHub Desktop.
Flash Jetpack 6.2 on jetson orin nano
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
| #!/usr/bin/env bash | |
| # Flash Jetson Orin Nano JP 6.2 (L4T r36.4.3) image to an auto-detected SD card. | |
| # No prompts except a single safety confirmation (skip with -y). | |
| set -euo pipefail | |
| URL="https://developer.nvidia.com/downloads/embedded/l4t/r36_release_v4.3/jp62-orin-nano-sd-card-image.zip" | |
| MIN=$((4*1024*1024*1024)) # require >= 4GB | |
| YES=0; [[ "${1:-}" == "-y" ]] && YES=1 | |
| die(){ echo "ERR: $*" >&2; exit 1; } | |
| human(){ local b=$1 u=(B KB MB GB TB) i=0; while (( b>=1024 && i<4 )); do b=$((b/1024)); ((i++)); done; echo "${b}${u[$i]}"; } | |
| need(){ command -v "$1" >/dev/null 2>&1 || die "missing dependency: $1"; } | |
| OS=$(uname -s) | |
| need unzip; need dd | |
| DL=""; command -v curl >/dev/null && DL="curl -fL" || command -v wget >/dev/null && DL="wget -O-" | |
| [[ -n "$DL" ]] || die "need curl or wget" | |
| # ---------- autodiscover target disk (largest removable/USB/SD/Thunderbolt >= 4GB) ---------- | |
| dev=""; bytes=0 | |
| if [[ $OS == "Linux" ]]; then | |
| # Removable block devices via sysfs; robust and dependency-light. | |
| best=0; bestdev="" | |
| for b in /sys/block/*; do | |
| [[ -r "$b/removable" && $(<"$b/removable") == 1 ]] || continue | |
| d="/dev/$(basename "$b")"; [[ -b "$d" ]] || continue | |
| sz=$(( $(<"$b/size") * 512 )) | |
| (( sz >= MIN )) || continue | |
| (( sz > best )) && { best=$sz; bestdev="$d"; } | |
| done | |
| [[ -n "$bestdev" ]] || die "no removable disk >=4GB found" | |
| dev="$bestdev"; bytes=$best | |
| elif [[ $OS == "Darwin" ]]; then | |
| need diskutil | |
| best=0; bestdev="" | |
| # Consider ALL whole disks, then filter by attributes (handles built-in SD slots & older macOS). | |
| while read -r d; do | |
| # whole disk only | |
| [[ "$(diskutil info "$d" | awk -F': *' '/^ *Whole:/{print $2; exit}')" == "Yes" ]] || continue | |
| # skip internal boot disk | |
| [[ "$d" == "/dev/disk0" ]] && continue | |
| info="$(diskutil info "$d")" | |
| proto="$(awk -F': *' '/^ *Protocol:/{print $2; exit}' <<<"$info")" | |
| removable="$(awk -F': *' '/^ *Removable Media:/{print $2; exit}' <<<"$info")" | |
| # accept if USB/SD/Thunderbolt OR removable | |
| case "$proto" in USB*|SD*|Thunderbolt*) ok=1 ;; *) [[ "$removable" =~ Yes|Removable ]] && ok=1 || ok=0 ;; esac | |
| (( ok==1 )) || continue | |
| sz="$(awk -F': *' '/^ *Disk Size:/{gsub(/[^0-9]/,"",$2); print $2; exit}' <<<"$info")" | |
| [[ -n "$sz" ]] || continue | |
| (( sz >= MIN )) || continue | |
| (( sz > best )) && { best=$sz; bestdev="$d"; } | |
| done < <(diskutil list | awk '/^\/dev\/disk[0-9]+/ {print $1}') | |
| [[ -n "$bestdev" ]] || die "no external/removable disk >=4GB found" | |
| dev="$bestdev"; bytes=$best | |
| else | |
| die "unsupported OS: $OS" | |
| fi | |
| raw="$dev"; [[ $OS == "Darwin" ]] && raw="${dev/\/dev\/disk/\/dev\/rdisk}" | |
| echo "Target: $dev ($(human "$bytes"))" | |
| if (( YES==0 )); then | |
| read -r -p "Erase and flash this device? [y/N] " a | |
| [[ "$a" == "y" || "$a" == "Y" ]] || die "aborted" | |
| fi | |
| # ---------- unmount ---------- | |
| if [[ $OS == "Linux" ]]; then | |
| for p in "${dev}"?*; do [[ -e "$p" ]] && umount -f "$p" 2>/dev/null || true; done | |
| else | |
| diskutil unmountDisk "$dev" || true | |
| fi | |
| sync | |
| # ---------- download -> flash ---------- | |
| TMP=$(mktemp -d); trap 'rm -rf "$TMP"' EXIT | |
| ZIP="$TMP/image.zip" | |
| echo "Downloading image..." | |
| $DL "$URL" > "$ZIP" || die "download failed (if NVIDIA requires login, download in a browser and place the ZIP at $ZIP)" | |
| IMG=$(unzip -Z1 "$ZIP" | grep -E '\.img(\.raw)?$' | head -n1 || true) | |
| [[ -n "$IMG" ]] || IMG=$(unzip -Z1 "$ZIP" | head -n1) | |
| [[ -n "$IMG" ]] || die "could not find image inside zip" | |
| echo "Flashing to $raw ..." | |
| if [[ $OS == "Linux" ]]; then | |
| unzip -p "$ZIP" "$IMG" | dd of="$raw" bs=4M status=progress oflag=direct || die "dd failed" | |
| else | |
| unzip -p "$ZIP" "$IMG" | dd of="$raw" bs=4m || die "dd failed" | |
| fi | |
| sync | |
| [[ $OS == "Darwin" ]] && diskutil eject "$dev" || true | |
| echo "Done." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment