> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 从 SD 卡启动 Linux 操作系统

您可以从 SD 卡启动 Qualcomm 开发套件。

1. 通过将 `efi.bin` 和 `rootfs.img` 烧录到 SD 卡来准备 SD 卡。
2. 将准备好的 SD 卡插入开发套件的 SD 卡插槽。

开发套件从 SD 卡启动，该 SD 卡包含备份或冗余操作系统，以确保持续运行。

## 支持的平台

| **平台** | **机器配置**           | **开发套件**                                         |
| ------ | ------------------ | ------------------------------------------------ |
| Kodiak | `rb3gen2-core-kit` | Qualcomm Dragonwing™ RB3 Gen 2 Core Kit（QCS6490） |
| Lemans | `iq-9075-evk`      | Qualcomm Dragonwing™ IQ-9075 EVK（QCS9075）        |
| Monaco | `iq-8275-evk`      | Qualcomm Dragonwing™ IQ-8275 EVK（QCS8275）        |
| Talos  | `iq-615-evk`       | Qualcomm QCS615 ADP Air EVK（QCS615）              |

要准备可启动的 SD 卡，请执行以下操作：

**前提条件**

使用 Linux 桌面系统执行步骤 1 到 5，准备可启动的 SD 卡。

**步骤**

1. 在任意 Linux 系统上确认所插入 SD 卡的设备节点，例如 `/dev/mmcblk1` 或 `/dev/mmcblk2`。
2. 要格式化 SD 卡，请在 Linux 终端上运行 `mkfs.ext4 <sdcard slot>` 命令。
   在以下示例中，SD 卡的设备节点为 `/dev/mmcblk1`。
   ```text theme={null}
   mkfs.ext4 /dev/mmcblk1
   ```
   输出：
   ```text theme={null}
   mke2fs 1.46.5 (30-Dec-2021)
   Found a dos partition table in /dev/mmcblk1
   Proceed anyway? (y,N) y
   Discarding device blocks: done
   Creating filesystem with 3889536 4k blocks and 972944 inodes
   Filesystem UUID: 069e04f8-0b72-4a94-aa93-f5ec03bea38d
   Superblock backups stored on blocks:
      32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
   Allocating group tables: done
   Writing inode tables: done
   Creating journal (16384 blocks): done
   Writing superblocks and filesystem accounting information: done
   ```
3. 使用 `fdisk` 命令在 SD 卡上创建两个分区，用于复制 `efi.bin` 和 `rootfs.img`。
   1. 创建第一个分区（`vfat` 文件系统）用于复制 `efi.bin`。
      要创建分区，请运行以下命令（例如，设备节点为 `/dev/mmcblk1`）：在此示例中，将 `First sector` 字段留空，并确保 `Last sector` 足够大以容纳 `efi.bin`。
      ```text theme={null}
      fdisk /dev/mmcblk1
      ```
      输出：
      ```text theme={null}
      Welcome to fdisk (util-linux 2.37.4).
      Changes will remain in memory only, until you decide to write them.
      Be careful before using the write command.
      The device contains 'ext4' signature and it will be removed by a write command.
      See fdisk(8) man page and --wipe option for more details.
      Device doesn't contain a recognized partition table.
      Created a new DOS disklabel with disk identifier 0xa5fa6b03.
      Command (m for help): n
      Partition type
         p   primary (0 primary, 0 extended, 4 free)
         e   extended (container for logical partitions)
      Select (default p): p
      Partition number (1-4, default 1): 1
      First sector (2048-31116287, default 2048):
      Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-31116287, default 31116287): +512M
      Created a new partition 1 of type 'Linux' and of size 512 MiB.
      Command (m for help): w
      The partition table has been altered.
      Calling ioctl() to re-read partition table.
      Syncing disks.
      ```
      要将该分区转换为 `vfat` 文件系统，请运行以下命令：
      ```text theme={null}
      mkfs.vfat /dev/mmcblk1p1
      ```
      输出：
      ```text theme={null}
      mkfs.fat 4.2 (2021-01-31)
      ```
   2. 按如下方式创建第二个分区（`ext4` 文件系统）用于复制 `rootfs.img`：
      要创建分区，请运行以下命令（例如，设备节点为 `/dev/mmcblk1`）：在此示例中，将 `First sector` 字段留空，并确保 `Last sector` 足够大以容纳 `rootfs.img`。
      ```text theme={null}
      fdisk /dev/mmcblk1
      ```
      输出：
      ```text theme={null}
      Welcome to fdisk (util-linux 2.37.4).
      Changes will remain in memory only, until you decide to write them.
      Be careful before using the write command.
      Command (m for help): n
      Partition type
         p   primary (1 primary, 0 extended, 3 free)
         e   extended (container for logical partitions)
      Select (default p): p
      Partition number (2-4, default 2): 2
      First sector (1050624-31116287, default 1050624):
      Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-31116287, default 31116287): +10G
      Created a new partition 2 of type 'Linux' and of size 10 GiB.
      Command (m for help): w
      The partition table has been altered.
      Calling ioctl() to re-read partition table.
      Syncing disks.
      ```
      要将该分区转换为 `ext4` 文件系统，请运行以下命令：
      ```text theme={null}
      mkfs.ext4 /dev/mmcblk1p2
      ```
      输出：
      ```text theme={null}
      mke2fs 1.46.5 (30-Dec-2021)
      Discarding device blocks: done
      Creating filesystem with 2621440 4k blocks and 655360 inodes
      Filesystem UUID: 9e470d01-77fe-4382-a273-ab8b022bdd8b
      Superblock backups stored on blocks:
               32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
      Allocating group tables: done
      Writing inode tables: done
      Creating journal (16384 blocks): done
      Writing superblocks and filesystem accounting information: done
      ```
4. 验证分区是否已创建：
   ```text theme={null}
   lsblk -f /dev/mmcblk1
   ```
   输出：
   ```text theme={null}
   NAME FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
   mmcblk1
   |
   |-mmcblk1p1
   |    vfat               1EAC-8FF8
   `-mmcblk1p2
        ext4               9e470d01-77fe-4382-a273-ab8b022bdd8b
   ```
5. 将主机上成功构建的 Qualcomm Linux 镜像中的 `efi.bin` 和 `rootfs.img` 复制到 SD 卡上的分区中。在主机上运行以下命令：
   * `dd if=<path>/efi.bin of=<sdcard slot> bs=4M`
   * `dd if=<path>/rootfs.img of=<sdcard slot> bs=4M`
     要从 `/tmp` 路径复制这两个镜像，以下是将它们复制到 SD 卡的示例：在此命令中，SD 卡的设备节点为 `/dev/mmcblk1`。
   ```text theme={null}
   dd if=/tmp/efi.bin of=/dev/mmcblk1p1 bs=4M
   dd if=/tmp/rootfs.img of=/dev/mmcblk1p2 bs=4M
   ```

**结果**

SD 卡现已准备就绪，可用作 Qualcomm Linux 开发套件的启动介质。插入 SD 卡后，仅当开发套件上的主闪存存储（UFS 或 eMMC）无法启动时，SD 卡才会用作备用启动介质。

## 模拟无法启动的状态

要验证 SD 卡是否用作备用启动介质，您可以通过擦除主闪存存储（UFS 或 eMMC）的 EFI 分区，强制其进入无法启动的状态。在插入 SD 卡之前，当开发套件仍从主存储运行时，在开发套件上执行以下步骤：

1. 通过 UART 控制台或 SSH 登录开发套件。
2. 确认 EFI 分区已作为 `/dev/disk/by-partlabel/efi` 公开。此分区名称来自您所在平台的 `partitions.conf` 文件中的 `--name=efi` 条目。有关更多信息，请参阅[在 Qualcomm Linux 中管理分区](./manage-partitions-in-qualcomm-linux)。
   ```text theme={null}
   ls -l /dev/disk/by-partlabel/efi
   ```
3. 通过写入零来擦除 EFI 分区：
   ```text theme={null}
   dd if=/dev/zero of=/dev/disk/by-partlabel/efi bs=4M
   ```
4. 将准备好的 SD 卡插入 SD 卡插槽并重启开发套件。由于主存储上的 EFI 分区现已被擦除，引导加载程序会回退到从 SD 卡启动。

<Note>
  擦除 EFI 分区会使主存储无法启动，直到重新烧录 EFI 分区。要恢复原始启动配置，请按照[烧录预构建镜像](./flash-prebuilt-images)中的步骤重新烧录设备，或重新构建并重新烧录 `efi.bin` 镜像。
</Note>
