Skip to content

First Boot, Cloud-Init & Recovery

On first boot, headless-phone turns a generic, secret-free Debian rootfs into a unique host with its own identity, SSH keys, networking, and full-disk root partition — completely offline.

  1. Stage 1 Initramfs (initramfs/init)

    Loads SoC, UFS storage, USB-C/TCPCI, thermal, and hardware watchdog (s3c2410_wdt) modules, resolves PARTNAME=userdata via /sys/class/block/*/uevent, performs a non-destructive read-only probe (mount -t ext4 -o ro,noload) checking for /sbin/init, then mounts read-write and executes switch_root.

  2. Read-Only /vendor Mount (mount-vendor.service)

    Runs before sysinit.target and cloud-init-local.service. Parses the device’s super partition LP metadata with SHA-256 verification, exposes vendor as read-only /dev/mapper/headless-vendor mounted at /vendor, and loads vendor firmware kernel modules (e.g., Wi-Fi bcmdhd4389) so wlan0 is ready before networking starts.

  3. Local cloud-init Provisioning (cloud-init-lite)

    Configured via /etc/cloud/cloud.cfg.d/90-headless-nocloud.cfg (datasource_list: [ NoCloud, None ]) so it never stalls waiting for cloud metadata endpoints. Reads /var/lib/cloud/seed/nocloud/ if injected at flash time, applying hostname, user accounts, SSH keys, ssh_pwauth, Netplan Wi-Fi/static IP config, and runcmd.

  4. Idempotent First-Boot Identity & Resize (firstboot-setup)

    Runs before systemd-networkd, ssh.service, and avahi-daemon:

    • Online ext4 resize: Expands / via resize2fs to fill the entire userdata partition (stamps /var/lib/headless-phone/resize-done only on success so failures retry cleanly).
    • Unique fallback hostname: If /etc/hostname is empty or headless-phone (i.e. not overridden by cloud-init), sets <codename>-<last-6-of-serial> (e.g. raven-a1b2c3), updates /etc/hosts, and stamps /var/lib/headless-phone/hostname-done.
    • Unique SSH host keys: Generates fresh /etc/ssh/ssh_host_*_key files via ssh-keygen -A (base image ships with zero host keys and an empty /etc/machine-id).
  5. Networking, Power & Slot-Success Confirmation

    • systemd-networkd brings up wired Ethernet (fallback /etc/systemd/network/90-wired-dhcp.network, overridden by Netplan 10-netplan-* when seeded) and Wi-Fi.
    • [email protected] shuts off the OLED CRTC via DRM KMS as soon as /dev/dri/card* appears.
    • charge-limit.service caps battery charge at 55%–70% and brownout-guard.service starts monitoring battery/charger health.
    • Once ssh.service and a carrier-up global IP uplink are confirmed, mark-boot-ok.service marks the A/B slot successful (on verified, allowlisted bootloaders).
Terminal window
# Seeded install (custom hostname)
# Unseeded install (auto-generated from codename + last 6 chars of serial)
  • Default credentials (when unseeded): user pixel, password headless (passwordless sudo enabled via /etc/sudoers.d/90-headless-phone; root login is locked and PermitRootLogin no is enforced).
  • Wired Ethernet: Plug into any USB-C Gigabit Ethernet adapter or USB-C PD dock (r8152, r8153_ecm, cdc_ncm, cdc_ether are preloaded via /etc/modules-load.d/headless-phone.conf).

Whenever the phone is plugged directly into a PC (USB-C Device / UFP role), usb-role.service binds a Linux configfs CDC ACM serial gadget (0525:a4a7) and spawns [email protected].

  • Linux: /dev/ttyACM0 — e.g. screen /dev/ttyACM0 115200 or picocom -b 115200 /dev/ttyACM0
  • macOS: /dev/cu.usbmodem*
  • Windows: Standard COM port using inbox usbser.sys (no driver install needed; connect with PuTTY, Tera Term, or Windows Terminal + plink)

Use this offline console anytime to check IP addresses, fix Wi-Fi credentials, or inspect journalctl.

Complete YAML Provisioning Schema (--config node.yaml)

Section titled “Complete YAML Provisioning Schema (--config node.yaml)”

Both tools/flash.py --config and tools/mkconfig.py --config accept a YAML mapping with the following fields:

node.yaml
hostname: pixel-node1
user: ops # Default: pixel. Non-pixel locks the factory pixel account.
# password: "initial-password" # Optional cleartext chpasswd override
ssh_authorized_keys:
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI... daniel@workstation"
disable_password_auth: true # Requires >= 1 valid SSH key; sets ssh_pwauth: false
instance_id: pixel-node1-v1 # Optional explicit NoCloud instance-id
# Optional Wi-Fi (wlan0, DHCPv4, optional: true)
wifi_ssid: "MyHomeWiFi"
wifi_psk: "MyWifiPassphrase" # Omit for open networks
# Optional static IPv4 for wired Ethernet (matches both en* and eth*)
static_ip: "192.168.1.50/24"
gateway: "192.168.1.1"
dns:
- "1.1.1.1"
- "9.9.9.9"
# Optional extra first-boot commands (YAML-only; runs after adding user to docker group)
runcmd:
- "timedatectl set-timezone Australia/Perth"
- "apt-get update && apt-get install -y tmux jq"
  1. Fastboot Recovery: Hold Volume Down while rebooting to enter fastboot. From there you can switch to the opposite A/B boot slot (fastboot --set-active=<a|b>) or re-flash a boot image set. Note that userdata is shared across slots — switching back to a stock Android boot slot only restores Android’s boot chain; booting stock Android again requires wiping/restoring userdata with a factory image.
  2. Stage 1 Initramfs USB Shell (headless.shell=1): If userdata fails to mount, lacks /sbin/init, or the boot image was built with SHELL_MODE=1, Stage 1 initramfs automatically brings up the 0525:a4a7 CDC ACM gadget (product="headless-initramfs-serial") and drops into an interactive BusyBox recovery shell (headless-initramfs# ) on /dev/ttyGS0 (115200 8N1). On Pixel 6 / 6 Pro (split Header v4 boot + vendor_boot), flash the matched SHELL_MODE=1 recovery boot set to an A/B slot without --userdata (python tools/flash.py --boot-dir <dir> --slot <a|b> --reboot, adding --vbmeta path/to/stock-vbmeta.img if AVB verification is still enabled on that slot — see Offline CLI Flashing). On devices with self-contained non-split recovery images (Header v2), you can RAM-boot non-destructively with python tools/flash.py --boot-dir <dir> --ram-boot.
  3. Automatic Rollback: If a newly flashed kernel fails to reach SSH + network uplink, mark-boot-ok.service never marks the slot successful, and ABL automatically falls back after retry count exhaustion. See Firmware, Watchdog & A/B Safety.