ops-about-ubi-filesystem

ubi文件系统需要附着到具体的MTD设备上,所以格式化分区时,需要先detach再格式化。

有如下配置:/dev/ubi2_0 attach to /dev/mtd14

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/ # mount -v
/dev/ubi2_0 on /userstore type ubifs (rw,relatime,bulk_read)

/ # df -h
Filesystem Size Used Available Use% Mounted on
/dev/ubi2_0 7.2M 108.0K 6.7M 2% /userstore

/ # cat /proc/mtd
dev: size erasesize name
mtd14: 00b00000 00020000 "userstore"

/ # fdisk -l /dev/mtdblock14

Disk /dev/mtdblock14: 11 MB, 11534336 bytes
255 heads, 63 sectors/track, 1 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/mtdblock14 doesn't contain a valid partition table

格式化ubi设备

umount

fuser -m /userstore:查看正在使用该目录的程序的PIDkill掉之后执行下一步。

umount /userstore

detach

ubidetach -m 14:detach /dev/mtd14,此时自动删除/dev/ubi2*

erase

dd if=/dev/zero of=/dev/mtdblock14 bs=1024 count=11264:1024 * 11264 = 11534336(/dev/mtdblock14的大小)

format

ubiformat /dev/mtd14 -y

挂载ubi设备

attach

ubiattach -m 14 -d 2 -b 1:sets PEBs for bad PEB handling to (1 * 4)

此处可以再开个shellcat /dev/kmsg有如下打印:

1
2
3
4
5
6
7
8
9
10
11
5,963,6012313368,-;ubi2: attaching mtd14
5,964,6012409521,-;ubi2: scanning is finished
5,965,6012424701,-;ubi2: attached mtd14 (name "userstore", size 11 MiB)
5,966,6012434711,-;ubi2: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
5,967,6012441141,-;ubi2: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
5,968,6012455103,-;ubi2: VID header offset: 2048 (aligned 2048), data offset: 4096
5,969,6012466213,-;ubi2: good PEBs: 88, bad PEBs: 0, corrupted PEBs: 0
5,970,6012471740,-;ubi2: user volume: 0, internal volumes: 1, max. volumes count: 128
5,971,6012479080,-;ubi2: max/mean erase counter: 0/0, WL threshold: 4096, image sequence number: 1802547055
5,972,6012488086,-;ubi2: available PEBs: 80, total reserved PEBs: 8, PEBs reserved for bad PEB handling: 4
5,973,6012499610,-;ubi2: background thread "ubi_bgt2d" started, PID 29236

可看到 available PEBs: 80, total reserved PEBs: 8, PEBs reserved for bad PEB handling: 4
ubiattach -b 1 就是对应这里的4,-b 是指1024个预留一个PEB用来处理坏块的,这里乘以4应该是跟打印的4096有关。
available PEBs: 80表示可使用的,越大则分区容量越大。

volume

ls /dev/ubi2_0:是否自动生成卷标。

  • 已生成/dev/ubi2_0:ubirsvol /dev/ubi2 -n 0 -S 80,分配80 PEBs。
  • 未生成/dev/ubi2_0:ubimkvol /dev/ubi2 -n 0 -S 80 -N userstore,分配80 PEBs。

mount

mount -t ubifs -o rw /dev/ubi2_0 /userstore -o bulk_read