Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release thay vì aosp-main để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trang này cung cấp thông tin chi tiết về cách cài đặt ROM Android trên thiết bị bằng các công cụ fastboot và adb. Adb cho phép bạn kết nối máy trạm phát triển trực tiếp với thiết bị chạy Android và thực hiện nhiều thao tác. Tính năng khởi động nhanh cho phép bạn cài đặt (đổ ROM) Android và tương tác với trình tải khởi động của thiết bị để bạn có thể kiểm thử các thay đổi đối với hệ điều hành và ứng dụng. Để biết thêm thông tin về cách hoạt động của adb, tập trung vào việc phát triển ứng dụng, hãy xem trang Android Debug Bridge (adb) của Android Studio.
Nếu bạn muốn biết thông tin chi tiết về mã cho adb, hãy xem README của adb.
Xác minh rằng bạn có fastboot và adb
Khi bạn tạo Android, adb và fastboot sẽ được tạo theo mặc định. Để xác nhận khả năng sử dụng adb và fastboot, hãy chạy các lệnh sau:
adb--versionfastboot--version
Nếu thấy số phiên bản, tức là bạn đã cài đặt fastboot và adb. Nếu bạn không thấy số phiên bản, hãy đảm bảo bạn đã tạo Android thành công. Tiếp tục Bật kết nối USB.
Bật kết nối USB
Trước khi chạy Android trên một thiết bị, bạn phải bật kết nối USB:
Bật tính năng mở khoá OEM và gỡ lỗi qua USB trong tuỳ chọn cho nhà phát triển:
Trong ứng dụng Cài đặt, hãy nhấn vào Giới thiệu về điện thoại.
Nhấn vào Số bản dựng 7 lần.
Khi bạn thấy thông báo Bạn đã là nhà phát triển!, hãy nhấn vào <-.
Nhấn vào Hệ thống, rồi nhấn vào Tuỳ chọn cho nhà phát triển.
Bật tính năng mở khoá OEM và gỡ lỗi qua USB. Nếu không thể mở khoá OEM, hãy kết nối với Internet để thiết bị có thể đăng ký. Nếu cách đó vẫn không hiệu quả, bạn có thể buộc kiểm tra bằng cách: Trong ứng dụng Điện thoại, hãy nhập *#*#CHECKIN#*#* (*#*#2432546#*#*) (không cần SIM). Sau khi nhập số (không cần nhấn nút gọi), văn bản sẽ biến mất và thông báo thành công sẽ xuất hiện.
Nếu bạn vẫn không thể mở khoá bằng OEM, thì có thể nhà mạng của bạn đã khoá SIM trên thiết bị và bạn không thể mở khoá trình tải khởi động.
Kết nối thiết bị với cổng USB trên máy trạm.
Khởi động vào chế độ khởi động nhanh
Trước khi có thể cài đặt ROM Android cho một thiết bị, thiết bị đó phải ở chế độ Khởi động nhanh.
Có hai cách để khởi động thiết bị vào chế độ Khởi động nhanh:
Sử dụng lệnh adb: Trên dòng lệnh, hãy nhập adb reboot bootloader.
Sử dụng tổ hợp phím:
Xác định tổ hợp phím cho thiết bị của bạn. Để biết bảng tổ hợp phím khởi động nhanh, hãy xem phần Tổ hợp phím khởi động nhanh.
Tắt thiết bị.
Bật thiết bị và ngay lập tức giữ tổ hợp phím cho thiết bị (được xác định ở bước 1).
Mở khoá trình tải khởi động
Sau khi khởi động vào chế độ khởi động nhanh, bạn phải mở khoá trình tải khởi động.
Cách mở khoá trình tải khởi động:
(Không bắt buộc) Sao lưu mọi tệp quan trọng trên thiết bị.
Chạy lệnh mở khoá cho thiết bị:
Nếu bạn đang cập nhật một thiết bị Nexus hoặc Pixel được sản xuất từ năm 2015 trở lên, hãy chạy fastboot flashing unlock.
Đối với Pixel 2: Để cài đặt ROM cho trình tải khởi động, hãy xác minh rằng trình tải khởi động của Pixel 2 đã được cập nhật lên ít nhất là phiên bản Oreo MR1. Để cập nhật Pixel 2 lên phiên bản này, hãy áp dụng bản cập nhật qua mạng không dây (OTA) hoặc tải OTA đầy đủ xuống thiết bị.
Chỉ dành cho Pixel 2 XL có phiên bản trình tải trước TMZ20a: Bạn có thể cần phải mở khoá các phân vùng quan trọng trước khi cài đặt ROM. Để chỉ mở khoá các phân vùng quan trọng trên Pixel 2 XL, hãy chạy fastboot flashing unlock_critical.
Nếu bạn đang mở khoá một thiết bị trước năm 2015, hãy chạy fastboot oem unlock.
Thiết bị mục tiêu sẽ hiển thị màn hình xác nhận.
Xác nhận rằng bạn muốn xoá tất cả dữ liệu người dùng và mở khoá thiết bị.
Truyền nhanh thiết bị
Bạn có thể cài đặt ROM cho toàn bộ hệ thống Android chỉ bằng một lệnh. Việc cài đặt ROM cho toàn bộ hệ thống bằng một lệnh duy nhất sẽ xác minh rằng hệ thống đang được cài đặt ROM tương thích với trình tải khởi động và đài đã cài đặt, ghi các phân vùng khởi động, khôi phục và hệ thống cùng nhau, đồng thời khởi động lại hệ thống.
Cách cài đặt ROM cho thiết bị:
Đặt thiết bị ở chế độ khởi động nhanh bằng cách giữ tổ hợp phím thích hợp khi khởi động hoặc sử dụng lệnh sau:
adbrebootbootloader
Sau khi thiết bị ở chế độ khởi động nhanh, hãy chạy:
fastbootflashall-w
Tuỳ chọn -w sẽ xoá sạch phân vùng /data trên thiết bị. Tuỳ chọn này sẽ hữu ích khi bạn cài đặt ROM cho một thiết bị cụ thể lần đầu tiên.
Khoá lại trình tải khởi động
Cách khoá lại trình tải khởi động:
Đối với các thiết bị từ năm 2015 trở lên, hãy chạy lệnh fastboot flashing lock
Đối với các thiết bị từ năm 2014 trở về trước, hãy chạy lệnh fastboot oem lock
Khôi phục thiết bị về trạng thái ban đầu
Bạn có thể tải hình ảnh gốc cho thiết bị Google từ trang Hình ảnh gốc cho thiết bị Nexus và Pixel.
Hình ảnh gốc cho Motorola Xoom do Motorola trực tiếp phân phối.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Flash with Fastboot\n\nThis page provides details for flashing Android builds onto devices using the\n*fastboot* and *adb* tools. Adb lets you connect your\ndevelopment workstation directly to your Android-powered device and\nperform a variety of operations. Fastboot lets you install (flash) Android\nand interact with the device's bootloader so you can test your OS and app\nchanges. For additional information on how adb works, with emphasis on app\ndevelopment, see\n[Android Studio's Android Debug Bridge (adb) page](https://developer.android.com/studio/command-line/adb).\nIf you want details on the code for adb, see the adb\n[README](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/adb/README.md).\n| **Note:** Google provides an additional flash tool, called [*Android Flash Tool*](/docs/setup/test/flash), that is intended for use only with prebuilt builds.\n| **Note:** Fastboot is also the name of a bootloader module and mode.\n\nVerify that you have fastboot and adb\n-------------------------------------\n\nWhen you build Android, adb and fastboot is built by default. To confirm\nthe availability of adb and fastboot, run the following commands: \n\n adb --version\n fastboot --version\n\nIf you see version numbers, you have fastboot and adb installed. If you\ndon't see version numbers, ensure you\n[built Android](/docs/setup/build/building).\nsuccessfully. Continue to\n[Enable your USB connection](#enable-usb).\n\nEnable your USB connection\n--------------------------\n\nBefore running Android on a device, you must enable your USB connection:\n\n1. Enable OEM unlocking and USB debugging in the developer options:\n\n 1. In the Settings app, tap **About phone**.\n 2. Tap **Build number** seven times.\n 3. When you see the message **You are now a developer!** , tap **\\\u003c-**.\n 4. Tap **System** , then tap **Developer options**.\n 5. Enable **OEM unlocking** and **USB debugging** . If OEM unlocking is unavailable, connect to the internet so the device can check in. If that still doesn't work, you can force a check in: In the Dialer app, enter **\\*#\\*#CHECKIN#\\*#\\*** (\\*#\\*#2432546#\\*#\\*) (no SIM required). After entering the number (no need to press call), the text disappears and a success notification appears.\n\n If OEM unlocking remains unavailable, your device might be SIM locked by\n your carrier and the bootloader can't be unlocked.\n2. Connect your device to a USB port on your workstation.\n\nBoot into Fastboot mode\n-----------------------\n\nBefore Android can be flashed to a device, a device must be in Fastboot mode.\nThere are two ways to boot a device into Fastboot mode:\n\n- Use the `adb` command: From the command-line, type `adb reboot bootloader`.\n- Use a key combination:\n 1. Determine the key combination for your device. For a table of Fastboot key combinations, see [Fastboot key combinations](/docs/setup/reference/fastboot-keys).\n 2. Turn the device off.\n 3. Turn the device on and immediately hold down the key combination for your device (determined in step 1).\n\nUnlock the bootloader\n---------------------\n\nAfter booting into fastboot mode, you must unlock the bootloader.\n| **Warning:** For privacy reasons, unlocking the bootloader deletes user data. After unlocking, all data on the device is erased, including both private app data and shared data accessible over USB (including photos and movies).\n\nTo unlock the bootloader:\n\n1. (Optional) Back up any important files on the device.\n2. Run the unlock command for your device:\n\n - If you're updating a Nexus or Pixel device that is manufactured in 2015 or later, run `fastboot flashing unlock`.\n - For Pixel 2: To flash the bootloader, verify that the Pixel 2's bootloader is updated to at least Oreo MR1's version. To update to a Pixel 2 to this version, apply the over-the-air (OTA) update or sideload a [full OTA](https://developers.google.com/android/ota).\n - For Pixel 2 XL only with loader version prior to TMZ20a: The critical partitions might need to be unlocked before flashing. To unlock the critical partitions on Pixel 2 XL only, run `fastboot flashing unlock_critical`.\n - If you're unlocking a pre-2015 device, run `fastboot oem unlock`.\n\n The target device displays a confirmation screen.\n3. Confirm that you want to erase all user data and unlock the device.\n\n | **Tip:** If your device is shown in the output before reboot, but Fastboot or the flash script are misbehaving, it might be an issue with your USB cable. Try a different port or switching connectors. For example, if you're using a USB C port on your workstation try a USB A port instead.\n\n| **Note:** On Nexus 10, after unlocking the bootloader, the internal storage remains unformatted. You can format the device using `fastboot format cache` followed by `fastboot format userdata`.\n\nFlash a device\n--------------\n\nYou can flash an entire Android system in a single command. Flashing an entire\nsystem with a single command verifies that the system being flashed is\ncompatible with the installed bootloader and radio, writes the boot, recovery,\nand system partitions together, and reboots the system.\n\nTo flash a device:\n\n1. Place the device in fastboot mode by holding the appropriate\n key combination at boot or using the following command:\n\n adb reboot bootloader\n\n2. After the device is in fastboot mode, run:\n\n fastboot flashall -w\n\nThe `-w` option wipes the `/data` partition on the device, which is useful\nfor your first time flashing a particular device.\n| **Note:** File systems created with `fastboot` on Motorola Xoom don't function optimally. Google recommends that you recreate file systems through recovery using `adb reboot recovery`. While in recovery, open the menu (press **Power + Volume Up**), wipe the cache partition, then wipe the data.\n\n### Re-locking the bootloader\n\nTo re-lock the bootloader:\n\n- For 2015 or later devices, run the command `fastboot flashing lock`\n- For 2014 or earlier devices, run the command `fastboot oem lock`\n\nRestore device to factory state\n-------------------------------\n\nFactory images for Google devices are available from\n[Factory Images for Nexus and Pixel Devices](https://developers.google.com/android/nexus/images).\nFactory images for the Motorola Xoom are distributed directly by Motorola."]]