This document walks through how to build and flash a Fuchsia image
on a hardware device using `fx` commands.

> [!NOTE]
> **Note:** For more information on these commands, run `fx help <COMMAND>`.

## Identify USB drive device path

Before you can build and flash Fuchsia on a target device, you first
need to identify the path of your USB drive.

It is recommended to run the command below once with the USB drive
disconnected, then run it again with the USB drive connected to see
the difference.

### fx tool

To check the correct path to your USB drive using the `fx` tool,
run the following command:

    fx mkzedboot

The `fx` tool is platform agnostic and lists available USB drives.

### Linux command

To check the correct path to your USB drive using a Linux command,
run the following command:

    sudo fdisk -l

Drives are usually in the form `/dev/sd*` such as `/dev/sdc`. Make sure
that you select the drive rather than a specific partition. Forexample,
a specific partition has a number at the end of the path such as
`/dev/sdc1`.

## Build and flash Fuchsia

To perform an initial build and flash of a Fuchsia image using the `fx`
tool, do the following:

1. Set your Fuchsia build configuration:

       fx set core.x64

   This configures the build to build the `core` product on a generic x64
   board. For a list of available products and boards, see `fx list-products`
   and `fx list-boards` for lists of available products, respectively.
2. Build a Fuchsia image:

       fx build

   This command builds Zircon and then the rest of Fuchsia.
3. Build the Zedboot media and install to a USB device target:

       fx mkzedboot <usb_drive_device_path>

   For information on obtaining the USB drive device path, see
   [USB drive device path](https://fuchsia.dev/fuchsia-src/development/build/build_and_flash_fuchsia#usb-drive-device-path).
4. Attach Zedboot USB drive to your target device and reboot that device.

5. On your target device, run:

       install-disk-image init-partition-tables

6. From your host, start the bootserver:

       fx flash

   The bootserver connects to the target device to upload the Fuchsia
   image and then flashes your target device.

## Rebuild and reflash Fuchsia

To re-deploy Fuchsia using the `fx` tool, do the following:

1. Ensure that HEAD is in a good state to pull at the [build dashboard](https://luci-milo.appspot.com/p/fuchsia).
2. Fetch the latest code:

       jiri update

3. Build a Fuchsia image:

       fx build

   This command builds Zircon and then the rest of Fuchsia.
4. From your host, start a development package server:

       fx serve

5. Boot your target device without the Zedboot USB attached.

6. From your host, push updated Fuchsia packages to the target device:

       fx ota

   In some cases, if `fx ota` does not complete successfully, consider repaving
   with `fx flash`.

## Troubleshooting

If `fx build` fails, make sure that your `PATH` environment variable is set
correctly.

To check the value of your `PATH` variable:

    echo $PATH

Make that sure that the output of your `PATH` variable is a list of
directories separated by colons. Make sure that none of the directories are
separated by a dot (`.`).

> [!NOTE]
> **Note:** The `fx` script changes the working directory in a way that may create conflicts between the commands it uses (such as `touch`) and the binaries in the working directory.

[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/development/build/build_and_flash_fuchsia.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/development/build/build_and_flash_fuchsia.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/development/build/build_and_flash_fuchsia.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/development/build/build_and_flash_fuchsia.md "Edit the source code of this page")