While ADB is used to communicate with Android after the operating system has fully booted, Fastboot is used to communicate with the device before the OS loads.
Fastboot is both a diagnostic protocol and a command-line tool. It is baked directly into the device's bootloader, allowing you to modify the flash memory partitions even if the main Android operating system is completely destroyed or caught in an endless boot loop.
Bootloader Unlocking
Before you can flash a custom compiled version of AOSP onto a commercial device (like a Google Pixel), you must unlock the bootloader. Manufacturers lock bootloaders to prevent malicious software from overwriting the operating system.
To unlock a device:
- Enable "OEM Unlocking" in the hidden Developer Options menu in Android.
- Reboot the device into the bootloader menu (usually by holding Power + Volume Down).
- Connect the USB cable and run the unlock command from your Ubuntu host.
# For modern devices (Pixel 2 and newer)
fastboot flashing unlock
# For older legacy devices
fastboot oem unlock
Note: Unlocking the bootloader will instantly trigger a secure wipe of the /data partition to prevent attackers from stealing user data.
Flashing Partitions
Once unlocked, Fastboot allows you to write specific binary image files directly to the physical storage partitions. When you compile AOSP, the output directory generates several .img files (like boot.img, system.img, and vendor.img).
Essential Flashing Commands
fastboot flash boot boot.img: Writes the newly compiled Linux kernel to thebootpartition.fastboot flash system system.img: Writes the core Android framework to thesystempartition.fastboot flashall: A powerful automated command. If you run this from your AOSP build directory, Fastboot will automatically discover every compiled image and flash them to the correct partitions in the correct order.
# Typical workflow to flash a completely custom ROM
fastboot flashall -w
(The -w flag wipes the userdata partition, ensuring a clean slate).
Fastbootd (Userspace Fastboot)
Historically, Fastboot was handled entirely by the low-level bootloader. However, with the introduction of Dynamic Partitions in Android 10, the rigid physical partitions (like /system and /vendor) were consolidated into a single "super" partition.
The primitive bootloader does not understand the complex logical structure of a dynamic super partition. To solve this, Google introduced fastbootd (Userspace Fastboot).
- When you flash the kernel (
boot.img), you are talking to the standard bootloader Fastboot. - When you flash the framework (
system.img), the device boots into a specialized, minimal Linux environment called "fastbootd", which has the intelligence required to resize and flash logical partitions.
# Force the device to transition from bootloader fastboot into userspace fastbootd
fastboot reboot fastboot