ubifs产生背景:
无排序区块图像文件系统(unsorted block image file system, ubifs)是用于固态硬盘存储设备上,并与logfs相互竞争,作为jffs2的后继文件系统之一。真正开始开发于2007年,并于2008年10月第一次加入稳定版本于linux核心2.6.27版。
ubifs最早在2006年由ibm与nokia的工程师thomas gleixner,artem bityutskiy所设计,专门为了解决mtd(memory technology device)设备所遇到的瓶颈。由于nand flash容量的暴涨,yaffs等皆无法再去控制nand flash的空间。ubifs通过子系统ubi处理与mtd device之间的动作。与jffs2一样,ubifs 建构于mtd device 之上,因而与一般的block device不兼容。jffs2运行在mtd设备之上,而ubifs则只能工作于ubi volume之上。也可以说,ubifs涉及了三个子系统:
1.mtd subsystem:
mtd 子系统, 提供对flash芯片的访问接口, mtd子系统提供了mtd device的概念,比如/dev/mtdx,mtd可以认为是raw flash。
2.ubi subsystem:
为flash device提供了wear-leveling和 volume management功能; ubi工作在mtd设备之上,提供了ubi volume;ubi是mtd设备的高层次表示,对上层屏蔽了一些mtd不得不处理的问题,比如wearing以及坏块管理。
3.ubifs filesystem
ubifs 文件系统,工作于ubi之上。
================================================================
mkfs.ubifs的用法
usage: mkfs.ubifs [options] target
make a ubifs file system image from an existing directory tree
examples:
build file system from directory /opt/img, writting the result in the ubifs.img file
mkfs.ubifs -m 512 -e 128kib -c 100 -r /opt/img ubifs.img
the same, but writting directly to an ubi volume
mkfs.ubifs -r /opt/img /dev/ubi0_0
creating an empty ubifs filesystem on an ubi volume
mkfs.ubifs /dev/ubi0_0
options:
-r, -d, --root=dir build file system from directory dir
-m, --min-io-size=size minimum i/o unit size,最小输入输出大小
-e, --leb-size=size logical erase block size逻辑可擦出块大小
-c, --max-leb-cnt=count maximum logical erase block count最大逻辑可擦出块数目
-o, --output=file output to file输出文件名
-j, --jrn-size=size journal size
-r, --reserved=size how much space should be reserved for the super-user
-x, --compr=type compression type - "lzo", "favor_lzo", "zlib" or
"none" (default: "lzo")
-x, --favor-percent may only be used with favor lzo compression and defines
how many percent better zlib should compress to make
mkfs.ubifs use zlib instead of lzo (default 20%)
-f, --fanout=num fanout num (default: 8)
-f, --space-fixup file-system free space has to be fixed up on first moun
(requires kernel version 3.0 or greater)
-k, --keyhash=type key hash type - "r5" or "test" (default: "r5")
-p, --orph-lebs=count count of erase blocks for orphans (default: 1)
-d, --devtable=file use device table file
-u, --squash-uids squash owners making all files owned by root
-l, --log-lebs=count count of erase blocks for the log (used only for debugging)
-v, --verbose verbose operation
-v, --version display version information
-g, --debug=level display debug information (0 - none, 1 - statistics, 2 - files, 3 - more details)
-h, --help display this help text
例:
mkfs.ubifs -x lzo -m 2kib -e 124kib -c 720 -o system_ubifs.img -d $path_to_system
压缩格式为lzo
-m最小输入输出大小为2kib(2048bytes),一般为页大小
-e逻辑可擦除块大小为124kib=(每块的页数-2)*页大小=(64-2)*2kib=124kib
-c最多逻辑可擦除块数目为720(720*128kib=90mib),这个可根据ubi volume来设置,实际上是设置此卷的最大容量。
========================================================================================
ubinize的用法
usage: ubinize [-o filename] [-p ] [-m ] [-s ] [-o ] [-e
][-x ] [-q ] [-v] [-h] [-v] [--output=]
[--peb-size=] [--min-io-size=] [--sub-page-size=]
[--vid-hdr-offset=] [--erase-counter=] [--ubi-ver=]
[--image-seq=] [--verbose] [--help] [--version] ini-file
example: ubinize -o ubi.img -p 16kib -m 512 -s 256 cfg.ini - create ubi image
'ubi.img' as described by configuration file 'cfg.ini'
-o, --output= output file name
-p, --peb-size= size of the physical eraseblock of the flash
this ubi image is created for in bytes,
kilobytes (kib), or megabytes (mib)
(mandatory parameter)物理可擦出块大小
-m, --min-io-size= minimum input/output unit size of the flash
in bytes
-s, --sub-page-size= minimum input/output unit used for ubi
headers, e.g. sub-page size in case of nand
flash (equivalent to the minimum input/output
unit size by default)子页大小
-o, --vid-hdr-offset= offset if the vid header from start of the
physical eraseblock (default is the next
minimum i/o unit or sub-page after the ec
header)vid头部偏移量,默认是512
-e, --erase-counter= the erase counter value to put to ec headers (default is 0)
-x, --ubi-ver= ubi version number to put to ec headers (default is 1)
-q, --image-seq= 32-bit ubi image sequence number to use
(by default a random number is picked)
-v, --verbose be verbose
-h, --help print help message
-v, --version print program version
例:
ubinize –o ubi.img -m 2kib -p 128kib -s 2048 $system_cfg_file –v
-m最小输入输出大小为2kib(2048bytes),一般为页大小
-p物理可擦出块大小为128kib=每块的页数*页大小=64*2kib=128kib
-s用于ubi头部信息的最小输入输出单元,一般与最小输入输出单元(-m参数)大小一样。
ubinize需要指定一个配置文件$system_cfg_file,内容如下:
[rootfs-volume]
mode=ubi
image=system_ubifs.img
vol_id=0
vol_size=90mib
vol_type=dynamic
vol_name=system
======================================================================
配置文件说明
ini-file format.
the input configuration ini-file describes all the volumes which have to
be included to the output ubi image. each volume is described in its own
section which may be named arbitrarily. the section consists on
"key=value" pairs, for example:
[jffs2-volume]
mode=ubi
image=../jffs2.img mkfs.ubi生成的源镜像
vol_id=1 卷序号
vol_size=30mib 卷大小
vol_type=dynamic 动态卷
vol_name=jffs2_volume 卷名
vol_flags=autoresize
vol_alignment=1
this example configuration file tells the utility to create an ubi image with one volume with id 1, volume size 30mib, the volume is dynamic, has name "jffs2_volume", "autoresize" volume flag, and alignment 1. the "image=../jffs2.img" line tells the utility to take the contents of the volume from the "../jffs2.img" file. the size of the image file has to be less or equivalent to the volume size (30mib). the "mode=ubi" line is mandatory and just tells that the section describes an ubi volume - other section modes may be added in the future.
notes:
* size in vol_size might be specified kilobytes (kib), megabytes (mib), gigabytes (gib) or bytes (no modifier);
* if "vol_size" key is absent, the volume size is assumed to be equivalent to the size of the image file (defined by "image" key);
* if the "image" is absent, the volume is assumed to be empty;
* volume alignment must not be greater than the logical eraseblock size;
* one ini file may contain arbitrary number of sections, the utility will put all the volumes which are described by these section to the output ubi image file.
转载自:http://blog.sina.com.cn/s/blog_9452251d0102v482.html