Ubifs FAQ and howto

Source: Internet
Author: User

Ubifs FAQ and howto
Table of contents
  1. May ubifs be used on mlc nand Flash?
  2. How to mount ubifs?
  3. How to create an ubifs image?
  4. How to find out LEB size?
  5. May an empty ubi volume be mounted?
  6. What is the purpose of-C (-- Max-LEB-CNT) mkfs. ubifs option?
  7. How to compile mkfs. ubifs?
  8. Can ubifs Mount loop-back devices?
  9. How to change a file atomically?
  10. Does ubifs support atime?
  11. Does ubifs support NFS?
  12. Does ubifs become slower when it is full?
  13. WhydfReports too few free space?
  14. How to disable compression?
  15. How to Use ubifs with nandsim?
  16. Is ubifs tolerant to power-cuts?
May ubifs be used on mlc nand Flash?

Yes, it shoshould run fine. Let's consider the specific aspects of mlc nand flashes:

  • Mlc nand flashes are more "Faulty" than SLC, so they use stronger ECC codes which occupy whole OOB area; this is not a problem for ubi/ubifs, because neither ubifs nor ubi use OOB area;
  • When the data is written to an eraseblock, it has to be written sequentially, from the beginning of the eraseblock to the end of it; this is also not a problem because it is exactly what ubi and ubifs do (see also this section );
  • MLC flashes have rather short eraseblock life-cycle of just few thousand of erase cycles; and this is not be a problem, because ubi uses deterministic wear-leveling algorithm (seethis section ).
How to mount ubifs?

Ubifs mounts ubi volumes, not ubi devices, not MTD devices. There are no block device nodes corresponding to ubi volumes and ubifs uses device-less mount, just likeprocfsOrsysfs. The volume to mount is specified usingubiX_YOrubiX:NAMESyntax, where

  • X-Ubi device number;
  • Y-Ubi volume number;
  • NAME-Ubi volume name.

For example,

$ mount -t ubifs ubi0_0 /mnt/ubifs

Mounts volume 0 on ubi device 0/mnt/ubifs, And

$ mount -t ubifs ubi0:rootfs /mnt/ubifs

Mounts "rootfs" volume of ubi device 0/mnt/ubifs("Rootfs" is volume name). This method of specifying ubi volume is more preferable because it does not depend on volume number.

Note, ifXIs not specified, ubifs uses 0, I. e .,"ubi0:rootfs"And"ubi:rootfs"Are equivalent.

Some environments like busybox are confused by the ":" delimiter (e.g .,ubi:rootfs) And "! "May be used instead (e.g .,ubi!rootfs).

The following is an example of the kernel boot arguments to attachmtd0To ubi and mount volume "rootfs ":

ubi.mtd=0 root=ubi0:rootfs rootfstype=ubifs

Please, see this section for information about how to create ubi devices and this section for information about how to create ubi volumes.

How to create an ubifs image?

Creating ubifs images might be a little trickier than creating jffs2 images. first of all, you have to understand that ubifs works on top of ubi which works on top or MTD which basically represents your raw flash. this means, that if you need to create an image which wowould be flashed to the raw flash, you showould first create an ubifs image, than ubi image. in other words, the process has 2 steps.

However, as described here, ubi has a volume update facility and there isubiupdatevolUtility which for this. so you may update ubi volumes straight form your running system as well. in this case, you only need ubifs image, and you do not have to make the ubi image, I. E ., the process has only 1 step in this case.

So, there are 2 utilities:

  • mkfs.ubifsWhich creates ubifs images;
  • ubinizeWhich creates ubi images.

And depending on the needs you use eithermkfs.ubifsOrmkfs.ubifsPlusubinize. Choose the former if you are going to upload the update ubifs image on your target and then update the ubi volume usingubiupdatevol. Choose the latter if you are going to flash the image to raw flash, e.g., at the factory.

The ubi and ubifs images depend on parameters of the flash they are going to be used on. Namely, you have to know the following characteristics of the flash before creating images:

  • Flash size;
  • Physical eraseblock size;
  • Minimum Flash Input/output unit size;
  • For NAND flashes, sub-page size;
  • Logical eraseblock size.

This and this sections explain the above parameters and give some hints about how to find them out.

And optionally, you shoshould decide which compression algorithm you woshould want to use for this file-system. ubifs supports zlib and lzo (default) at the moment. generally, zlib compresses better, but it is slower on both compression and decompression. so this is a trade-off between space savings and speed. the best idea is to try both and choose the one which is more appropriate for you. but if Flash space is not a big issue, it is recommended to use lzo. alternatively, the compression may be switched off. see"-x"Option ofmkfs.ubifsUtility.

There are other advanced file-system and ubi characteristics which may be altered with the tools. Use them only if you understand what they do.

The below example demonstrates how to create an ubi/ubifs image for a 256mib SLC onenand flash chip with 128kib physical eraseblocks, 2048 bytes NAND pages, and which supports 4 sub-pages (this means that it allows to do 4x512 bytes writes to the same NAND page, which is quite typical for SLC flashes ). the resulting image will have one ubi volume storing ubifs file-system.

$ mkfs.ubifs -r root-fs -m 2048 -e 129024 -c 2047 -o ubifs.img $ ubinize -o ubi.img -m 2048 -p 128KiB -s 512 ubinize.cfg

Whereubinize.cfgContains:

$ cat ubinize.cfg [ubifs] mode=ubi image=ubifs.img vol_id=0 vol_size=200MiB vol_type=dynamic vol_name=rootfs vol_flags=autoresize

Some comments about what the options mean:

  • -r root-fs: Tellsmkfs.ubifsTo create an ubifs image which wowould have identical contents as the localroot-fsDirectory has;
  • -m 2048: Tellsmkfs.ubifsThat the minimum input/output unit size of the flash this ubifs image is created for is 2048 bytes;
  • -e 129024: Logical eraseblock size of the ubi volume this image is created;
  • -c 2047: Specifies maximum file-system size in logical eraseblocks; this means that it will be possible to use the resulting file-system on volumes up to this size (less or equivalent ); so in this participates case, the resulting FS may be put on volumes up to about 251mib (129024 multiplied by 2047 );
  • -p 128KiB: TellsubinizeThat physical eraseblock size of the flash chip the ubi image is created for is 128kib (128*1024 bytes );
  • -s 512: TellsubinizeThat the flash supports sub-pages and sub-page size is 512 bytes;ubinizeWill take this into account and put the vid header to the same NAND page as the EC header.

TheubinizeUtility requires volumes description file. Please, refer this section for moreubinizeUsage information.

In the example,ubinize.cfgFile tellsubinizeTo create an ubi image which has a singe 200mib dynamic volume with ID 0, and name "rootfs ". the configuration file also sets the "autoresize" volume flag, which means that the volume will be automatically enlarged by ubifs to have the maximum possible size when it runs for the first time. see here for more information about what the auto-resize feature is.

Please, runubinize -hAndmkfs.ubifs -hFor more information and for more possibilities to tweak the generated images.

Here is one more example for a 32mib nor flash with 128kib physical eraseblock size.

$ mkfs.ubifs -r root-fs -m 1 -e 130944 -c 255 -o ubifs.img $ ubinize -o ubi.img -m 1 -p 128KiB ubinize.cfg

Whereubinize.cfgContains:

$ cat ubinize.cfg [ubifs] mode=ubi image=ubifs.img vol_id=0 vol_size=30MiB vol_type=dynamic vol_name=rootfs vol_alignment=1 vol_flags=autoresize

And one more example for a 512mib mlc nand Flash with 128kib physical eraseblock size, 2048 bytes NAND page size and no sub-page write support.

$ mkfs.ubifs -r root-fs -m 2048 -e 126976 -c 4095 -o ubifs.img $ ubinize -o ubi.img -m 2048 -p 128KiB ubinize.cfg

Whereubinize.cfgContains:

$ cat ubinize.cfg [ubifs] mode=ubi image=ubifs.img vol_id=0 vol_size=450MiB vol_type=dynamic vol_name=rootfs vol_alignment=1 vol_flags=autoresize
How to find out LEB size?

When creating ubifs images it is necessary to know logical eraseblock size which depends on the following flash chip parameters:

  • Physical eraseblock size;
  • Minimum input/output unit size;
  • Sub-page size;

Please, refer this section for more information about how to find those 3 parameters. Here are the most typical configurations:

  • Nor flash with 1 byte min. I/O unit size: LEB size is peb size minus 128;
  • NAND Flash with 512 byte NAND page and 265 byte sub-page: LEB size is peb size minus 512;
  • NAND Flash with 2048 byte NAND page and 512 byte sub-page: LEB size is peb size minus 2048;
  • NAND Flash with 2048 byte NAND page and no sub-page: LEB size is peb size minus 4096.

Please, also refer this section for additional information.

The easiest way to find out the LEB size is to attach the MTD device to ubi, as it is suggested at the end of this section.

Is it OK to mount empty ubi volumes?

Yes, it is OK to mount empty ubi volumes, I. e. the volumes which contain only 0xff bytes. in this case ubifs formats the media automatically with default parameters (Journal size, compression, etc ). but generally, this feature shocould have limited use, and a proper ubifs image shoshould preferably be flashed created (see this section ).

Note, ubi has similar property and it automatically formats the Flash Media if it is empty (see here). So if there ismtd0MTD device, the following will work:

# Wipe the MTD device out. Note, we could use flash_eraseall, but we do not # want to loose erase counters ubiformat /dev/mtd0 # Load UBI module modprobe ubi # Attach mtd0 to UBI - UBI will detect that the MTD device is # empty and automatically format it. This command will also create # UBI device 0 and udev should create /dev/ubi0 node ubiattach /dev/ubi_ctrl -m 0 # Create an UBI volume - the created volume will be empty ubimkvol /dev/ubi0 -N test_volume -s 10MiB # Mount UBIFS - it will automatically format the empty volume mount -t ubifs ubi0:test_volume /mnt/ubifs

It is also possible to wipe out an existing ubifs volume represented/dev/ubi0_0Using the following command:

ubiupdatevol /dev/ubi0_0 -t
What is the purpose of-C (-- Max-LEB-CNT) mkfs. ubifs option?

It is a form of specifying file-system size. But instead of specifying the exact file-system size, this option definesMaximumFile-system size (more strictly, maximum ubi volume size). For example, if you use--max-leb-cnt=200 mkfs.ubifsOption, than it will be possible to put the resulting image to smaller ubi volume and mount it. but if the image is put to a larger ubi volume, the file-system will anyway take only first 200 lebs, and the rest of the volume will be wasted.

Note,--max-leb-cntOption does not affect the size of the resulting image file, which depends only on the amount of data in the file-system.mkfs.ubifsJust writes--max-leb-cntValue to the file-system superblocks.

This feature is quite handy on NAND flashes, because they have random amount of initial bad eraseblocks (marked as bad in production ). this means, that different devices may have slightly different volume sizes (especially if the ubi auto-resize feature is used ). so you may specify the maximum possible volume size and this will guarantee that the image will work on all devices, irrespectively on the amount of initial bad eraseblocks.

Fundamentally,mkfs.ubifsHas to know file-system size because ubifs maintains and stores per-LEB information (like amount of dirty and free space in each LEB) in so-called LPT area on the media. so obviusly, the size of this area depends on the total amount of lebs, I. e. on the volume size. note, various characteristics of the lpt B-tree depend on the LPT area size, e.g ., we use less bits in LPT tree keys of smaller LPT area. so do not use unnecessarily large--max-leb-cntValue to achieve better performance.

Can ubifs Mount loop-back devices?

Unfortunately not, because loop-back devices are Block devices (backed by regular files), while ubifs works on top of ubi devices (see here ).

However, there is a very hacky way to make ubifs work with a file-backed Image Using NAND simulator (see here). OriginallynandsimHas been created to emulate NAND flashes in Ram, but there is a patch which teachesnandsimTo use a file instead of memory. Try something like

# Create a 1GiB emulated MTD device backed by regular file "my_image" $ modprobe nandsim cache_file=my_image first_id_byte=0xec second_id_byte=0xd3 third_id_byte=0x51 fourth_id_byte=0x95

See here for more instructions about using ubifs with nandsim.

But be warned that this patch has not been well tested, it is not in mainline yet, and it has been created for development and debugging purposes, but not for production use.

How to compile mkfs. ubifs?

Themkfs.ubifsUtility requiresZlib,LzoAndUUIDLibraries. The former two are used for compressing the data, and the latter one is used for generatingUniversally unique ID numberFor the file-system. In fedora installzlib-devel,lzo-devel, Ande2fsprogs-devel(libuuidIs provided there, strangely) packages, In Debian installzlib1g-dev,liblzo2-devAnduuid-devPackages.

How to change a file atomically?

Changing a file atomically means changing the contents in a way that unclean reboots cocould not lead to any temporary uption or inconsistency in the file. the only reliable way to do this in ubifs (and in most of other file-systems, e.g. jffs2 or ext3) is the following:

  • Make a copy of the file;
  • Change the copy;
  • Synchronize the copy (see here );
  • Re-name the copy to the file (usingrename() LibcFunction ormvUtility ).

Note, if power-cut happens during re-naming, the original file will be intact. This isPOSIXRequirement and ubifs satisfies it.

Does ubifs support atime?

No, it does not support atime. the authors think it is not very useful in Embedded world and did not implement this. indeed most of the users do not provably want the file-system doing inode updates every time it is read.

Does ubifs support NFS?

Not so far, but it is planned to be implemented.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.