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.
Host Prerequisites
Section titled “Host Prerequisites”- Android Platform Tools (
fastboot>= 35.0.1) - Python 3.10+ (optional:
pip install pyyamlif provisioning from a--config node.yamlfile) zstdandtarwith--zstdsupport to unpack release archivese2fsprogs(debugfs) andandroid-sdk-libsparse-utils(simg2img,img2simg) on Linux — or inside WSL on Windows — whenever injecting pre-first-bootcloud-initconfig into a raw.ext4rootfs image
1. Download & Unpack Release Artifacts
Section titled “1. Download & Unpack Release Artifacts”Every GitHub Release publishes:
headless-phone-boot-<device>.tar.zst— matchedboot.img,vendor_boot.img,dtbo.img,boot-manifest.json,modules-*.tar.zst,kernel.config, andSOURCES-AND-LICENSES.txtuserdata-<device>.simg.zst— Zstandard-compressed Android sparse ext4 Debian 13 + Docker rootfsheadless-phone-system-<device>.tar.zst(releases built with PR #3 / post-v0.2.0) — on-device OTA system overlay bundle (used later byos-upgrade)- Combined
SHA256SUMS.txt(GitHub Actions CI artifacts instead place a separateSHA256SUMS.txtinside each artifact folder)
# Verify SHA-256 checksums of downloaded release assetssha256sum -c --ignore-missing SHA256SUMS.txt
# Extract matched boot imagesmkdir -p boot-raventar --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:
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):
# Preview firstpython tools/flash.py \ --boot-dir boot-raven \ --slot <inactive-slot> \ --userdata userdata-raven.simg \ --dry-run
# Flash and rebootpython tools/flash.py \ --boot-dir boot-raven \ --slot <inactive-slot> \ --userdata userdata-raven.simg \ --rebootDefault credentials are pixel / headless (change on first login).
Injects a pre-first-boot NoCloud seed into raw .ext4 (keeps password fallback enabled):
python tools/flash.py \ --boot-dir boot-raven \ --slot <inactive-slot> \ --userdata rootfs-raven.ext4 \ --hostname pixel-node1 \ --wifi-ssid "YourNetwork" \ --wifi-psk "YourPassphrase" \ --ssh-key ~/.ssh/id_ed25519.pub \ --rebootDisables SSH password authentication on first boot (requires at least one valid --ssh-key):
python tools/flash.py \ --boot-dir boot-raven \ --slot <inactive-slot> \ --userdata rootfs-raven.ext4 \ --hostname pixel-node1 \ --wifi-ssid "YourNetwork" \ --wifi-psk "YourPassphrase" \ --ssh-key ~/.ssh/id_ed25519.pub \ --disable-password-auth \ --rebootUse --config node.yaml for repeatable multi-node provisioning (including static IPs, custom usernames, and runcmd hooks):
python tools/flash.py \ --boot-dir boot-raven \ --slot <inactive-slot> \ --userdata rootfs-raven.ext4 \ --config node.yaml \ --rebootFlashes only the matched boot images to <inactive-slot> without modifying userdata (useful when iterating on kernels on an already-flashed Debian phone; also install the matching modules-*.tar.zst into /lib/modules/ or use os-upgrade instead):
python tools/flash.py \ --boot-dir boot-raven \ --slot <inactive-slot> \ --reboottools/flash.py Flag Reference
Section titled “tools/flash.py Flag Reference”| 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. |
Preflight & Safety Checks
Section titled “Preflight & Safety Checks”Before writing a single byte to flash, tools/flash.py enforces:
- 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). - Device & slot verification: Pins one serial, verifies
unlocked == yesandproduct == <device>, refuses--slot noneon A/B devices (requiring positive unslotted evidence), and refuses--slot a|bon non-A/B devices. - Companion partition guard: Detects existing
init_boot,vendor_boot,vendor_kernel_boot, anddtbopartitions on the device and refuses to silently skip them unless included in--boot-diror listed with--keep-stock-partition. - Partition size checks: Verifies every image fits
partition-size:<target>— for Android sparse.simgfiles (0xED26FF3A), checks the uncompressed size (blk_sz * total_blks), not compressed file size. - Safe execution order: Flashes
vbmeta, boot partitions, anduserdatafirst, then callsfastboot --set-active=<slot>only after every flash command succeeds. - Verified ext4 seed injection: Injects seed files into a temporary copy (
userdata-provisioned.ext4) viadebugfs(natively on Linux or viawslon Windows), enforcesroot:rootownership and0700/0600/0644permissions, 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:
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.9tools/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.