target文件系统是squashfs,它是只读的,每升级一个文件都得整个区擦除然后重新写,很麻烦,使用overlayfs可以使只读区中单个文件进行替换修改,很方便。
根目录是squashfs只读的挂载设备是/dev/mtdblock2,其上有/overlay /rootdir文件夹, 分配出一个jffs2分区mtdblock3来做为可写区, 内核中使能overlay文件系统,
在init中实现overlay挂载
- #!/bin/sh
- init_sys()
- {
- mount -t proc proc /proc
- mount -t sysfs sysfs /sys
- mount -n -t jffs2 /dev/mtdblock3 /overlay
- mount -n -t overlayfs overlayfs -o lowerdir=/,upperdir=/overlay /rootdir
- mount -n /proc -o noatime,--move /rootdir/proc
- mount -n /dev -o noatime,--move /rootdir/dev
- mount -n /tmp -o noatime,--move /rootdir/tmp
- mount -n /sys -o noatime,--move /rootdir/sys
- mount -n /rootdir/overlay -o noatime,--move /overlay
- }
- fini_system()
- {
- umount /proc
- umount /sys
- umount /dev
- }
- boot()
- {
- fini_system
- if [ -x /sbin/init ]; then
- exec chroot /rootdir /sbin/init
- fi
- }
- start_shell()
- {
- /sbin/getty -L ttyS1 115200 vt100 -n -l /bin/ash
- }
- init_sys
- bootm=1
- times=0
- # read -n1 -t2 bootm
- case $bootm in
- 1)
- # echo "Boot the normal pid: $$...."
- boot
- ;;
- 9)
- # echo "Start the shell pid: $$...."
- start_shell
- ;;
- *)
- boot
- ;;
- esac