创建img镜像模板

概览:

生成rpi64-v0.1.img

注意:count=200,即镜像大小为200M(太小的话,在f2fs文件系统下储存不下内核。),如若需要可以弄大一点儿(2048,4096等)。

1
2
3
mkdir image
cd image
dd bs=1M count=200 if=/dev/zero of=rpi64-v0.1.img

镜像分区

1
cfdisk rpi64-v0.1.img

(1).选择分区格式:dos
(2).新建分区30M,primary(主分区),选择Bootable(可启动),再选则Type为(b W95 FAT32),
(3).选择剩余分区(Free space)
(4).选择新建分区(默认剩余全部),primary(主分区)
(5).选择Write写入分区信息
(6).选择Quit,完成写入

格式化

挂载虚拟文件系统

1
sudo kpartx -av rpi64-v0.1.img

标准输出:

1
2
add map loop0p1 (253:0): 0 61440 linear 7:0 2048
add map loop0p2 (253:1): 0 346112 linear 7:0 63488

** 然后格式化**

格式化第一个分区为FAT32,格式化第二个分区为f2fs

1
2
sudo mkfs.vfat  /dev/mapper/loop0p1
sudo mkfs.f2fs /dev/mapper/loop0p2

标准输出:

  • fat
1
mkfs.fat 4.1 (2017-01-24)
  • f2fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

F2FS-tools: mkfs.f2fs Ver: 1.11.0 (2018-07-10)

Info: Disable heap-based policy
Info: Debug level = 0
Info: Label =
Info: Trim is enabled
Info: Segments per section = 1
Info: Sections per zone = 1
Info: sector size = 512
Info: total sectors = 346112 (169 MB)
Info: zone aligned segment0 blkaddr: 512
Info: format version with
"Linux version 4.15.0-54-generic (buildd@lgw01-amd64-014) (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) #58-Ubuntu SMP Mon Jun 24 10:55:24 UTC 2019"
Info: [/dev/mapper/loop0p2] Discarding device
Info: This device doesn't support BLKSECDISCARD
Info: Discarded 169 MB
Info: Overprovision ratio = 15.000%
Info: Overprovision segments = 29 (GC reserved = 21)
Info: format successful

卸载虚拟文件系统

1
2
3
sync   # 同步写入
sudo kpartx -dv /dev/loop0
sudo losetup -d /dev/loop0

检验

------ 文章已经结束,谢谢你的阅读 ------
------ article has ended,thank you for reading ------
Thanks support Me

---------------- The End ----------------