创建TF卡镜像

如果您没有部署本地TFTP服务器,则您可以使用TF卡进行数据传输。
重要: 该操作将覆盖目标TF卡上的所有现有数据。

TF卡的默认大小为16 GB,建议使用TF卡的GPT分区表。

按照以下步骤,创建TF卡镜像:

  1. 执行以下命令,生成sdcard.img文件。

    $ make -j$(nproc)
    $ make buildroot_rootfs -j$(nproc)
    $ make img
    
    结果:

    将生成输出文件work/sdcard.img

    提示: 您可通过以下方式之一将镜像文件烧录到TF卡上:
    • 执行dd命令:

      $ sudo dd if=work/sdcard.img of=/dev/sdX bs=4096
      $ sync
    • 或使用rpi-imagerbalenaEtcher工具。
  2. (可选)如有需要,可执行以下方法扩展分区:
    • 方法1:在Ubuntu主机上:
      1. 输入以下命令,安装软件包:
        $ sudo apt install cloud-guest-utils e2fsprogs
      2. 在Ubuntu主机上插入一张TF卡。
      3. 执行以下命令扩展分区。
        注: /dev/sdX是TF卡设备名,可根据实际情况更改该变量。
        $ sudo growpart /dev/sdX 4  # extend partition 4
        $ sudo e2fsck -f /dev/sdX4
        $ sudo resize2fs /dev/sdX4  # extend filesystem
        $ sudo fsck.ext4 /dev/sdX4
        
    • 方法2:在昉·惊鸿-7110 DevKit开发板上运行fdiskresize2fs命令:
      # fdisk /dev/mmcblk1
      Welcome to fdisk (util-linux 2.37.2).
      Changes will remain in memory only, until you decide to write them.
      Be careful before using the write command.
      This disk is currently in use - repartitioning is probably a bad idea.
      It's recommended to umount all file systems, and swapoff all swap
      partitions on this disk.
      Command (m for help): d
      Partition number (1-4, default 4): 4
      Partition 4 has been deleted.
      Command (m for help): n
      Partition number (4-128, default 4): 4
      First sector (614400-62333918, default 614400): 
      ): t sector, +/-sectors or +/-size{K,M,G,T,P} (614400-62333918, default 62333918)
      Created a new partition 4 of type 'Linux filesystem' and of size 29.4 GiB.
      Partition #4 contains a ext4 signature.
      Do you want to remove the signature? [Y]es/[N]o: N
      Command (m for help): w
      The partition table has been altered.
      Syncing disks.
      
      # resize2fs /dev/mmcblk1p4
      resize2fs 1.46.4 (18-Aug-2021)
      Filesystem at /d[
      111.756178] EXT4-fs (mmcblk1p4): resizing filesystem from 512000
      to 30859756 blocks
      ev/mmcblk1p4 is [
      111.765203] EXT4-fs (mmcblk1p4): resizing filesystem from 512000
      to 30859265 blocks
      mounted on /; on-line resizing required
      old_desc_blocks = 2, new_desc_blocks = 118
      [ 112.141953] random: crng init done
      [ 112.145369] random: 7 urandom warning(s) missed due to ratelimiting
      [ 115.474184] EXT4-fs (mmcblk1p4): resized filesystem to 30859265
      The filesystem on /dev/mmcblk1p4 is now 30859756 (1k) blocks long.
      
      如果您需要新增一个分区,例如swap分区(我们将剩余的磁盘空间设置为swap分区,但一般来说,swap分区的大小应该与DDR大小相同或是DDR大小的两倍),在镜像运行后,您可以运行以下shell脚本:
      #!bin/sh
      sgdisk -e /dev/mmcblk0
      disk=/dev/mmcblk0
      gdisk $disk << EOF
      p
      n
      5
      
      
      8200
      p
      c
      5
      hibernation
      w
      y
      EOF
      
      mkswap /dev/mmcblk0p5
      swapoff -a
      swapon /dev/mmcblk0p5