树莓派笔记--制作安装映像
查看映像分区信息:
# fdisk -l 2020-06-21-raspios-4.19.img
Disk 2020-06-21-raspios-4.19.img: 3.6 GiB, 3829399552 bytes, 7479296 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9fb1957f
Device Boot Start End Sectors Size Id Type
2020-06-21-raspios-4.19.img1 8192 532479 524288 256M c W95 FAT32 (LBA)
2020-06-21-raspios-4.19.img2 532480 7479295 6946816 3.3G 83 Linux
Units:指明sectors单位(目前一般都为512字节)
Start: 分区起始地址(单位由Units说明)
End : 分区结束位置
Size : 分区大小
Type : 分区类型
挂载第1个分区
# mount 2020-06-21-raspios-4.19.img /mnt/boot -t vfat -o rw,loop,offset=4194304,sizelimit=45297664
挂载第2个分区
# mount 2020-06-21-raspios-4.19.img /mnt/rootfs/ -t ext4 -o rw,loop,offset=$((532480*512))
offset: 分区起始偏移位置,单位字节(重要,需要在位置读取分区信息),4194304 = 8192*512,可以用单位M来表示。
也可以采用乘法表达式来表述(shell规则需要加$(())),比较直观。
sizelimit:分区容量,单位字节(可省略,系统貌似会自动计算)
rw: 可读写
loop:环回设备(可省略)
查看挂载状态
$ df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/loop0 253M 51M 202M 21% /mnt/boot
/dev/loop1 3.2G 2.7G 358M 89% /mnt/rootfs
挂载完成就可以直接进行修改镜像内容了,将编译好的内核、模块、设备树文件分别替换原来的文件就可以了。
挂载脚本:
#/bin/sh
IMG_FILE=raspios.img
# Initialization
action=$1
[ -z $1 ] && action=-a
case "${action}" in
-a | mount)
echo mount ${IMG_FILE}
sudo mount ${IMG_FILE} /mnt/boot -t vfat -o rw,loop,offset=$((8192*512))
sudo mount ${IMG_FILE} /mnt/rootfs -t ext4 -o rw,loop,offset=$((532480*512))
;;
-r | umount)
echo umount ${IMG_FILE}
sudo umount /mnt/boot
sudo umount /mnt/rootfs
;;
*)
;;
esac
增加磁盘镜像:
# dd if=/dev/zero of=raspios-hndfsj.img bs=1M count=0 seek=8000
seek指明写入的偏移位置,单位为bs指定的值;
count=0,实际上不复制数据,seek为置就为磁盘大小,否则会在seek位置再添加数据。
减小磁盘镜像:
先用分区工具无损修改分区大小,再用dd命令复制指定大小的数据至新的镜像文件中。
取消开机提示pi用户密码未修改:
删除文件:/etc/xdg/autostart/pprompt.desktop