1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun=============== 4*4882a593SmuzhiyunUBI File System 5*4882a593Smuzhiyun=============== 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunIntroduction 8*4882a593Smuzhiyun============ 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunUBIFS file-system stands for UBI File System. UBI stands for "Unsorted 11*4882a593SmuzhiyunBlock Images". UBIFS is a flash file system, which means it is designed 12*4882a593Smuzhiyunto work with flash devices. It is important to understand, that UBIFS 13*4882a593Smuzhiyunis completely different to any traditional file-system in Linux, like 14*4882a593SmuzhiyunExt2, XFS, JFS, etc. UBIFS represents a separate class of file-systems 15*4882a593Smuzhiyunwhich work with MTD devices, not block devices. The other Linux 16*4882a593Smuzhiyunfile-system of this class is JFFS2. 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunTo make it more clear, here is a small comparison of MTD devices and 19*4882a593Smuzhiyunblock devices. 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun1 MTD devices represent flash devices and they consist of eraseblocks of 22*4882a593Smuzhiyun rather large size, typically about 128KiB. Block devices consist of 23*4882a593Smuzhiyun small blocks, typically 512 bytes. 24*4882a593Smuzhiyun2 MTD devices support 3 main operations - read from some offset within an 25*4882a593Smuzhiyun eraseblock, write to some offset within an eraseblock, and erase a whole 26*4882a593Smuzhiyun eraseblock. Block devices support 2 main operations - read a whole 27*4882a593Smuzhiyun block and write a whole block. 28*4882a593Smuzhiyun3 The whole eraseblock has to be erased before it becomes possible to 29*4882a593Smuzhiyun re-write its contents. Blocks may be just re-written. 30*4882a593Smuzhiyun4 Eraseblocks become worn out after some number of erase cycles - 31*4882a593Smuzhiyun typically 100K-1G for SLC NAND and NOR flashes, and 1K-10K for MLC 32*4882a593Smuzhiyun NAND flashes. Blocks do not have the wear-out property. 33*4882a593Smuzhiyun5 Eraseblocks may become bad (only on NAND flashes) and software should 34*4882a593Smuzhiyun deal with this. Blocks on hard drives typically do not become bad, 35*4882a593Smuzhiyun because hardware has mechanisms to substitute bad blocks, at least in 36*4882a593Smuzhiyun modern LBA disks. 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunIt should be quite obvious why UBIFS is very different to traditional 39*4882a593Smuzhiyunfile-systems. 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunUBIFS works on top of UBI. UBI is a separate software layer which may be 42*4882a593Smuzhiyunfound in drivers/mtd/ubi. UBI is basically a volume management and 43*4882a593Smuzhiyunwear-leveling layer. It provides so called UBI volumes which is a higher 44*4882a593Smuzhiyunlevel abstraction than a MTD device. The programming model of UBI devices 45*4882a593Smuzhiyunis very similar to MTD devices - they still consist of large eraseblocks, 46*4882a593Smuzhiyunthey have read/write/erase operations, but UBI devices are devoid of 47*4882a593Smuzhiyunlimitations like wear and bad blocks (items 4 and 5 in the above list). 48*4882a593Smuzhiyun 49*4882a593SmuzhiyunIn a sense, UBIFS is a next generation of JFFS2 file-system, but it is 50*4882a593Smuzhiyunvery different and incompatible to JFFS2. The following are the main 51*4882a593Smuzhiyundifferences. 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun* JFFS2 works on top of MTD devices, UBIFS depends on UBI and works on 54*4882a593Smuzhiyun top of UBI volumes. 55*4882a593Smuzhiyun* JFFS2 does not have on-media index and has to build it while mounting, 56*4882a593Smuzhiyun which requires full media scan. UBIFS maintains the FS indexing 57*4882a593Smuzhiyun information on the flash media and does not require full media scan, 58*4882a593Smuzhiyun so it mounts many times faster than JFFS2. 59*4882a593Smuzhiyun* JFFS2 is a write-through file-system, while UBIFS supports write-back, 60*4882a593Smuzhiyun which makes UBIFS much faster on writes. 61*4882a593Smuzhiyun 62*4882a593SmuzhiyunSimilarly to JFFS2, UBIFS supports on-the-flight compression which makes 63*4882a593Smuzhiyunit possible to fit quite a lot of data to the flash. 64*4882a593Smuzhiyun 65*4882a593SmuzhiyunSimilarly to JFFS2, UBIFS is tolerant of unclean reboots and power-cuts. 66*4882a593SmuzhiyunIt does not need stuff like fsck.ext2. UBIFS automatically replays its 67*4882a593Smuzhiyunjournal and recovers from crashes, ensuring that the on-flash data 68*4882a593Smuzhiyunstructures are consistent. 69*4882a593Smuzhiyun 70*4882a593SmuzhiyunUBIFS scales logarithmically (most of the data structures it uses are 71*4882a593Smuzhiyuntrees), so the mount time and memory consumption do not linearly depend 72*4882a593Smuzhiyunon the flash size, like in case of JFFS2. This is because UBIFS 73*4882a593Smuzhiyunmaintains the FS index on the flash media. However, UBIFS depends on 74*4882a593SmuzhiyunUBI, which scales linearly. So overall UBI/UBIFS stack scales linearly. 75*4882a593SmuzhiyunNevertheless, UBI/UBIFS scales considerably better than JFFS2. 76*4882a593Smuzhiyun 77*4882a593SmuzhiyunThe authors of UBIFS believe, that it is possible to develop UBI2 which 78*4882a593Smuzhiyunwould scale logarithmically as well. UBI2 would support the same API as UBI, 79*4882a593Smuzhiyunbut it would be binary incompatible to UBI. So UBIFS would not need to be 80*4882a593Smuzhiyunchanged to use UBI2 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun 83*4882a593SmuzhiyunMount options 84*4882a593Smuzhiyun============= 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun(*) == default. 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun==================== ======================================================= 89*4882a593Smuzhiyunbulk_read read more in one go to take advantage of flash 90*4882a593Smuzhiyun media that read faster sequentially 91*4882a593Smuzhiyunno_bulk_read (*) do not bulk-read 92*4882a593Smuzhiyunno_chk_data_crc (*) skip checking of CRCs on data nodes in order to 93*4882a593Smuzhiyun improve read performance. Use this option only 94*4882a593Smuzhiyun if the flash media is highly reliable. The effect 95*4882a593Smuzhiyun of this option is that corruption of the contents 96*4882a593Smuzhiyun of a file can go unnoticed. 97*4882a593Smuzhiyunchk_data_crc do not skip checking CRCs on data nodes 98*4882a593Smuzhiyuncompr=none override default compressor and set it to "none" 99*4882a593Smuzhiyuncompr=lzo override default compressor and set it to "lzo" 100*4882a593Smuzhiyuncompr=zlib override default compressor and set it to "zlib" 101*4882a593Smuzhiyunauth_key= specify the key used for authenticating the filesystem. 102*4882a593Smuzhiyun Passing this option makes authentication mandatory. 103*4882a593Smuzhiyun The passed key must be present in the kernel keyring 104*4882a593Smuzhiyun and must be of type 'logon' 105*4882a593Smuzhiyunauth_hash_name= The hash algorithm used for authentication. Used for 106*4882a593Smuzhiyun both hashing and for creating HMACs. Typical values 107*4882a593Smuzhiyun include "sha256" or "sha512" 108*4882a593Smuzhiyun==================== ======================================================= 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun 111*4882a593SmuzhiyunQuick usage instructions 112*4882a593Smuzhiyun======================== 113*4882a593Smuzhiyun 114*4882a593SmuzhiyunThe UBI volume to mount is specified using "ubiX_Y" or "ubiX:NAME" syntax, 115*4882a593Smuzhiyunwhere "X" is UBI device number, "Y" is UBI volume number, and "NAME" is 116*4882a593SmuzhiyunUBI volume name. 117*4882a593Smuzhiyun 118*4882a593SmuzhiyunMount volume 0 on UBI device 0 to /mnt/ubifs:: 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun $ mount -t ubifs ubi0_0 /mnt/ubifs 121*4882a593Smuzhiyun 122*4882a593SmuzhiyunMount "rootfs" volume of UBI device 0 to /mnt/ubifs ("rootfs" is volume 123*4882a593Smuzhiyunname):: 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun $ mount -t ubifs ubi0:rootfs /mnt/ubifs 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunThe following is an example of the kernel boot arguments to attach mtd0 128*4882a593Smuzhiyunto UBI and mount volume "rootfs": 129*4882a593Smuzhiyunubi.mtd=0 root=ubi0:rootfs rootfstype=ubifs 130*4882a593Smuzhiyun 131*4882a593SmuzhiyunReferences 132*4882a593Smuzhiyun========== 133*4882a593Smuzhiyun 134*4882a593SmuzhiyunUBIFS documentation and FAQ/HOWTO at the MTD web site: 135*4882a593Smuzhiyun 136*4882a593Smuzhiyun- http://www.linux-mtd.infradead.org/doc/ubifs.html 137*4882a593Smuzhiyun- http://www.linux-mtd.infradead.org/faq/ubifs.html 138