ArchWiki / F2FS
ArchWiki / F2FS
ja:F2FS ko:F2FS ru:F2FS zh-hans:F2FS
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 a flash-transition layer (FTL) to handle write distribution. It is supported from kernel 3.8 onwards.
An FTL is found in all flash memory with a SCSI/SATA/PCIe/NVMe interface https://accelazh.github.io/storage/A-Summary-On-SSD-And-FTL, opposed to bare NAND Flash and SmartMediaCards http://www.linux-mtd.infradead.org/archive/tech/nand.html.
The data contained on F2FS partitions can become unusable if the kernel version used to create the partition uses features more recent than the one running. For example, this limitation can manifest if the F2FS partition was created on a mainline kernel provided by linux yet the system has a need to downgrade to an older series of kernels provided by linux-lts. See 69363 for an historical example: since kernel 6.12 there has been a single new feature added in the kernel (device aliasing) which is not usable until f2fs-tools receives a release.
Known issues
fsck failures
F2FS has a weak fsck that can lead to data loss in case of a sudden power loss https://www.usenix.org/system/files/atc19-jaffer.pdfhttps://web.archive.org/web/20200925120546/https://archived.forum.manjaro.org/t/record-fsync-data-failed-on-f2fs-file-system-how-to-fix-foregt-the-help-i-reinstalled-its-just-easier/121051.
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 finishhttps://bbs.archlinux.org/viewtopic.php?id=245702.
This may be mitigated in the future thanks to a recent commit https://lore.kernel.org/linux-f2fs-devel/20200619184346.56536-1-jaegeuk@kernel.org/.
GRUB support
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
This article assumes the device has partitions already setup. Install f2fs-tools. Use mkfs.f2fs to format the target partition referred to as /dev/sdxY:
# mkfs.f2fs -l mylabel -i -O extra_attr,inode_checksum,sb_checksum /dev/sdxY* The -i option is included to allow more space for inodes.
* extra_attr, inode_checksum, and sb_checksum are options which help fsck.f2fs to detect and to fix some types of filesystem corruption. See mkfs.f2fs(8) for all available options.
Compression
Unlike other filesystems with inline compression, f2fs compression does not expose additional freespace by default and instead reserves the same number of blocks regardless of whether compression is enabled or not. The primary goal is reducing writes to extend flash lifetime, and potentially, a small increase in performance. See Compression Implementation in the kernel docs. F2FS_IOC_RELEASE_COMPRESS_BLOCKS can 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/sdxYWhen mounting the filesystem, specify compress_algorithm=(lzo|lz4|zstd|lzo-rle). Using 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/sdxYor add encryption capability at a later time with fsck.f2fs -O encrypt /dev/sdxY.
Mounting an F2FS file system
The file system can then be mounted manually or via other mechanisms:
# mount /dev/sdxY /mnt/fooRecommended mount options
Since F2FS is designed to be used on flash devices, compression is a good idea. You have to enable it at mkfs.f2fs time.
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/mountpointcompress_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 https://sourceforge.net/p/linux-f2fs/mailman/message/36957687. 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 f2fs-tools. To check a file system, execute
# fsck.f2fs /dev/sdxYDepending on the result, see fsck.f2fs(8) for available switches to repair inconsistencies. For example:
# fsck.f2fs -f /dev/sdxYGrow 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 print command in 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 ext4To 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/sdxYwhere /dev/sdxY is the target F2FS volume to grow. See resize.f2fs(8) for supported options.
If using GPT, the partition's GUID (seen in /dev/disk/by-partuuid/) might change, but the filesystem UUID (seen in /dev/disk/by-uuid/) should stay the same.
Troubleshooting
Remounting impossible with some options
As alluded to in Fsck#Boot time checking, the kernel keeps file systems in a read-only state by default, and it is either explicitly needed to pass the rw kernel parameter or have systemd remounting the filesystems as read-write with the systemd-remount-fs.service.
When remounting the file system from a read-only state to a read-write state, the mount -o remount,... / steps can fail for multiple reasons, which will either leave the root file system read-only or make the system unable to boot with the error message:
Failed to start Remount Root and Kernel File Systems.If the atgc option is specified in the fstab file but has not been passed as a kernel parameter, the F2FS kernel module will not permit re-mounting with an added or cleared atgc optionhttps://github.com/systemd/systemd/issues/22982https://github.com/systemd/systemd/issues/26763, either:
add the kernel parameter
rootflags=atgcto your boot loader configuration,add the kernel parameter
rwto your boot loader configuration,remove the
atgcmount option from the fstab.
Since linux 6.2, a check is made in the kernel to disable flush_merge when the file system is read-only, but it is the state of the file system before remounting that is checked. As explained in 77596, either:
add the kernel parameter
rwto your boot loader configuration,remove the
flush_mergemount option from the fstab.
Cannot set file attributes for '/var/log/journal'
If the error:
Cannot set file attributes for '/var/log/journal', maybe due to incompatibility in specified attributes, previous=0x10001000, current=0x10001000, expected=0x10801000, ignoring.is present in your journal, it can be safely ignored: it is due to systemd-tmpfiles trying to use the NOCOW file system feature that is not supported by F2FS.
To avoid the message, create:
#h /var/log/journal - - - - +C
#h /var/log/journal/%m - - - - +C
#h /var/log/journal/remote - - - - +C/etc/tmpfiles.d/journal-nocow.confThen do a daemon-reload.