From: eLinux.org

UBIFS

Contents

Introduction

UBIFS is a filesystem that works on top of
UBI volumes

It represents a next-generation flash filesystem, compared to JFFS2, and
(via UBI) operates on raw flash rather than on block-based media (such
as eMMC or traditional hard drives).

History

UBIFS was written by developers at Nokia with help from the University
of Szeged. Included in these developers was the current (as of 2012)
maintainer of UBIFS, Artem Bityuski. The filesystem was mainlined in the
Linux kernel in July, 2008, in kernel version 2.6.27.

Features

The UBIFS home page
has more detailed information, but in summary, UBI has the following
features relative to other flash filesystems:

  • UBI/UBIFS scales to large flash sizes better than JFFS2
  • Good fault tolerance, via a number of features
  • Built-in on-the-fly compression
  • Good runtime performance

Fastmap support

As of kernel version 3.7, UBI fastmap support was added to the kernel,
to overcome a scalability issue with the time required to mount UBIFS on
large flash media.

I specifically deals with the scalability issue described here:
http://www.linux-mtd.infradead.org/doc/ubifs.html#L_scalability

A description of the feature is at:
http://lwn.net/Articles/517422/

  1. "UBI Fastmap is an optional feature which stores the physical to
  2. logical eraseblock relations in a checkpoint (called fastmap) to reduce
  3. the initialization time of UBI. The current init time of UBI is
  4. proportional to the number of physical erase blocks on the FLASH
  5. device. With fastmap enabled the scan time is limited to a fixed
  6. number of blocks."

UBIFS vs. YAFFS2 comparisons for 2.6.31.1

Note: see our
Flash_Filesystem_Benchmarks
for more recent benchmarks.

Hardware: MIPS, 403MHz CPU, 1GB Nand Flash

IOZone results: 4M, 8M & 16M file sizes in 980MB partition.

  • mount time
    • “1st mount” : time for mounting just after “flash_eraseall”.
    • “Empty” : time for mounting after “1st mount”.(there’s no files
      in partition)
    • “Full” : time for mounting after creating files util the
      partition is full.(file size is random.)
    • “Ubiattach” time for attaching 980MB partition into the ubi
      layer using ubiattach util.





























UbiattachUbifsYaffs2
1st mount2.59 sec0.17 sec2.25 sec
Empty2.57 sec0.11 sec0.03 sec
Full2.63 sec0.16 sec0.80 sec
  • IOZone results






































































UBIFS compared to YAFFS2 (file size = 4MB)
4Mwriterewritereadrereadr.readr.writeb.readr.rewrites.readfwritefrewritefreadfreread
yaffs2153815272969622976962978251521296876152629516415361524297436299021
ubifs199132098929834629763129980920968298368201812994582047120962297371297760
ubifs/yaffs212.9513.751.001.001.0113.791.0113.221.0113.3313.751.001.00






































































UBIFS compared to YAFFS2 (file size = 16MB)
16Mwriterewritereadrereadr.readr.writeb.readr.rewrites.readfwritefrewritefreadfreread
yaffs2153815232971992985252988961528298433152529884715381525299661300656
ubifs205012065629827229910929903220521298417207102989232044820521298259299267
ubifs/yaffs213.3313.561.001.001.0013.431.0013.581.0013.3013.461.001.00






































































UBIFS compared to YAFFS2 (file size = 32MB)
32Mwriterewritereadrereadr.readr.writeb.readr.rewrites.readfwritefrewritefreadfreread
yaffs2153915252965372972042972531527297177152729658315311523296537297463
ubifs204742061129676529749029733420659296972384162973711906820059296618296658
ubifs/yaffs213.3013.521.001.001.0013.531.0025.161.0012.4513.171.001.00

Creating UBI Image

This is easiest to do, if you have access to the device and can run
ubinfo and dmesg, otherwise you’ll need to determine the volume size,
Logical Erase Block size, etc by other means. UBI has some block
overhead, which I found documentation inconsistent with my particular
application, so your results may very. If your device is one UBI image
for the entire NAND, this should be easier, and could probably be
determined by just mounting a copy of the UBI image from the device if
available.

To create the image from a rootfs you’ve built first you need to create
the ubi.ini file, that describes your ubi image. Create a regular text
file, ubi.ini, example contents, for more info run ubinize -h:

  1. [ubi_rfs]
  2. mode=ubi
  3. image=ubifs.img
  4. vol_id=0
  5. vol_size=87349248
  6. vol_type=dynamic
  7. vol_name=ubi_rfs
  8. vol_alignment=1
  9. vol_flags=autoresize

Next you’ll run the commands that actually build it. Here ubi.ini is the
file you just created, ubifs.img is a temp file you can delete once you
are done, and your_erootfs.ubi is the name of the rootfs image that
will be created.

  1. sudo /usr/sbin/mkfs.ubifs -m 2048 -e 129024 -c 677 -r /path/to/rootfs ubifs.img
  2. sudo /usr/sbin/ubinize -o your_erootfs.ubi -p 131072 -m 2048 -s 512 -O 512 ubi.ini

To determine these and the ubi.ini file settings, use ubinfo -a and
dmesg on the device if possible, which both give plenty of information
about the values needed. The size and vol_name are listed under
“Present volumes” when you run ubinfo -a on the device. The second half
of that particular ubi device’s description. While the NAND
description’s PEB, LEB etc are in dmesg.

mkfs.ubifs

  • -m - Minimum I/O unit size.
  • -e - Logical Erase Block (LEB) size.
  • -c - Max LEB count. (vol_size/LEB)
  • -x - Compression type: lzo (default), favor_lzo, zlib, none
  • -r - Path to root filesystem.
  • ubifs.img - Temporary image file.

ubinize

  • -o - Output file.
  • -p - Physical Erase Block (PEB) size.
  • -m - Minimum I/O unit size.
  • -s - Minimum I/O size for UBI headers, eg. sub-page size.
  • -O - VID header offset from start of PEB.
  • ubi.ini - UBI image configuration file.

Mounting UBI Image on PC using nandsim

First create a simulated NAND device (this one is 256MB, 2048 page
size). \_id_byte= corresponds to the ID bytes sent back from
the NAND.

  1. $ sudo modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 fourth_id_byte=0x15

Check it was created.

  1. $ cat /proc/mtd
  2. dev: size erasesize name
  3. mtd0: 10000000 00020000 "NAND simulator partition 0"

Next, attach it to a mtd device.

  1. $ sudo modprobe ubi mtd=0

I had to detach it prior to formatting it.

  1. $ sudo ubidetach /dev/ubi_ctrl -m 0

If that ubidetach step fails when you enter it, just proceed to the next
step to format the mtd device.

  1. $ sudo ubiformat /dev/mtd0 -f <image>.ubi
  2. ubiformat: mtd0 (nand), size 268435456 bytes (256.0 MiB), 2048 eraseblocks of 131072 bytes (128.0 KiB), min. I/O size 2048 bytes
  3. libscan: scanning eraseblock 2047 -- 100 % complete
  4. ubiformat: 2048 eraseblocks have valid erase counter, mean value is 1
  5. ubiformat: flashing eraseblock 455 -- 100 % complete
  6. ubiformat: formatting eraseblock 2047 -- 100 % complete

Then, attach it.

  1. $ sudo ubiattach /dev/ubi_ctrl -m 0
  2. UBI device number 0, total 2048 LEBs (264241152 bytes, 252.0 MiB), available 0 LEBs (0 bytes), LEB size 129024 bytes (126.0 KiB)

Make a target directory, and mount the device.

  1. $ mkdir temp
  2. $ sudo mount -t ubifs ubi0 temp