Espressif

LittleFS ESP32: Setting Up Flash Storage with Arduino and ESP-IDF

LittleFS on the ESP32, from partition tables and the Arduino core to the esp_littlefs component for ESP-IDF and PlatformIO.

Illustration of an ESP32-style module writing files into flash blocks

LittleFS has become the default choice for file storage on the ESP32. Whether you write sketches in the Arduino IDE or build production firmware with ESP-IDF, it gives you directories, power-loss resilience and wear leveling on the same SPI flash chip that holds your application. This article explains how the pieces fit together on Espressif hardware, from the partition table to the first file you write, and how to diagnose the problems people meet most often.

LittleFS details here were checked against the upstream littlefs repository and the documentation of the esp_littlefs component on 23 November 2026. Where behaviour depends on the version of the Arduino core or ESP-IDF you use, we say so, because those projects evolve faster than the filesystem itself.

Why LittleFS suits the ESP32

LittleFS was designed for exactly the situation an ESP32 is in: a microcontroller with a few megabytes of NOR flash, a supply that may be interrupted, and a modest amount of RAM. The upstream README promises three things, namely power-loss resilience, dynamic wear leveling and strictly bounded RAM usage, and all three matter on a Wi-Fi device that may be unplugged at any moment.

LittleFS also replaced an older default. Espressif's SPIFFS driver has no directories and, as the esp_littlefs authors explain in their README, they ported LittleFS to ESP-IDF because SPIFFS was too slow and FAT was too fragile. Their published benchmark writes five 88 KB files on an ESP32: LittleFS with its default 512-byte cache took about 6.4 seconds, FAT about 7.1 seconds, and SPIFFS about 99 seconds as it filled up.

Two ways to use LittleFS on an ESP32

LittleFS reaches ESP32 projects through two main routes, and it helps to know which one you are on before following any tutorial.

  • The Arduino core for ESP32 bundles a LittleFS library with the familiar File API used by SPIFFS and SD.
  • ESP-IDF projects add the community component joltwallet/littlefs, often called esp_littlefs, which plugs LittleFS into the ESP-IDF virtual filesystem so that standard fopen() and fprintf() calls work.

LittleFS on PlatformIO can use either route, because PlatformIO supports both the Arduino and ESP-IDF frameworks. The filesystem on flash is the same littlefs format in every case; only the wrapper differs.

Planning the partition table

LittleFS needs a data partition to live in, and the ESP32 decides where everything goes through a partition table. Most Arduino board definitions ship with schemes that already reserve a data partition, historically labelled spiffs, and the Arduino LittleFS wrapper can mount that partition. In ESP-IDF you describe partitions in a partitions.csv file.

LittleFS partitions in ESP-IDF are usually declared with a littlefs subtype. The esp_littlefs documentation shows a layout along these lines:

# Name,   Type, SubType,  Offset,   Size
nvs,      data, nvs,      0x9000,   0x5000,
otadata,  data, ota,      0xe000,   0x2000,
app0,     app,  ota_0,    0x10000,  0x1E0000,
app1,     app,  ota_1,    0x1F0000, 0x1E0000,
littlefs, data, littlefs, 0x3D0000, 0x20000,

LittleFS block size on the ESP32 matches the 4 KB flash sector, so the partition size should be a multiple of 4096 bytes. Remember that every file larger than a few hundred bytes occupies at least one whole block, which means a 128 KB partition holds at most around thirty such files once metadata is accounted for.

Sizing for your data

LittleFS needs room to manoeuvre because it never overwrites data in place. A practical rule is to plan for your expected data plus a healthy margin of free blocks. A filesystem that is nearly full still works, but allocation and metadata compaction become slower, and the wear-leveling algorithm has fewer blocks to rotate through.

Using LittleFS with the Arduino core

LittleFS in the Arduino core is a drop-in replacement for SPIFFS in most sketches. The mount call accepts an optional flag that formats the partition if mounting fails, which is what you want on a brand-new board.

#include <LittleFS.h>

void setup() {
  Serial.begin(115200);
  if (!LittleFS.begin(true)) {          // true = format if mount fails
    Serial.println("LittleFS mount failed");
    return;
  }
  File f = LittleFS.open("/hello.txt", "w");
  f.println("Hello from LittleFS");
  f.close();                             // commits the file
}

LittleFS commits data only when a file is closed or flushed, so always close files promptly. The close() call is not a formality; until it completes, the new contents are not part of the filesystem.

Uploading a data folder

LittleFS images can be generated from a data folder in your sketch directory and flashed alongside the application. In Arduino IDE 2 this is done with the community arduino-littlefs-upload plug-in, while PlatformIO users set board_build.filesystem = littlefs and run the Upload Filesystem Image task. Either approach builds the image with the correct block size and writes it to the data partition.

Using LittleFS with ESP-IDF

LittleFS is added to an ESP-IDF project as a managed component. The component registry command is a single line:

idf.py add-dependency joltwallet/littlefs

LittleFS options then appear in idf.py menuconfig under Component config → LittleFS, including cache sizes and the maximum path length. Registration mirrors the SPIFFS API closely; the esp_littlefs README says you can largely replace spiffs with littlefs in function calls.

#include "esp_littlefs.h"

esp_vfs_littlefs_conf_t conf = {
    .base_path = "/littlefs",
    .partition_label = "littlefs",
    .format_if_mount_failed = true,
};
ESP_ERROR_CHECK(esp_vfs_littlefs_register(&conf));

FILE *f = fopen("/littlefs/log.txt", "a");
fprintf(f, "boot\n");
fclose(f);

LittleFS in esp_littlefs differs from SPIFFS in a few helpful ways. There is no max_files limit, and an optional grow_on_mount setting expands an existing filesystem to fill an enlarged partition. The README notes that LittleFS filesystems can grow but not shrink in this way.

The raw API

LittleFS functions such as lfs_file_open() are hidden by default in recent esp_littlefs releases, because the POSIX layer is the intended interface. The component documents an explicit opt-in, CONFIG_LITTLEFS_EXPOSE_RAW_API, for code that needs the native API, for example to use custom attributes.

Flash encryption and security

LittleFS stores data unencrypted. On the ESP32 you can combine it with Espressif's flash encryption by marking the data partition as encrypted, which the esp_littlefs documentation covers in its test instructions. Without encryption, anyone with physical access can read the flash chip, so keep credentials out of plain files or protect them at the application level.

Troubleshooting LittleFS on the ESP32

LittleFS problems on Espressif chips usually fall into a few patterns.

Symptom Likely cause What to try
Mount fails on a new board Partition never formatted Pass true to begin() or set format_if_mount_failed
Partition not found Label mismatch with the partition table Check the label in partitions.csv and your mount call
Uploaded files missing Image built for wrong size or filesystem Rebuild the image for LittleFS with the correct partition size
Data lost after reset File not closed or flushed Call close() or fflush() before restarting
Writes slow down over time Partition nearly full Free space or enlarge the partition

LittleFS mount errors in ESP-IDF appear in the log with the esp_littlefs tag, which the component unified in 2023. Reading those lines is usually the fastest way to tell a missing partition from a corrupted one.

Over-the-air updates and the filesystem

LittleFS data survives application OTA updates on the ESP32, because the data partition is separate from the application partitions. This is a significant advantage: you can ship new firmware without losing logs or settings. If you also want to update the web assets or default files stored on LittleFS, you must either upload a new filesystem image, which replaces everything, or have the firmware download and write individual files. Many projects keep user data and shipped assets in separate directories so that an asset refresh never touches user settings.

Measuring performance on your own board

LittleFS speed on an ESP32 depends on the cache size, flash frequency and access pattern, so published benchmarks are only a guide. A simple test is to time writing a known amount of data in chunks of the size your application uses, then repeat with the partition half full. If writes are too slow, raise the cache size in menuconfig, write larger chunks less often, or move heavy logging to a separate partition so that metadata compaction never competes with it.

Preparing an ESP32 deployment

Start by mapping the flash layout for the exact board and firmware image. The application, update slots and filesystem partition must fit within the physical flash capacity without overlapping. Give the filesystem enough space for the largest expected set of files and leave room for updates and temporary data. Record the partition label and size alongside the build configuration so another developer can reproduce the layout.

During startup, check the filesystem mount result and include the error in your device logs. A failure can point to an incorrect partition label, an incompatible image or a damaged filesystem. Avoid treating every mount failure as a reason to format: if the device contains user settings or logs, formatting removes the opportunity to inspect or recover them.

When serving files over a network, verify that the requested path stays within the intended content directory. Handle missing files with a clear response and close file handles after transmission. Large transfers and concurrent requests should be tested on the target board because available memory, network buffers and other tasks all affect the number of files the application can handle at once.

Before a production update, create a repeatable test using the same partition table and filesystem image as the release build. Check a clean installation, an upgrade with existing files, a nearly full partition and a restart during a write. If the new firmware changes the format of stored settings, add a version field and a recovery strategy. Keep a backup of important data before changing partition boundaries or rebuilding the filesystem image.

Frequently Asked Questions

Is LittleFS better than SPIFFS on the ESP32?

LittleFS supports directories, is power-loss resilient and, in the esp_littlefs benchmarks, writes far faster than SPIFFS as the partition fills. SPIFFS can still be acceptable for tiny, read-mostly data.

Do I need a special partition type for LittleFS?

LittleFS in ESP-IDF projects commonly uses a littlefs data subtype, while Arduino board schemes often reuse the existing spiffs partition. What matters is that the label you mount matches the table.

Can I read LittleFS files from my computer?

LittleFS images can be read back with host tools such as littlefs-python or mklittlefs after dumping the partition with esptool. Desktop operating systems cannot mount the format natively.

How much flash should I reserve?

LittleFS needs at least one 4 KB block per non-inlined file plus free blocks for copy-on-write, so reserve noticeably more than your data size.

Does LittleFS work on the ESP32-S3 and ESP32-C3?

LittleFS works on any ESP32-family chip supported by your Arduino core or ESP-IDF version, since the component registry lists esp_littlefs as supporting all targets.

Does an OTA update erase LittleFS data on the ESP32?

LittleFS data lives in its own partition, so ordinary application OTA updates leave it untouched. Uploading a new filesystem image, however, replaces the whole partition.

Conclusion

LittleFS gives ESP32 projects dependable storage with very little effort. Choose the Arduino library or the esp_littlefs component, reserve a sensibly sized partition, mount with formatting enabled on first boot and always close your files. With those habits in place, settings, logs and web assets survive resets and power cuts. For the configuration fields behind the scenes, try the calculator on our home page, and if you are moving from SPIFFS on older boards, read our ESP8266 migration article.

Keep reading

More LittleFS articles