> ## 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 卡挂载到特定路径。

<Note>
  所有 Qualcomm SoC UFS 设备组件均已针对首选供应商列表（PVL）进行验证。请从 [内存列表](https://www.qualcomm.com/products/internet-of-things/industrial/building-enterprise/qcs6490/peripherals) 中选择适用的器件。
</Note>

## 挂载文件系统

EXT4 是一种开源文件系统，用于 Qualcomm Linux 上的数据分区。EXT4 文件系统可支持大小高达 64 ZB 的卷，在标准 4 kB 块大小下可支持大小高达 16 TB 的单个文件。有关 EXT4 的更多信息，请参见 [https://opensource.com/article/17/5/introduction-ext4-filesystem。](https://opensource.com/article/17/5/introduction-ext4-filesystem。)

extent 是一段连续物理块的范围，可提升大文件性能并减少碎片化。在 4 kB 块大小下，EXT4 中单个 extent 最多可映射 128 MiB 的连续空间。EXT4 不限制单个目录中的子目录数量，仅受目录本身固有大小限制的约束。

例如：

```bash theme={null}
/dev/sda3 on /usr type ext4 (ro,relatime,inlinecrypt)
```

1. 将 `/dev/sda3` 挂载到 `/data`。

   ```bash theme={null}
   mkdir /tmp/data
   ```

   ```bash theme={null}
   mount -o rw,remount /
   ```

   ```bash theme={null}
   mount -t ext4 /dev/sda3 /tmp/data
   ```

2. 验证 `/dev/sda3` 分区是否已挂载。

   ```bash theme={null}
   df -ah
   ```

   输出：

   ```
   ...
   Filesystem     Size    Used  Avail  Use%  Mounted on

   /dev/sda3      108.2G  3.7G  99.9G  4%    /tmp/data
   ```

3. 使用特定的 SELinux 上下文选项挂载文件系统。

   ```bash theme={null}
   mount -o rootcontext=system_u:object_r:etc_t:s0 -t ext4 /dev/sda3 /home/root/data
   ```

<Note>
  运行 `mount` 命令以获取与 `/dev/sda3` 相关的确切 `rootcontext=<>` 值。
</Note>

## 将 SD 卡挂载到特定路径

SD 卡在插入时会自动挂载。要手动挂载 SD 卡，请运行以下命令：

1. 将根分区重新挂载为可读写。

   ```bash theme={null}
   mount -o rw,remount /
   ```

2. 创建 SD 卡目录。

   ```bash theme={null}
   mkdir sdcard
   ```

3. 找到 SD 卡目录的默认路径。

   ```bash theme={null}
   root@qcs6490-rb3gen2-vision-kit:~# pwd
   ```

   输出：

   ```
   / (<-- default path)
   ```

4. 如果 SD 卡未格式化为 VFAT，请使用以下命令进行格式化。

   ```bash theme={null}
   mkfs.vfat /dev/mmcblk1p1
   ```

5. 将 SD 卡挂载到默认路径（`/sdcard`）。

   ```bash theme={null}
   mount -t vfat /dev/mmcblk1p1 /<default_path>/sdcard
   ```

   <Note>
     如果 SD 卡有多个分区，请重复步骤 4 挂载每个分区。
   </Note>

6. 验证 SD 卡是否已挂载。

   ```bash theme={null}
   df -a
   ```

   输出：

   ```
   ...
   Filesystem      Size    Used  Avail  Use%  Mounted on
   /dev/mmcblk1p1  511.0M  4.0K  511.0M  0%   /sdcard
   ```

## 挂载 NVMe 卡

要使用 `fdisk` 格式化并挂载新的或现有的 NVMe 卡，请执行以下操作：

1. 运行以下命令创建分区表。

   ```bash theme={null}
   fdisk /dev/nvme0n1
   ```

   输出：

   ```
   Command (m for help): i
   No partition is defined yet!
   Command (m for help): n
   Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
   Select (default p):  (press enter)
   Using default response p.
   Partition number (1-4, default 1):  (press enter)
   First sector (2048-1953525167, default 2048):  (press enter)
   Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1953525167, default 1953525167):
   Created a new partition 1 of type 'Linux' and of size 931.5 GiB.
   Command (m for help): w
   The partition table has been altered.
   Syncing disks.
   root@lemans:~#
   ```

2. 重启开发板。

   <Note>
     `mkfs.ext4` 二进制文件位于 `/usr/sbin/mkfs.ext4`。
   </Note>

3. 格式化 `/dev/nvme0n1p1` 分区。

   ```bash theme={null}
   mkfs.ext4 /dev/nvme0n1p1
   ```

   输出：

   ```
   mke2fs 1.46.5 (30-Dec-2021)
   Discarding device blocks: done
   Creating filesystem with 244190390 4k blocks and 61054976 inodes
   Filesystem UUID: 94ca7f8e-eb27-45ce-84f6-67f0cf977ca8
   Superblock backups stored on blocks:
   32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
   4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
   102400000, 214990848
   Allocating group tables: done
   Writing inode tables: done
   Creating journal (262144 blocks): done
   Writing superblocks and filesystem accounting information: done
   ```

4. 将 NVMe partition1 挂载到 media 文件夹。

   ```bash theme={null}
   mount /dev/nvme0n1p1 /media
   ```

5. 验证 `nvme0n1p1` 分区是否已挂载。

   ```bash theme={null}
   df -a
   ```

   输出：

   ```
   ...
   Filesystem      Size  Used  Avail  Use%  Mounted on
   /dev/nvme0n1p1  458G   28K  435G   1%    /var/rootdirs/media
   ```
