By: fu linux
E-mail: fulinux@sina.com
Blog: https://blog.csdn.net/fulinus
喜欢的盆友欢迎点赞和订阅!
你的喜欢就是我写作的动力!
创建Read-Only Root文件系统
假设出于安全原因,需要禁用目标设备的根文件系统的写权限(即需要一个只读的根文件系统)。
或者可能正在从只读存储设备运行设备的操作系统。
无论哪种情况,都可以为该行为自定义image。
注意:此时根目录系统下绝大部分的目录都是不能写操作的,但是像/tmp、/var等目录下是可以创建临时文件的,因为这些目录下的文件系统是在内存中创建的虚拟文件系统,系统结束时,里面的任何内容都失效了。
有两种方法创建只读根文件系统
方法一
一种方法是在image的recipe中使用IMAGE_FEATURE变量中添加"read-only-rootfs"属性,知道是什么文件吗?
参考如下:
poky]$ cd meta
meta]$ find -iname core-image-sato*
./recipes-sato/images/core-image-sato-sdk.bb
./recipes-sato/images/core-image-sato.bb
./recipes-sato/images/core-image-sato-sdk-ptest.bb
./recipes-sato/images/core-image-sato-ptest-fast.bb
./recipes-sato/images/core-image-sato-dev.bb
- 1
- 2
- 3
- 4
- 5
- 6
- 7
找到./recipes-sato/images/core-image-sato.bb文件,在文件的末尾加上:
meta]$ vim recipes-sato/images/core-image-sato.bb
...
IMAGE_FEATURES += "read-only-rootfs"
- 1
- 2
- 3
方法二
在local.conf文件中添加EXTRA_IMAGE_FEATURES变量,参考如下:
poky]$ vim build/conf/local.conf
...
EXTRA_IMAGE_FEATURES = "read-only-rootfs"
- 1
- 2
- 3
结尾处添加。
修改完成后重新source,再编译。
运行效果
root@qemux86-64:~# mount
/dev/root on / type ext4 (ro,relatime) #提示根文件系统为只读
devtmpfs on /dev type devtmpfs (rw,relatime,size=244932k,nr_inodes=61233,mode=755)
proc on /proc type proc (rw,relatime)
tmpfs on /mnt/.psplash type tmpfs (rw,relatime,size=40k)
sysfs on /sys type sysfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /var/volatile type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /var/lib type tmpfs (rw,relatime)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
root@qemux86-64:~# ls
root@qemux86-64:~# touch xxx
touch: xxx: Read-only file system #提示为只读文件系统
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15