ubifs文件系统操作记录

ubifs 依赖于一个mtd设备

> ls /dev/mtd*
/dev/mtd0   /dev/mtd1    /dev/mtd2  /dev/mtd3 /dev/mtd4

以/dev/mtd4为例,大小为32MB,其NAND FLASH参数IO大小2KB,块大小128KB

(1)擦除mtd设备(非必需)

> flash_erase /dev/mtd4 0 0
Erasing 32768 Kibyte @ 0 -- 100 % complete

(2)ubi格式化mtd设备

> ubiformat /dev/mtd4
ubiformat: mtd4 (nand), size 33554432 bytes (32.0 MiB), 256 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
libscan: scanning eraseblock 255 -- 100 % complete
ubiformat: 256 eraseblocks are supposedly empty
ubiformat: formatting eraseblock 255 -- 100 % complete

(3)ubi连接mtd设备

> ubiattach -p /dev/mtd4
[ 1417.312716] ubi0: attaching mtd4
[ 1417.872099] ubi0: scanning is finished
[ 1417.907133] ubi0: attached mtd4 (name "test", size 32 MiB)
[ 1417.912616] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 1417.922333] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 1417.930299] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 1417.938516] ubi0: good PEBs: 256, bad PEBs: 0, corrupted PEBs: 0
[ 1417.944516] ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
[ 1417.953416] ubi0: max/mean erase counter: 0/0, WL threshold: 4096, image sequence number: 739687731
[ 1417.963599] ubi0: available PEBs: 232, total reserved PEBs: 24, PEBs reserved for bad PEB handling: 20
[ 1417.974133] ubi0: background thread "ubi_bgt0d" started, PID 1189
UBI device number 0, total 256 LEBs (32505856 bytes, 31.0 MiB), available 232 LEBs (29458432 bytes, 28.0 MiB), LEB size 126976 bytes (124.0 KiB)

此步骤完成后,系统目录会有如下变化

  • 在/sys/class/ubi/下新生成一个ubi0的目录(如果原来没有ubi设备连接)
  • 会生成一个/dev/ubi0 的设备文件

(4)创建ubi设备,名称随意,此处为data

> ubimkvol /dev/ubi0 -s 28MiB -N data
Volume ID 0, size 232 LEBs (29458432 bytes, 28.0 MiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "data", alignment 1

以上的-s参数指定卷大小,不能超过上一步骤输出的可用大小(即29458432 bytes, 28.0 MiB),-n参数指定卷名称
此步骤完成后,系统目录会有如下变化

  • 生成/sys/class/ubi/ubi0_0目录,包含了此volume的全部信息
  • 生成/dev/ubi0_0设备文件

(5)挂载

> mount -t ubifs /dev/ubi0_0 /mnt
[ 2365.188657] UBIFS (ubi0:0): default file-system created
[ 2365.197591] UBIFS (ubi0:0): Mounting in unauthenticated mode
[ 2365.205991] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" started, PID 1203
[ 2365.430632] UBIFS (ubi0:0): UBIFS: mounted UBI device 0, volume 0, name "data"
[ 2365.437991] UBIFS (ubi0:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 2365.449424] UBIFS (ubi0:0): FS size: 28188672 bytes (26 MiB, 222 LEBs), journal size 1396736 bytes (1 MiB, 11 LEBs)
[ 2365.460949] UBIFS (ubi0:0): reserved for root: 1331420 bytes (1300 KiB)
[ 2365.468666] UBIFS (ubi0:0): media format: w5/r0 (latest is w5/r0), UUID 1A65B837-5CD5-4806-9C2A-222A44F58AC6, small LPT model

挂载完成后,查看挂载信息

> mount
/dev/root on / type yaffs2 (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=28084k,nr_inodes=7021,mode=755)
proc on /proc type proc (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=666)
tmpfs on /dev/shm type tmpfs (rw,relatime,mode=777)
tmpfs on /tmp type tmpfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
sysfs on /sys type sysfs (rw,relatime)
/dev/ubi0_0 on /mnt type ubifs (rw,relatime,assert=read-only,ubi=0,vol=0)

(6)卸载

> umount /mnt
[ 2521.997132] UBIFS (ubi0:0): un-mount UBI device 0
[ 2522.001891] UBIFS (ubi0:0): background thread "ubifs_bgt0_0" stops

> ubidetach -p /dev/mtd4
[ 2544.583182] ubi0: detaching mtd4
[ 2544.589499] ubi0: mtd4 is detached

posted @ 2024-04-30 01:33  坚持梦想的蜗牛  阅读(88)  评论(0编辑  收藏  举报