Languages & RTOS

LittleFS Zephyr: Kconfig, fstab and Mounting Explained

LittleFS is a first-class filesystem in Zephyr. This article covers Kconfig, devicetree fstab nodes and the messages you see on first boot.

Illustration of a devicetree node wired to a mounted storage partition

LittleFS is a first-class filesystem in the Zephyr real-time operating system. Instead of writing block device callbacks yourself, you enable a few Kconfig options, describe the mount in devicetree and let Zephyr's flash map and filesystem layer do the rest. This article explains each piece: the Kconfig symbols, the zephyr,fstab,littlefs devicetree binding, partitions, automounting and the log messages you will see on first boot.

LittleFS integration details here come from the Zephyr documentation for its LittleFS sample and devicetree bindings, and from the upstream littlefs repository, checked on 23 November 2026. Zephyr evolves quickly, so compare property names with the documentation for the release you build against.

How Zephyr wraps LittleFS

LittleFS in Zephyr sits beneath the generic filesystem API in zephyr/fs/fs.h. Your application calls functions such as fs_open(), fs_write() and fs_close(), and Zephyr routes them to LittleFS for paths under its mount point. Underneath, Zephyr's flash map supplies the block device, either on-chip flash, external SPI or QSPI flash, or, for block devices such as SD cards, a disk driver.

LittleFS configuration values that you would normally place in struct lfs_config appear instead as Kconfig defaults or devicetree properties. That makes it easy to keep geometry alongside the hardware description of each board.

Step 1: enable the Kconfig options

LittleFS needs flash support and the filesystem subsystem. A typical prj.conf contains:

CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y

LittleFS defaults such as read size, program size, cache size, lookahead size and block cycles can be set globally through options like CONFIG_FS_LITTLEFS_READ_SIZE and CONFIG_FS_LITTLEFS_CACHE_SIZE. The devicetree binding documentation states which Kconfig option each property corresponds to.

Step 2: define a storage partition

LittleFS needs a flash partition. Many Zephyr board definitions already provide one labelled storage, and the LittleFS sample uses it: the sample's README explains that the partition labelled "storage" is used, and that if it does not contain a compatible littlefs filesystem its contents are replaced by an empty one. If your board lacks such a partition, add one in a devicetree overlay under the flash controller's partitions node.

LittleFS partitions must start and end on erase-block boundaries, because each LittleFS block maps to one or more erasable sectors.

Step 3: describe the mount with fstab

LittleFS mounts can be declared in devicetree using an fstab node with the zephyr,fstab,littlefs compatible. The binding requires a mount point, a partition reference and the core geometry values.

/ {
    fstab {
        compatible = "zephyr,fstab";
        lfs1: lfs1 {
            compatible = "zephyr,fstab,littlefs";
            mount-point = "/lfs1";
            partition = <&lfs1_part>;
            automount;
            read-size = <16>;
            prog-size = <16>;
            cache-size = <64>;
            lookahead-size = <32>;
            block-cycles = <512>;
        };
    };
};

LittleFS properties in this binding follow the same rules as the C library. The documentation describes reasonable defaults of 16 bytes for read and program sizes and 64 bytes for the cache, and states that the cache must be a multiple of the read and program sizes and a factor of the block size. For the lookahead buffer, the binding notes that each byte tracks eight blocks, that the value must be a multiple of 8, and that 32 is a reasonable default.

Optional properties

LittleFS fstab nodes support several useful flags documented in the binding:

  • automount mounts the filesystem during initialisation.
  • read-only mounts without write access.
  • no-format prevents automatic formatting if the mount fails.
  • disk-version keeps backward compatibility with older littlefs versions sharing the same major disk version.

LittleFS automounting is convenient, but no-format deserves thought for products in the field. Without it, a mount failure leads to formatting, which is right on first boot but destructive if the failure has another cause.

Step 4: use the filesystem API

LittleFS files are then accessed through Zephyr's generic calls. A boot counter, like the one in the official sample, looks roughly like this:

#include <zephyr/fs/fs.h>

struct fs_file_t f;
uint32_t boot_count = 0;

fs_file_t_init(&f);
fs_open(&f, "/lfs1/boot_count", FS_O_CREATE | FS_O_RDWR);
fs_read(&f, &boot_count, sizeof(boot_count));
boot_count++;
fs_seek(&f, 0, FS_SEEK_SET);
fs_write(&f, &boot_count, sizeof(boot_count));
fs_close(&f);

LittleFS commits on fs_close() or fs_sync(), exactly as in the C API, so close files after important writes.

Reading the first-boot messages

LittleFS produces log messages on a fresh partition that look alarming but are normal. The Zephyr sample documents a sequence like this:

<inf> littlefs: LittleFS version 2.0, disk version 2.0
<err> littlefs: Corrupted dir pair at 0 1
<wrn> littlefs: can't mount (LFS -84); formatting
<inf> littlefs: filesystem mounted!
<err> fs: failed get file or dir stat (-2)

LittleFS reports error -84 (LFS_ERR_CORRUPT) because there is no filesystem yet; Zephyr then formats the partition. The final -2 (ENOENT) simply means the boot-count file does not exist yet. The sample's documentation explains both as expected. To force a fresh filesystem during development, the sample offers CONFIG_APP_WIPE_STORAGE.

Using LittleFS on SD and MMC cards

LittleFS can also run on block devices in Zephyr. The sample includes a configuration for SD and MMC cards, which, per its documentation, requires preparing the card with a littlefs filesystem on the host using the lfs FUSE program from littlefs-fuse. The Zephyr documentation describes testing this on a Nucleo H743ZI board, which makes it a practical route for STM32 users too.

Zephyr in vendor SDKs

LittleFS reaches many developers through vendor distributions of Zephyr, such as Nordic's nRF Connect SDK. On those platforms the same Kconfig and devicetree approach applies, and external QSPI flash parts on development kits are common targets for the filesystem.

Troubleshooting

Symptom Likely cause Fix
-84 then formatting on first boot Partition has no filesystem Normal; no action needed
-84 on every boot Partition repeatedly erased or wrong geometry Check other users of the partition and the fstab values
-12 (ENOMEM) when mounting or opening Caches or file handles exceed configured memory Reduce cache sizes or raise the related memory limits
Build error about lookahead Value not a multiple of 8 Use 8, 16, 32 and so on
Mount point not found fstab node missing or automount disabled Add the node or mount manually with fs_mount()

Mounting manually instead of automounting

LittleFS does not have to be mounted automatically. Some applications prefer to mount in code so that they can decide what to do if mounting fails, for example by reporting an error over a debug channel before formatting. Zephyr supports this by declaring the mount point in a struct fs_mount_t with the LittleFS filesystem type and a pointer to a storage configuration, then calling fs_mount(). The LittleFS sample in the Zephyr tree shows both approaches, and the code is a useful template.

LittleFS statistics are available through fs_statvfs(), which reports block size and free blocks. Logging these at boot, as the official sample does, is a quick way to confirm that the partition size and geometry are what you intended.

Partition planning on real boards

LittleFS partitions often share a flash device with MCUboot images in Zephyr products. Make sure the storage partition does not overlap the bootloader's primary or secondary slots, and remember that resizing slots later can move or shrink the storage area. Changes to partition layout should be treated as a migration, with data backed up or deliberately discarded, rather than a silent configuration tweak.

Thread safety and multiple tasks

LittleFS access in Zephyr goes through the filesystem subsystem, which serialises operations on a mount so that several threads can use the API without corrupting state. Even so, design matters: two threads writing the same file still need application-level coordination, and long writes in one thread delay file access in others. A common pattern is a dedicated storage thread that receives messages from the rest of the system and performs all writes, which keeps timing predictable and makes power-loss behaviour easier to reason about.

Validating the Zephyr configuration

When a filesystem fails to mount, inspect the entire configuration path rather than changing one option at random. Confirm that the intended storage device is enabled, that the partition exists at the expected offset and that the filesystem mount entry refers to the correct partition. The final generated configuration and devicetree are useful for checking the values that reached the build.

Reserve enough space for both application data and routine updates. A filesystem that is almost full can make ordinary writes fail, so test the largest realistic set of files and monitor remaining capacity. Keep the partition definition consistent across bootloader, application and upgrade builds; changing offsets without a migration plan can make existing data inaccessible.

After mounting, test the application's file operations on the target hardware. Create a file, write a known payload, close it, restart and verify the result. Repeat the test with a missing file, insufficient space and a simulated interruption. Log the operation and returned error so a storage failure can be distinguished from a path or permission mistake.

If several threads use the filesystem, define which component owns each file and how concurrent updates are coordinated. Avoid performing long operations in a time-critical path without measuring their effect on the rest of the system. For deployed devices, keep a recovery procedure and a backup for important settings. Treat formatting as a deliberate maintenance operation because it removes existing files from the selected storage area.

Frequently Asked Questions

How do I enable LittleFS in Zephyr?

LittleFS is enabled with CONFIG_FILE_SYSTEM=y and CONFIG_FILE_SYSTEM_LITTLEFS=y, together with flash and flash map support.

Is the -84 error on first boot a problem?

LittleFS returns -84 when no filesystem exists. On a new partition Zephyr formats it and continues, which the official sample describes as normal.

What lookahead size should I use in Zephyr?

LittleFS lookahead in the Zephyr binding must be a multiple of 8; the documentation suggests 32 as a reasonable default.

Can I keep compatibility with older LittleFS versions?

LittleFS fstab nodes in recent Zephyr releases accept a disk-version property to keep compatibility with older minor versions sharing the same major disk version.

Does LittleFS work on SD cards with Zephyr?

LittleFS can be used on SD and MMC cards in Zephyr, but the card must first be prepared with a littlefs filesystem on a host machine.

Is LittleFS thread-safe in Zephyr?

LittleFS operations pass through Zephyr's filesystem layer, which serialises access per mount, but coordinating writes to the same file remains the application's job.

Where do the LittleFS geometry values come from in Zephyr?

LittleFS geometry in Zephyr comes from the fstab devicetree properties when a node exists, or from the CONFIG_FS_LITTLEFS_* Kconfig defaults otherwise. The block size itself is derived from the flash device's erase page layout reported by the flash driver.

Can I use more than one LittleFS mount?

LittleFS mounts can be declared multiple times in Zephyr, one fstab node per partition, each with its own mount point such as /lfs1 and /lfs2.

Conclusion

LittleFS in Zephyr is mostly configuration: enable the Kconfig symbols, point an fstab node at a partition and let automount handle the rest. Learn to recognise the harmless first-boot messages, choose no-format deliberately for production, and keep geometry values within the documented rules. For a deeper look at those rules, see our STM32 porting article or the configuration calculator on the home page.

Keep reading

More LittleFS articles