How to use the command 'fastboot' (with examples)

How to use the command 'fastboot' (with examples)

Fastboot is a command-line tool used mainly in Android development. It allows communication with connected Android devices, specifically when they are in the bootloader mode, which is the one place where the ‘adb’ command does not work. This article will illustrate several use cases of the ‘fastboot’ command.

Use case 1: Unlock the bootloader

Code:

fastboot oem unlock

Motivation: Unlocking the bootloader is necessary to perform various advanced tasks on an Android device, such as installing a custom recovery or custom ROMs. By default, most Android devices have their bootloaders locked to maintain the device’s integrity and security. Unlocking the bootloader is a prerequisite for modifying system files or flashing custom firmware.

Explanation: The command ‘fastboot oem unlock’ instructs the connected Android device to unlock its bootloader. This command is device-specific, and the exact syntax can vary across different devices. It is important to note that unlocking the bootloader will erase all data on the device.

Example output:

...
(bootloader) Unlocking bootloader...
OKAY [  0.383s]
Finished. Total time: 0.383s

Use case 2: Relock the bootloader

Code:

fastboot oem lock

Motivation: Relocking the bootloader is essential for restoring the device’s default state after performing modifications or flashing custom firmware. Relocking the bootloader can help prevent unauthorized access to the device’s internal system and ensure the device’s security.

Explanation: The command ‘fastboot oem lock’ instructs the connected Android device to relock its bootloader. Like the previous use case, the exact syntax can vary across different devices. Relocking the bootloader will typically erase all data on the device.

Example output:

...
(bootloader) Locking bootloader...
OKAY [  0.383s]
Finished. Total time: 0.383s

Use case 3: Reboot the device from fastboot mode into fastboot mode again

Code:

fastboot reboot bootloader

Motivation: Sometimes, when flashing custom software or performing other modifications, it may be necessary to reboot the device into fastboot mode again. This allows further interaction with the device while it is still in the bootloader mode.

Explanation: The command ‘fastboot reboot bootloader’ reboots the connected Android device from fastboot mode back into fastboot mode. This can be useful when performing a series of tasks that require repeated interactions with the bootloader.

Example output:

...
< waiting for any device >
(bootloader) Bootloader rebooting...
OKAY [  0.153s]
Finished. Total time: 0.153s

Use case 4: Flash a given image

Code:

fastboot flash file.img

Motivation: Flashing an image onto the Android device is a common process when installing custom ROMs or updating firmware. This can help personalize the device’s functionality or address potential software issues.

Explanation: The command ‘fastboot flash file.img’ allows the user to flash a given image file onto the connected Android device. The ‘file.img’ should be replaced with the actual name and path of the image file to be flashed. This command requires the user to have the appropriate image file available.

Example output:

...
target reported max download size of 471859200 bytes
sending 'file' (20480 KB)...
OKAY [  0.615s]
writing 'file'...
OKAY [  0.488s]
finished. total time: 1.103s

Use case 5: Flash a custom recovery image

Code:

fastboot flash recovery file.img

Motivation: Installing a custom recovery image allows for advanced operations like creating backups, flashing custom firmware or modifications, and performing system maintenance tasks. It provides a separate environment that can be used to perform actions that are not possible in the standard Android operating system.

Explanation: The command ‘fastboot flash recovery file.img’ flashes a custom recovery image onto the connected Android device. Similar to the previous use case, the ‘file.img’ should be replaced with the correct name and path of the recovery image file.

Example output:

...
target reported max download size of 471859200 bytes
sending 'recovery' (20480 KB)...
OKAY [  0.615s]
writing 'recovery'...
OKAY [  0.488s]
finished. total time: 1.103s

Use case 6: Display connected devices

Code:

fastboot devices

Motivation: It can be useful to check if a device is properly connected and recognized by the computer when using the ‘fastboot’ command. This command provides a list of connected devices in the bootloader mode.

Explanation: The command ‘fastboot devices’ displays a list of connected devices that are in the bootloader mode. It verifies that the computer can communicate with the devices. If no devices are listed, it indicates that there might be an issue with the connection or the device is not in the bootloader mode.

Example output:

123456789    fastboot

Use case 7: Display all information of a device

Code:

fastboot getvar all

Motivation: Obtaining detailed information about an Android device can be helpful for troubleshooting or determining specific device details required for certain operations. This command provides an overview of various variables associated with the device.

Explanation: The command ‘fastboot getvar all’ retrieves all information variables from the connected Android device. It includes variables such as the product model, bootloader version, serial number, device ID, and more.

Example output:

...
(bootloader) version: 0.5
(bootloader) version-bootloader: 1700.99
...
(bootloader) product: Pixel 3
(bootloader) secure: yes
...

Conclusion:

The ‘fastboot’ command is a powerful tool for interacting with Android devices in the bootloader mode. It provides a range of functionalities, including unlocking/relocking the bootloader, flashing images, rebooting the device, obtaining device information, etc. Understanding how to use these various commands and their arguments is crucial for developers and advanced users working with Android devices.

Related Posts

How to use the command 'rename' (with examples)

How to use the command 'rename' (with examples)

The ‘rename’ command is a useful tool for renaming multiple files in one go using Perl regular expressions.

Read More
How to use the command "msfvenom" (with examples)

How to use the command "msfvenom" (with examples)

msfvenom (with examples) The msfvenom command is a powerful tool included in the Metasploit Framework.

Read More
How to use the command ebook-convert (with examples)

How to use the command ebook-convert (with examples)

The ebook-convert command is a part of the Calibre e-book library tool and can be used to convert e-books between common formats such as PDF, EPUB, and MOBI.

Read More