There is an updated version of this article for newer Debian releases.

Install Debian 10 Buster on an F2FS Partition

This article describes the necessary steps to install Debian 10 (Buster) on an F2FS-formatted storage partition. F2FS stands for Flash-Friendly File System. As the name suggests, F2FS is designed for flash-based storage, such as SD cards, flash drives, or SSDs. In some cases, it outperforms other traditional file systems, such as ext4 or XFS, both in performance and in the longevity of the flash device.

This guide is an updated and polished version of my previous notes, which I originally wrote many years ago for then-new Debian 8 (Jessie). The principle remains the same; the most significant change is the addition of a few more kernel modules to initramfs.

Updated
February 13, 2020

The Idea

Debian installer still doesn't offer an option to format partitions with an F2FS file system during the installation. The easiest way to get Debian running from F2FS-formatted storage seems to be performing an installation on partitions with supported file systems, backing up all files, formatting the partitions to F2FS, and copying all files back.

Disclaimer

Following the steps described in this guide led to a bootable Debian 10 on my system. Most of the commands mentioned in this document are specific to a particular system configuration and cannot be simply copy-pasted. Incorrect usage of the commands can lead to data loss. I am not responsible for any data loss that occurs as a consequence of incorrect usage of any information provided in this guide.

Unless you have a solid reason to use F2FS, I recommend sticking with the file systems offered by the Debian installer instead. The method mentioned here is not official. The very reason why I am updating this guide is that an update to the F2FS driver in the Linux kernel a few years ago brought additional kernel module requirements, making the systems set up according to my previous guide to F2FS unbootable. Also, F2FS may not work with some extended file system attributes, such as those used by SELinux.

Before Installation

I suppose that you are already familiar with the process of creating a Debian installation media, hard drive partitioning, and installing Debian on the computer's hard drive. To successfully install Debian on F2FS-formatted storage, we need to prepare the following:

Installation

Install Debian as you would normally do. Make sure to have /boot on a separate partition because F2FS may not be supported by the GRUB boot loader. If you choose LVM automatic partitioning, an ext2-formatted /boot partition is created automatically. In this guide, I don't use LVM.

In the Software selection screen, I recommend selecting only the "standard system utilities", leaving all other package groups unchecked. This will reduce the amount of data to be copied in later steps. The remaining package groups can be installed later using the tasksel command. You can see my Debian installation guide if you want.

My Partition Layout

I followed the "Guided partitioning", "Guided - use entire disk", "All files in one partition" options. The following partition layout was proposed by the installer:

  1. ESP (EFI system partition)
  2. / (ext4)
  3. swap

Note that the ESP partition may not be present on legacy BIOS systems. I modified the partition proposal by adding a separate partition for /boot:

  1. ESP (EFI system partition)
  2. /boot (256MB, ext4)
  3. / (the remaining capacity, ext4 -- this is where I would select F2FS if the installer allowed me to)
  4. swap

Prepare the System for Booting From F2FS

Once the installation is finished, boot into the newly-installed Debian system.

Install Additional Packages

I recommend installing the latest updates, if available:

$ sudo apt update
$ sudo apt full-upgrade

Next, install the f2fs-tools package which provides tools for managing F2FS file system format:

$ sudo apt update
$ sudo apt install f2fs-tools

Add Necessary Modules to initramfs

In order to successfully mount a root F2FS partition during boot time, some additional modules need to be added to the initramfs image. In my previous guide related to Debian 8 Jessie, the only needed module was f2fs. Because F2FS introduced CRC checksums and additional security features, more modules are needed now. I haven't verified whether all of these modules are absolutely necessary, I took the list from the Arch Linux Forum.

Using your favorite text editor, such as vi or nano, add the following lines to the end of /etc/initramfs-tools/modules file:

f2fs
fscrypto
crc32-pclmul
crc32c_generic
crc32c-intel
crc32_generic
libcrc32c

Next, rebuild the initramfs image.

$ sudo update-initramfs -u

Modify fstab

By default, partitions are identified by their UUIDs in the /etc/fstab file. Because formatting a partition format will change its UUID, there are two ways how to proceed:

To stay on the safe side, I decided for the former. The sudo blkid command helps identify which UUID belongs to which partition. I changed the original line:

UUID=de5ef06e-afc7-425c-849d-4fbb272d7d4b /               ext4    errors=remount-ro 0       1

I modified it to look like this:

sda4 /               ext4    errors=remount-ro 0       1

I recommend performing a reboot to make sure the new configuration is correct.

Identify Partition Mount Points

An lsblk command lists partitions and their mount points. This information will be useful when mounting the partitions to a chroot environment later. This is my output:

In my case, the root partition is located after the swap partition in the Partition table, even though it is physically before it. This is because it was created later.

Use Another System to Convert the ext4 Partition to F2FS

Now we have a Debian system installed on an ext4-formatted root partition, but prepared to mount F2FS partitions on boot. The next step is to back up all files on the root partition (while preserving all permissions and other file attributes), format the partition to F2FS, and move all the files back. Some information can also be found in my Raspbian installation guide, where I also used an F2FS file system.

The steps of copying the data from/to the system partition cannot be done online to a running system. You can either connect the system drive to another Linux system or boot another operating system. I booted the text-only Debian Live medium (debian-live-10.3.0-amd64-standard.iso).

Install F2FS Utilities In the Live Session

As I already stated, I used a Debian Live media without a GUI. In order to be able to format a partition with F2FS, the F2FS tools needed to be installed in the live session.

$ sudo apt update
$ sudo apt install f2fs-tools

Prepare and Mount a Backup Drive

Prepare your backup drive with sufficient capacity to hold data from all partitions which you are going to format. Plug it in the computer and mount it, for example, in /mnt/flash directory. Note: from now on, your drive names may differ from mine. I used a USB flash drive located at /dev/sdb.

$ sudo mkdir /mnt/flash
$ sudo mount /dev/sdb1 /mnt/flash

Create a new directory on the backup drive named, for example, debian. The contents of the whole system partition will later be copied in this folder.

$ mkdir /mnt/flash/debian

Locate the Partition That Will Be Converted to F2FS

Using lsblk, fdisk, and other tools, locate the partition that you want to convert to F2FS and make sure the other partitions' information matches our previous findings. My computer's hard drive is /dev/sda and the partition information can be found with the following command.

$ sudo fdisk -l /dev/sda

As a reference, here is my configuration:

Backup, Format to F2FS, Restore!

Now we can finally begin converting the partition from ext4 to F2FS.

Do not blindly copy-paste the provided commands. Your device and partition numbers may differ from mine!

Mount the partition (it currently contains an ext4 file system) to a newly-created /mnt/root directory.

$ sudo mkdir /mnt/root
$ sudo mount /dev/sda4 /mnt/root

Copy all files from the partition to our prepared directory on the backup drive. Make sure to copy all files and preserve all file attributes. Notice that there is a dot at the end of /mnt/root/., as it will help include any hidden files in the source directory and the permissions of the directory itself.

$ sudo cp -a /mnt/root/. /mnt/flash/debian
$ sudo umount /mnt/root

Next, unmount the drive, and optionally invalidate the previous file system by choosing one of the commands below.

$ sudo dd if=/dev/zero of=/dev/sda4 bs=1M count=100
$ sudo wipefs -a /dev/sda4
$ sudo blkdiscard -v /dev/sda4 # mkfs.f2fs will also discard

Finally, format the partition with an F2FS file system. If a previous file system is detected, a -f parameter needs to be passed to the command. I also noticed that the mkfs.f2fs program would automatically issue discard (TRIM) on the partition.

$ sudo mkfs.f2fs /dev/sda4

Now mount the drive again and copy all previously backed-up files back on it.

$ sudo mount /dev/sda4 /mnt/root
$ sudo cp -a /mnt/flash/debian/. /mnt/root

Make the System Bootable Again!

The installed system will need to know that the partition file system changed from ext4 to F2FS. The fstab and GRUB information will need to be updated. Start by creating a chroot environment. As a reminder, my device and partition numbers likely differ from yours, and are as follows:

Let's switch to chroot environment. All of these steps are still done from the live system booted from the Debian Live media. The /dev/sda4 partition has already been mounted to /mnt/root.

sudo mount /dev/sda2 /mnt/root/boot
$ sudo mount /dev/sda1 /mnt/root/boot/efi
$ sudo mount --bind /dev /mnt/root/dev
$ sudo mount --bind /proc /mnt/root/proc
$ sudo mount --bind /sys /mnt/root/sys
$ sudo mount --bind /run /mnt/root/run
$ sudo chroot /mnt/root

First, modify /etc/fstab file. In the entry related to the now F2FS-formatted partition, perform these changes:

In my case, the relevant line now looks like this:

sda4 /               f2fs    defaults 0       1

With a new UUID, it looks like this:

UUID="d8e59df1-b8c4-4862-9017-1f66e6e6a7dc" /               f2fs    defaults 0       1

Next, update GRUB information. It might be useful to repeat this step once the system reboots into the installed system.

# update-grub2

Now we are ready to reboot into the installed system that now uses an F2FS file system.

Post-Installation Steps

When the installed system successfully boots, you can celebrate by installing the remaining package groups that we left unselected during the installation in order to reduce the size of the copied system.

$ sudo tasksel

If the storage device supports discard (TRIM) operation, I would recommend running fstrim. But I noticed that a discard mount option is enabled by default on F2FS, so there is no need to run fstrim periodically.

Now you can show off to your friends that your file system type is f2fs:

A screenshot of the Monitor app window showing that the file system type is F2FS.