target使用overlay实现在squashfs只读区写操作

这其实是openwrt中的一个功能,现在把它移到普通的target中
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

作者:帅得不敢出门

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

帅得不敢出门

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值