Skip to content

Offline CLI Flashing

tools/flash.py is the cross-platform Python fastboot flasher for offline installs, CI artifacts, local source builds, scripted fleet provisioning, and non-destructive RAM recovery boots.

  • Android Platform Tools (fastboot >= 35.0.1)
  • Python 3.10+ (optional: pip install pyyaml if provisioning from a --config node.yaml file)
  • zstd and tar with --zstd support to unpack release archives
  • e2fsprogs (debugfs) and android-sdk-libsparse-utils (simg2img, img2simg) on Linux — or inside WSL on Windows — whenever injecting pre-first-boot cloud-init config into a raw .ext4 rootfs image

Every GitHub Release publishes:

  • headless-phone-boot-<device>.tar.zst — matched boot.img, vendor_boot.img, dtbo.img, boot-manifest.json, modules-*.tar.zst, kernel.config, and SOURCES-AND-LICENSES.txt
  • userdata-<device>.simg.zst — Zstandard-compressed Android sparse ext4 Debian 13 + Docker rootfs
  • headless-phone-system-<device>.tar.zst (releases built with PR #3 / post-v0.2.0) — on-device OTA system overlay bundle (used later by os-upgrade)
  • Combined SHA256SUMS.txt (GitHub Actions CI artifacts instead place a separate SHA256SUMS.txt inside each artifact folder)
Terminal window
# Verify SHA-256 checksums of downloaded release assets
sha256sum -c --ignore-missing SHA256SUMS.txt
# Extract matched boot images
mkdir -p boot-raven
tar --zstd -xf headless-phone-boot-raven.tar.zst -C boot-raven/
# Decompress sparse userdata image (flashable directly for zero-config wired DHCP)
zstd -d userdata-raven.simg.zst
# Only needed when injecting flash-time cloud-init config (Options B & C below):
simg2img userdata-raven.simg rootfs-raven.ext4

(If you built locally with kernel/build.sh, initramfs/build.sh, and rootfs/build.sh, substitute out/raven/boot and out/raven/rootfs/rootfs-raven.ext4.)

2. Choose Your Inactive Slot & Flash with tools/flash.py

Section titled “2. Choose Your Inactive Slot & Flash with tools/flash.py”

Boot the phone into fastboot mode (hold Volume Down during reboot) and check which A/B slot is currently active so you flash onto the opposite (inactive) slot:

Terminal window
fastboot getvar current-slot
# If current-slot is "a", pass --slot b below.
# If current-slot is "b", pass --slot a below.

Always preview your plan with --dry-run before writing.

Plug the phone into a USB-C Ethernet adapter or PD dock after flashing. You can flash the decompressed sparse .simg directly without converting to raw .ext4 (replace <inactive-slot> with a or b from fastboot getvar current-slot):

Terminal window
# Preview first
python tools/flash.py \
--boot-dir boot-raven \
--slot <inactive-slot> \
--userdata userdata-raven.simg \
--dry-run
# Flash and reboot
python tools/flash.py \
--boot-dir boot-raven \
--slot <inactive-slot> \
--userdata userdata-raven.simg \
--reboot

Default credentials are pixel / headless (change on first login).

Flag Description
--boot-dir <PATH> (required) Directory containing boot images and optional boot-manifest.json.
--device <CODENAME> Expected fastboot product codename (defaults to boot-manifest.json’s device).
--slot {a,b,none} Target A/B slot (a/b), or none for non-A/B devices. Required unless --ram-boot is set.
--userdata <PATH> Debian rootfs image (.simg or raw .ext4). Must be raw .ext4 when passing any seed option.
--vbmeta <PATH> Stock AVB0 vbmeta.img flashed to vbmeta[_<slot>] with --disable-verity --disable-verification.
--serial <STR> Pin a specific fastboot serial (required when >1 fastboot device is connected).
--config <PATH> YAML provisioning config file (requires pyyaml). CLI seed flags override YAML keys.
--hostname, --user, --password Override hostname, admin user (default pixel), or password.
--ssh-key <STR_OR_PATH> Repeatable. SSH public key string or path to .pub file.
--disable-password-auth Set ssh_pwauth: false (hard-fails if no valid SSH key is provided).
--wifi-ssid, --wifi-psk Wi-Fi credentials for wlan0 (omit --wifi-psk for open networks).
--static-ip <CIDR>, --gateway <IP>, --dns <IP> Static IPv4 config for wired interfaces (en* and eth*); --dns is repeatable.
--keep-stock-partition <PART> Repeatable (init_boot, vendor_boot, vendor_kernel_boot, dtbo). Explicitly allow omitting an existing device boot partition.
--ram-boot Non-destructive RAM-only boot (fastboot boot boot.img). Cannot combine with --slot, --userdata, or --vbmeta.
--force-ram-boot Allow --ram-boot even when vendor_boot/vendor_kernel_boot/init_boot exist in --boot-dir.
--allow-storage-boot Allow --ram-boot with a non-shell image that may mount userdata.
--dry-run Validate all local files, binary headers, and seed config, then print fastboot commands without running them.
--reboot Run fastboot reboot after flashing and slot activation succeed.

Before writing a single byte to flash, tools/flash.py enforces:

  1. Boot-bundle integrity & binary headers: Validates boot-manifest.json (schema_version == 1, exact byte sizes, safe filenames) plus binary magic headers (ANDROID! v0–v4, VNDRBOOT, DTBO, AVB0).
  2. Device & slot verification: Pins one serial, verifies unlocked == yes and product == <device>, refuses --slot none on A/B devices (requiring positive unslotted evidence), and refuses --slot a|b on non-A/B devices.
  3. Companion partition guard: Detects existing init_boot, vendor_boot, vendor_kernel_boot, and dtbo partitions on the device and refuses to silently skip them unless included in --boot-dir or listed with --keep-stock-partition.
  4. Partition size checks: Verifies every image fits partition-size:<target> — for Android sparse .simg files (0xED26FF3A), checks the uncompressed size (blk_sz * total_blks), not compressed file size.
  5. Safe execution order: Flashes vbmeta, boot partitions, and userdata first, then calls fastboot --set-active=<slot> only after every flash command succeeds.
  6. Verified ext4 seed injection: Injects seed files into a temporary copy (userdata-provisioned.ext4) via debugfs (natively on Linux or via wsl on Windows), enforces root:root ownership and 0700/0600/0644 permissions, and verifies byte-for-byte read-back before converting to sparse (img2simg) and flashing.

Standalone Seed Generation (tools/mkconfig.py)

Section titled “Standalone Seed Generation (tools/mkconfig.py)”

Generate NoCloud seed files (meta-data, user-data, and optional network-config) without flashing:

Terminal window
python tools/mkconfig.py \
--out ./seed-out \
--hostname pixel-lab \
--user ops \
--ssh-key ~/.ssh/id_ed25519.pub \
--disable-password-auth \
--wifi-ssid "LabWiFi" \
--wifi-psk "SuperSecretPassphrase" \
--static-ip 192.168.10.50/24 \
--gateway 192.168.10.1 \
--dns 1.1.1.1 \
--dns 9.9.9.9

tools/mkconfig.py also accepts --instance-id <STR> (auto-generated as headless-<sha256[:8]>-<uuid4[:6]> when omitted) and --config node.yaml. See First Boot, Cloud-Init & Recovery for the complete YAML schema.