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

3140阅读 0评论2018-12-10 帅得不敢出门
分类:嵌入式

这其实是openwrt中的一个功能,现在把它移到普通的target中
target文件系统是squashfs,它是只读的,每升级一个文件都得整个区擦除然后重新写,很麻烦,使用overlayfs可以使只读区中单个文件进行替换修改,很方便。
根目录是squashfs只读的挂载设备是/dev/mtdblock2,其上有/overlay /rootdir文件夹, 分配出一个jffs2分区mtdblock3来做为可写区, 内核中使能overlay文件系统,
在init中实现overlay挂载

  1. #!/bin/sh
  2. init_sys()
  3. {
  4. mount -t proc proc /proc
  5. mount -t sysfs sysfs /sys
  6. mount -n -t jffs2 /dev/mtdblock3 /overlay
  7. mount -n -t overlayfs overlayfs -o lowerdir=/,upperdir=/overlay /rootdir
  8. mount -n /proc -o noatime,--move /rootdir/proc
  9. mount -n /dev -o noatime,--move /rootdir/dev
  10. mount -n /tmp -o noatime,--move /rootdir/tmp
  11. mount -n /sys -o noatime,--move /rootdir/sys
  12. mount -n /rootdir/overlay -o noatime,--move /overlay
  13. }
  14. fini_system()
  15. {
  16. umount /proc
  17. umount /sys
  18. umount /dev
  19. }
  20. boot()
  21. {
  22. fini_system
  23. if [ -x /sbin/init ]; then
  24. exec chroot /rootdir /sbin/init
  25. fi
  26. }
  27. start_shell()
  28. {
  29. /sbin/getty -L ttyS1 115200 vt100 -n -l /bin/ash
  30. }
  31. init_sys
  32. bootm=1
  33. times=0
  34. # read -n1 -t2 bootm
  35. case $bootm in
  36. 1)
  37. # echo "Boot the normal pid: $$...."
  38. boot
  39. ;;
  40. 9)
  41. # echo "Start the shell pid: $$...."
  42. start_shell
  43. ;;
  44. *)
  45. boot
  46. ;;
  47. esac
作者:帅得不敢出门


上一篇:qt调zint把文本转化成条码并显示
下一篇:ubuntu新开机启动方法