Ubifs檔案系統和mkfs.ubifs以及ubinize工具的用法
轉載地址:https://blog.csdn.net/wjjontheway/article/details/8977871
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 <bytes>] [-m <bytes>] [-s <bytes>] [-O <num>] [-e
<num>][-x <num>] [-Q <num>] [-v] [-h] [-V] [--output=<filename>]
[--peb-size=<bytes>] [--min-io-size=<bytes>] [--sub-page-size=<bytes>]
[--vid-hdr-offset=<num>] [--erase-counter=<num>] [--ubi-ver=<num>]
[--image-seq=<num>] [--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=<file name> output file name
-p, --peb-size=<bytes> 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=<bytes> minimum input/output unit size of the flash
in bytes
-s, --sub-page-size=<bytes> 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=<num> 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=<num> the erase counter value to put to EC headers (default is 0)
-x, --ubi-ver=<num> UBI version number to put to EC headers (default is 1)
-Q, --image-seq=<num> 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.