当前位置:网站首页>UBI read only file system
UBI read only file system
2022-07-28 03:55:00 【toradexsh】
By Toradex Hu Shanfeng
In the previous article, we have introduced the use of eMMC File system with read-only attribute configured on the module of , And the use of squashfs and overlayfs Mount writable partition .Toradex In addition to using eMMC Out of storage , The other part is to adopt Nand Flash, for example Colibri iMX7 and Colibri iMX6ULL. The following will be Colibri iMX7 As an example, this paper introduces how to configure a file system with read-only attribute .
Due to different storage media ,Nand Flash Generally, such as jffs2、UBI Equal format file system .Toradex Of Linux System use UBI file system .
stay Colibri iMX7 Of Nand Flash The following plan will be adopted .Nand Flash In general, it is divided into two parts . The front of raw Part does not use any file system , Direct storage module hardware information bcb,u-boot and u-boot environment variable . The second part uses UBI, establish 5 individual volume, Used to store kernel files (kernel)、 Device tree file (dtb)、M4 The firmware of (m4-fw)、Linux file system (rootfs)、 User files (userdata). among rootfs Set to self reading property , and userdata You can write data .

Toradex Easy Installer Can pass image.json File easily modify partition , Thus avoiding the use of command tools . First download from here for Colibri iMX7S Of Linux BSP v5.x The installation files . After decompression image.json Add userdata Related configuration of .
-----------------------------------
{
"name": "rootfs",
"content": {
"filesystem_type": "ubifs",
"filename": "Reference-Minimal-Image-colibri-imx7.tar.xz",
"uncompressed_size": 108.1171875
},
"size_kib": 102400
},
{
"name": "userdata",
"content": {
"filesystem_type": "ubifs",
"filename": "app.tar.xz",
"uncompressed_size": 0.1171875
}
}
-----------------------------------
here name Appoint ubi volume Name ,filesystem_type Is used to specify the ubifs File format ,filename It includes the need to burn to userdata volume The file of , These are user applications and configurations ,uncompressed_size Refer to app.tar.xz Uncompressed size , Used for display Toradex Easy Installer Installation progress bar . More about image.json Please refer to here .
Use Toradex Easy Installer Burn the image modified above to Colibri iMX7S that will do . Start and enter u-boot, Use the following name to see the created volume.
-----------------------------------
Colibri iMX7 # ubi part ubi
Colibri iMX7 # ubi info layout
Volume information dump:
vol_id 0
......
name kernel
Volume information dump:
vol_id 1
......
skip_check 0
name dtb
Volume information dump:
vol_id 2
......
skip_check 0
name m4firmware
Volume information dump:
vol_id 3
......
skip_check 0
name rootfs
Volume information dump:
vol_id 4
......
skip_check 0
name userdata
-----------------------------------
Activate access Linux after ,userdata It will not be automatically mounted , You need to add the following to /etc/fstab In file . Now? rootfs The root directory has not been set as read-only , You can create /home/root/userdata The directory is used to mount userdata volume .
-----------------------------------
ubi:userdata /home/root/userdata ubifs defaults,noatime,rw 1 1
-----------------------------------
At the same time , You can also configure the system . For example, add a startup application . The application write_to_file When running, it will go /home/root/userdata Write a file . stay /etc/systemd/system/ Create under directory user-demo.service.
user-demo.service
-----------------------------------
[Unit]
Description=launch user's demo on dedicated partition
ConditionFileIsExecutable=/home/root/userdata/write_to_file
After=multi-user.target
[Service]
WorkingDirectory=/home/root/userdata
Type=simple
ExecStart=/home/root/userdata/write_to_file
[Install]
WantedBy=multi-user.target
-----------------------------------
Run the following command to make user-demo.service Boot operation . Then restart the system .
-----------------------------------
~# systemctl enable user-demo.service
~# reboot
-----------------------------------
here , Use mount Command to view the mounted volume , Among them is ubi:userdata.
-----------------------------------
~# mount -l
tmpfs on /var/volatile type tmpfs (rw,relatime)
ubi:userdata on /home/root/userdata type ubifs (rw,noatime,assert=read-only,ubi=0,vol=4)
-----------------------------------
stay /home/root/userdata You can also see write_to_file Written file file.txt.
-----------------------------------
~/userdata# ls
file.txt write_to_file
~/userdata# cat file.txt
This is a writing file test
~/userdata# systemctl status user-demo.service
* user-demo.service - launch user's demo on dedicated partition
Loaded: loaded (/etc/systemd/system/user-demo.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Wed 2022-07-06 06:09:44 UTC; 14min ago
Process: 316 ExecStart=/home/root/userdata/write_to_file (code=exited, status=0/SUCCESS)
Main PID: 316 (code=exited, status=0/SUCCESS)
Jul 06 06:09:44 colibri-imx7-02873356 systemd[1]: Started launch user's demo on dedicated partition.
Jul 06 06:09:44 colibri-imx7-02873356 systemd[1]: user-demo.service: Succeeded.
-----------------------------------
Finally, it needs to be modified again /etc/fstab take rootfs The root directory is set to read-only property ,noatime Add later ro.
-----------------------------------
/dev/root / auto noatime,ro 1 1
-----------------------------------
Restart the system , Get into u-boot Command mode , Configure lower parameters .
-----------------------------------
setenv ubiargs "ubi.mtd=ubi root=ubi0:rootfs ro rootfstype=ubifs ubi.fm_autoconvert=1"
saveenv
reset
-----------------------------------
Restart access Linux System . root directory / It is already read-only , Unable to create file . and /home/root/userdata Applications under the directory can still execute normally and write files .
-----------------------------------
:~# mount -l
ubi0:rootfs on / type ubifs (ro,noatime,assert=read-only,ubi=0,vol=3)
~# mkdir test
mkdir: can't create directory 'test': Read-only file system
-----------------------------------
summary
By way of Linux The system file of is set to read-only , It can reduce the probability of failure to start due to file system corruption . For more demanding applications , You can even use external storage as a backup , For restoring files .
边栏推荐
- Move notice!
- [force deduction] 1337. Row K with the weakest combat effectiveness in the matrix
- Advanced Mathematics (Seventh Edition) Tongji University exercises 3-5 personal solutions
- C语言:不创建临时变量实现两数交换
- 高等数学(第七版)同济大学 习题3-6 个人解答
- 数据挖掘-02
- 常用的弱网测试工具
- Protocols in swift
- Prefix-Tuning: Optimizing Continuous Prompts for Generation
- Istio's Traffic Management API
猜你喜欢

ES6 from getting started to mastering 08: extended object functions

一个仿win10蓝屏的404页面源码

test case management tool

In depth introduction to sap ui5 fileuploader control - why do you need a hidden iframe trial

From Clickhouse to Snowflake: MPP query layer

Data mining-01

Simple and easy-to-use performance testing tools recommended

numeric_ Limits the range and related attributes of each data type learned

LeetCode 0141. 环形链表 - 三种方法解决

Tungsten Fabric SDN — BGP as a Service
随机推荐
Web Security Foundation - Command Execution Vulnerability
[P4] check the differences between the two historical versions of the library file
《剑指offer》| 刷题小记
cookie与Session
Appnium -- app automated test tool
xml文件使用及解析
Jumping game II in question 45 of C language power deduction. Ergodic jump
[wrong question]
【P4】解决本地文件修改与库文件间的冲突问题
一个仿win10蓝屏的404页面源码
[force deduction] 1337. Row K with the weakest combat effectiveness in the matrix
Collection | 0 basic open source data visualization platform flyfish large screen development guide
What is interface testing and its testing process
【LeetCode】34、在排序数组中查找元素的第一个和最后一个位置
servlet使用
Appnium--APP自动化测试工具
Move notice!
Prefix-Tuning: Optimizing Continuous Prompts for Generation
高等数学(第七版)同济大学 习题3-4 个人解答(后8题)
ES6 from getting started to mastering 09: symbol type