Contents
F2FS is a FileSystem for Linux optimized for Flash storage. It was originally introduced in kernel v3.8, on 2012-12-20.
F2FS is popular on portable devices such as smartphones and tablets and uncommon on desktops and servers.
For more information about it, follow the links in the See Also section.
Things you need to know
F2FS is a log-structured file system designed to accommodate the characteristics of storage devices that use NAND flash memory, like Secure Digital (SD) and eMMC drives.
F2FS supports:
- Transparent file compression using LZO, LZ4 and zstd
- File-based encryption
- Online defragmentation
- TRIM
- Atomic operations and recovery from power loss or crash
Status
F2FS is available in Buster, Testing and Unstable
Usage
Enabling compression
To create a compressed FS, f2fs-tools at version >= 1.14.0-1 is required
Note that compression, by default, does not reduce the number of blocks reserved for a file, and filesystem space is consumed at the same rate as if compression was disabled for compressed files. Rather than allowing storage of additional data, as inline compression permits on other filesystems, F2FS uses compression to reduce the amount of writes, thus extending disk life. Kernels as of 5.10 support ioctl(F2FS_IOC_RELEASE_COMPRESS_BLOCKS) which marks a compressed file as immutable and releases the unused, reserved blocks. See F2FS Compression implementation notes
1 dev=/dev/CHANGEME
2 mnt=/mnt/CHANGEME
3 # Enable compression on FS creation
4 sudo mkfs.f2fs -f -O extra_attr,compression $dev
5 # (or enable encryption and compression)
6 # sudo mkfs.f2fs -f -O encrypt,extra_attr,compression $dev
7
8 # Also at mount time
9 sudo mount -o compress_algorithm=zstd $dev $mnt
10
11 ## Compression demo ##
12 # create a directory and enable compression on it
13 sudo mkdir $mnt/comp
14 sudo chattr -R -V +c $mnt/comp
15
16 # Write a compression-friendly file
17 sudo cp /etc/dictionaries-common/words $mnt/comp
18 # du shows the uncompressed size
19 du -h $mnt/comp/words
20 # notice: df might be misleading
21 # Show F2FS status:
22 sudo cat /sys/kernel/debug/f2fs/status
See also
Wikipedia's article about F2FS
WikiPedia: F2FSManual pages: mkfs.f2fs(8)
CategoryKernel | ?CategoryFileSystem | CategorySystemAdministration