Ubifs文件系统和mkfs.ubifs以及ubinize工具的用法
Ubifs產(chǎn)生背景:
? ? ? ? 無排序區(qū)塊圖像文件系統(tǒng)(Unsorted?Block?Image?File?System,?UBIFS)是用于固態(tài)硬盤存儲設(shè)備上,并與LogFS相互競爭,作為JFFS2的后繼文件系統(tǒng)之一。真正開始開發(fā)于2007年,并于2008年10月第一次加入穩(wěn)定版本于Linux核心2.6.27版。
UBIFS最早在2006年由IBM與Nokia的工程師Thomas?Gleixner,Artem?Bityutskiy所設(shè)計,專門為了解決MTD(Memory?Technology?Device)設(shè)備所遇到的瓶頸。由于Nand?Flash容量的暴漲,YAFFS等皆無法再去控制Nand?Flash的空間。UBIFS通過子系統(tǒng)UBI處理與MTD?device之間的動作。與JFFS2一樣,UBIFS?建構(gòu)于MTD?device?之上,因而與一般的block?device不兼容。JFFS2運行在MTD設(shè)備之上,而UBIFS則只能工作于UBI?volume之上。也可以說,UBIFS涉及了三個子系統(tǒng):
?
1.MTD Subsystem:
?MTD?子系統(tǒng),?提供對flash芯片的訪問接口,?MTD子系統(tǒng)提供了MTD?device的概念,比如/dev/mtdx,MTD可以認(rèn)為是raw?flash。
2.UBI?subsystem:
為flash?device提供了wear-leveling和?volume?management功能;?UBI工作在MTD設(shè)備之上,提供了UBI?volume;UBI是MTD設(shè)備的高層次表示,對上層屏蔽了一些MTD不得不處理的問題,比如wearing以及壞塊管理。
3.UBIFS filesystem
UBIFS?文件系統(tǒng),工作于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最大邏輯可擦出塊數(shù)目?
-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=(每塊的頁數(shù)-2)*頁大小=(64-2)*2KiB=124KiB?
-c最多邏輯可擦除塊數(shù)目為720(720*128KiB=90MiB),這個可根據(jù)ubi volume來設(shè)置,實際上是設(shè)置此卷的最大容量。?
========================================================================================
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頭部偏移量,默認(rèn)是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=每塊的頁數(shù)*頁大小=64*2KiB=128KiB?
-s用于UBI頭部信息的最小輸入輸出單元,一般與最小輸入輸出單元(-m參數(shù))大小一樣。?
ubinize需要指定一個配置文件$system_cfg_file,內(nèi)容如下:?
[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 ? ? ? ? ? 動態(tài)卷?
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.?
?
有了mkfs.ubifs和ubinize兩個工具后,就可以制作UBIFS鏡像了,具體步驟如下:
1.?使用mkfs.ubifs命令將某個文件夾制作為UBIFS鏡像,具體命令為:
?
以上命令的含義為將/tmp/rootfs文件夾制作為UBIFS文件系統(tǒng)鏡像,輸出的鏡像名為ubifs.img,-m參數(shù)指定了最小的I/O操作的大小,也就是NAND?FLASH一個page的大小,-e參數(shù)指定了邏輯擦除快的大小,-c指定了最大的邏輯塊號。
通過此命令制作的出的UBIFS文件系統(tǒng)鏡像可在u-boot下使用ubi?write命令燒寫到NAND?FLASH上。
2.?使用ubinize命令可將使用mkfs.ubifs命令制作的UBIFS文件系統(tǒng)鏡像轉(zhuǎn)換成可直接在FLASH上燒寫的格式(帶有UBI文件系統(tǒng)鏡像卷標(biāo)):
?
ubinize.cfg為一些配置參數(shù):
?
通過此命令生成的ubi.img可直接使用NAND?FLASH的燒寫命令燒寫到FLASH上。
-----------------------------------UBI文件系統(tǒng)掛載----------------------------------------------
ubiattach?-?鏈接MTD設(shè)備(MTD設(shè)備描述原始Flash設(shè)備)到UBI并且創(chuàng)建相應(yīng)的UBI設(shè)備;
(1)ubiattach:將指定的mtd分區(qū)關(guān)聯(lián)到ubi上
用法:./ubiattach /dev/ubi_ctrl -m 1 -d 1, 將mtd1關(guān)連ubi_1
(2)ubidetach:解除mtd與ubi的關(guān)聯(lián)
用法:./ubidetach /dev/ubi_ctrl -m 1
mount -a 是自動掛載 /etc/fstab 里面的東西。
總結(jié)
以上是生活随笔為你收集整理的Ubifs文件系统和mkfs.ubifs以及ubinize工具的用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux /etc/profile文件
- 下一篇: #ifdef ...#else...#e