F2FS (Flash-Friendly File System) is a file system intended for NAND-based flash memory equipped with Flash Translation Layer. Unlike JFFS or UBIFS it relies on FTL to handle write distribution. It is supported from kernel 3.8 onwards.
If power losses are frequent, consider an alternative file system.
Long running fsck delays boot
If the kernel version has changed between boots, the fsck.f2fs utility will perform a full file system check which will take longer to finish.
This may be mitigated in the future thanks to a recent commit .
While GRUB supports F2FS since version 2.0.4, it cannot correctly read its boot files from an F2FS partition that was created with the
extra_attr flag enabled (for more details, see GRUB#Unsupported file systems).
Creating a F2FS file system
# mkfs.f2fs -l mylabel -O extra_attr,inode_checksum,sb_checksum /dev/sdxY
f2fs.fsckto detect and to fix some types of filesystem corruption. See for all available options.
F2FS_IOC_RELEASE_COMPRESS_BLOCKScan be used to expose unused space on a per-file basis, but it makes the file immutable in the process.
To use compression, include the
compression option. Example:
# mkfs.f2fs -l mylabel -O extra_attr,inode_checksum,sb_checksum,compression /dev/sdxY
When mounting the filesystem, specify
compress_extension=txt will cause all txt files to be compressed by default.
In order to tell F2FS to compress a file or a directory, use :
$ chattr -R +c [FOLDER]
File-based encryption support
Since Linux 4.2, F2FS natively supports file encryption. Encryption is applied at the directory level, and different directories can use different encryption keys. This is different from both dm-crypt, which is block-device level encryption, and from eCryptfs, which is a stacked cryptographic filesystem. To use F2FS's native encryption support, see the fscrypt article. Create the file system with
# mkfs.f2fs -l mylabel -O extra_attr,inode_checksum,sb_checksum,encrypt /dev/sdxY
or add encryption capability at a later time with
fsck.f2fs -O encrypt /dev/sdxY.
Mounting a F2FS file system
The file system can then be mounted manually or via other mechanisms:
# mount /dev/sdxY /mnt/foo
Recommended mount options
Since F2FS is designed to be used on flash devices, compression is a good idea. You have to enable it at
A few mount options can be used to improve things slightly.
# mount -o compress_algorithm=zstd:6,compress_chksum,atgc,gc_merge,lazytime /dev/sdxY /mnt/foo
compress_algorithm=zstd:6tells F2FS to use zstd for compression at level 6, which should give pretty good compression ratio.
compress_chksumtells the filesystem to verify compressed blocks with a checksum (to avoid corruption)
atgc,gc_mergeEnable better garbage collector, and enable some foreground garbage collections to be asynchronous.
lazytimeDo not synchronously update access or modification times. Improves IO performance and flash durability.
Implementation of discard
By default, F2FS is mounted using a hybrid TRIM mode which behaves as continuous TRIM. This implementation creates asynchronous discard threads to alleviate long discarding latency among RW IOs. It keeps candidates in memory, and the thread issues them in idle time . As a result of this, users wanting periodic TRIM will need to implicitly set the
nodiscard mount option in
/etc/fstab or pass it to mount if mounting manually.
Checking and repair
Checking and repairs to F2FS file systems are accomplished with
fsck.f2fs provided by . To check a file system, execute
# fsck.f2fs /dev/sdxY
Depending on the result, seefor available switches to repair inconsistencies. For example:
# fsck.f2fs -f /dev/sdxY
Grow an F2FS file system
When the filesystem is unmounted, it can be grown if the partition is expanded. Shrinking is not currently supported.
First use a partition tool to resize the partition: for example, suppose the output of the
parted console is the following:
Number Start End Size File system Name Flag 1 1049kB 106MB 105MB fat32 EFI system partition boot, esp 2 106MB 11,0GB 10,9GB ext4 3 11,0GB 12,3GB 1322MB f2fs 4 31,0GB 31,3GB 261MB ext4
To resize the
f2fs partition to occupy all the space up to the fourth one, just give
resizepart 3 31GB and
exit. Now expand the filesystem to fill the new partition using:
# resize.f2fs /dev/sdxY
/dev/sdxY is the target F2FS volume to grow. See for supported options.
/dev/disk/by-partuuid/) might change, but the filesystem UUID (seen in
/dev/disk/by-uuid/) should stay the same.