1、生成一个空的SD卡镜像
dd if=/dev/zero of=uboot.disk bs=1M count=1024
2、创建GPT分区,下面创建了两个分区,一个用来存放kernel和设备树,另一个存放根文件系统
sgdisk -n 0:0:+10M -c 0:kernel uboot.disk
sgdisk -n 0:0:0 -c 0:rootfs uboot.disk
查看分区:
$ sgdisk -p uboot.disk
Disk uboot.disk: 2097152 sectors, 1024.0 MiB
Sector size (logical): 512 bytes
Disk identifier (GUID): 04963A5B-34CF-4DEE-B610-F40257C45F6D
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2097118
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 22527 10.0 MiB 8300 kernel
2 22528 2097118 1013.0 MiB 8300 rootfs
3、寻找一个空闲的loop设备
$ losetup -f
/dev/loop16
4、将SD卡镜像映射到loop设备上
sudo losetup /dev/loop16 uboot.disk
sudo partprobe /dev/loop16
此时会看到/dev/loop16p1和/dev/loop16p2两个节点
5、格式化
sudo mkfs.ext4 /dev/loop16p1
sudo mkfs.ext4 /dev/loop16p2
如果是创建FAT32文件系统,sudo mkfs.vfat -F 32 /dev/loop16p2
6、挂载
sudo mount -t ext4 /dev/loop16p1 p1/
sudo mount -t ext4 /dev/loop16p2 p2/
7、拷贝文件
sudo cp linux-4.14.13/arch/arm/boot/zImage p1/
sudo cp linux-4.14.13/arch/arm/boot/dts/vexpress-v2*.dtb p1/
sudo cp -raf …/rootfs/rootfs/* ./p2
8、umount
sudo umount p1 p2
sudo losetup -d /dev/loop16