Install Debian 12 (Bookworm) on an F2FS Partition

This guide shows how to install Debian onto an F2FS root file system directly from the official Debian installer. F2FS stands for Flash-Friendly File System. As the name suggests, F2FS is designed for flash-based storage, such as SD cards, eMMC modules, and flash drives. F2FS achieves better performance and extends the lifetime of flash-based storage in many cases compared to other traditional file systems, such as ext4 or XFS. The F2FS format is especially useful on single-board devices (like Raspberry Pi, RockPro64, etc.) that boot from an SD card or an eMMC module. Many Android devices use F2FS too.

I developed this guide on Debian 12 (Bookworm), and I tested that it also works on Debian 11 (Bullseye). This guide doesn't work on Debian 10 (Buster) or older Debian versions because their installation image doesn't contain the necessary F2FS modules or packages. I have a different guide (called the "Copy Method") for those old Debian versions.

Created
May 24, 2023

The Idea

Debian 12 (Bookworm) can boot from a root F2FS file system, but the Debian installer still doesn't offer an option to format partitions with F2FS. This guide takes advantage of the fact that the Debian installation medium contains the necessary tools to format the storage with F2FS manually from the installer's shell.

The gist: Run the Debian installer and let it create an ext4 root partition on the disk. Before the installer starts copying system files to the partition, manually format the root partition with F2FS by invoking the mkfs.f2fs command from the installer's shell. Update the root partition information in the fstab file. Then resume the installation and continue as usual.

I also have another guide that uses a different method to install Debian on F2FS. It was useful on older Debian releases that didn't include F2FS tools in the installation image and didn't support booting from F2FS. The other guide first installs Debian onto a supported ext4 file system, and then it copies the installed system onto an F2FS partition. That approach can also be used to convert prebuilt Linux disk images to use F2FS.

You can see the other guide here: Debian F2FS — Copy Method

Disclaimer

Following the steps described in this guide leads to a bootable Debian system on my x86_64 and AArch64 UEFI-based systems. Many of the commands mentioned in this document are specific to a particular system configuration and cannot be simply copy-pasted (e.g., your disk drive letters will be different). 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 good reason to use F2FS, I recommend using file systems offered by the Debian installer. The method used in this guide is not official.

Prerequisites

I expect that you are already familiar with the process of creating a Debian installation medium, hard drive partitioning and formatting, and installing Debian. You will also need to be familiar with copying files, mounting disk partitions, and formatting disk partitions from the command line.

To install Debian on F2FS, you will need:

I tested this guide with the netinst and DVD versions of the Debian installer on x86_64 (amd64) and AArch64 (arm64) UEFI-based computers.

Start the Installer with the Main Menu Enabled

Boot from a Debian installation medium. I used a netinst image of Debian 12 (Bookworm) written to a USB flash drive. My computer uses UEFI with Secure Boot enabled. You should see the installer boot menu:

A screenshot of the Debian installer boot menu with the Install option highlighted

I prefer to use the text mode of the installer (the "Install" option instead of the "Graphical install" option). Configure the installer to show the main installer menu before each installation step so that we can enter the shell at the right moment. One way to enable the installer menu is to select the "Expert install" advanced option. Those who don't want advanced installer features can enable the menu by following these steps:

  1. Highlight the "Install" option and press the E key on the keyboard to edit the boot parameters.
  2. Add a priority=medium boot parameter to the "linux" line.
A screenshot of the Debian installer boot menu with the priority=medium boot parameter added to the linux line

Press Ctrl+X to boot. Once the installer boots, you should see the Debian installer main menu:

A screenshot of the Debian installer main menu

Proceed Until the Load of Installer Components

Begin the installation process as usual. Start with the "Choose language" option. Hit Enter to select the default options or to proceed to the following item in the installer menu. Use the arrow keys and the Tab key to navigate in the user interface. Use the space bar to make a selection in lists of options.

Stop right before the "Load installer components from installation media" option.

Load the F2FS Kernel Module

To mount a partition that contains the F2FS file system from the installer, the f2fs-modules package must be installed in the installer. First, select "Load installer components from installation media".

A screenshot of the Debian installer main menu with the Load installer components from installation media option highlighted

Then select "f2fs-modules" in the menu. Highlight the option with a space bar, then select Continue or hit the Enter key. The f2fs-modules component will allow us to mount an F2FS partition from the installer's shell in the later steps.

A screenshot of the Debian installer component installation menu with the f2fs-modules option selected

Note that after this step has been completed, the Debian installer main menu will contain additional entries.

Proceed Until Disk Partitioning

Proceed with installation until the "Partition disks" step is next. Again, you can hit the Enter key to use the default options for most questions.

Create Disk Partitions

The Debian installer doesn't offer to format partitions with the F2FS file system. In this step, I let the installer create the default partition layout with the ext4 file system for the root partition. Immediately after the partitions are created, and before the Debian system files are installed to the partition, I re-format the root partition to F2FS manually in the shell.

Select the "Partition disks" option in the Debian installer main menu:

A screenshot of the Debian installer main menu with the Partition disks option highlighted

In this guide, I use a simple automatic partition layout:

  1. Select "Guided - use entire disk",
  2. then select "All files in one partition".

The installer will propose the following partition configuration. We can't select F2FS as the file system for the root partition in the menu, so continue with the default ext4 format. We will change the format from ext4 to F2FS manually after the partitions are written to disk. Remember the device name and partition numbers! In my case, the root (/) partition is the second partition on the sda device (the device is a USB flash drive in my case). Note that the EFI System Partition (ESP) is created on UEFI systems and may be missing on systems that don't use UEFI.

A screenshot of the Debian installer with the proposed disk partitions

Although the GRUB version in Debian 12 supports booting from F2FS, according to ArchWiki, GRUB doesn't support F2FS that has extra attributes enabled. To avoid any issues, you can create a separate 512 MB /boot partition with the ext4 file system. The installer would create a separate 512MB ext2 /boot partition automatically if the LVM automatic partitioning option was selected. For simplicity, this guide doesn't use a separate /boot partition.

The installer doesn't offer F2FS, unfortunately:

A screenshot of the Debian installer with a list of supported file systems

Confirm the partition layout and proceed until the Debian installer main menu is displayed.

Re-Format the Root Partition with F2FS

Right when the "Install the base system" option is highlighted as the next step, DON'T SELECT IT!

A screenshot of the Debian installer main menu with the Install the base system option highlighted

Instead, enter the shell by selecting the "Execute a shell" option from the Debian installer main menu.

A screenshot of the Debian installer main menu with the Execute a shell option highlighted

A command line opens. The installer formatted the root partition with the ext4 file system. In the shell command line, we will erase the ext4 format and format the partition with F2FS instead.

Do not copy-paste the commands shown in this guide! Your device names and partition numbers will differ! Replace sda1 and sda2 in the commands below with the correct names on your system so that you don't accidentally erase the wrong device!

Gather Partition Information

The installer mounted the created partitions under the /target mount point. Find and remember the mount points of all partitions under the /target mount point. We already identified the device name and partition numbers in the partitioning step before (I know that I am looking for partitions on the sda device), and now we are trying to see where those partitions are mounted. You can find the mount points with the following command:

df -hT
A screenshot of the output of the df command

In my case, /dev/sda2 is the root partition that I want to format to F2FS, and it is currently mounted in /target. It currently contains an ext4 file system. The /dev/sda1 partition is the EFI System Partition, and it is mounted in /target/boot/efi. Your device names will very likely differ.

In the later steps, we will unmount all partitions under the /target mount point, format the ext4 root partition with F2FS, and then we will mount those partitions back with the same mount points.

Unmount any Nested Partitions

First, unmount any nested partitions (except the root partition) that are mounted under the /target mount point. In my case, I need to unmount the EFI partition:

umount /target/boot/efi

Backup and Unmount the Root Partition

Once the root partition is the only partition mounted under /target, back up the root partition's content. Formatting the partition with F2FS will erase its content. Since the root partition contains only about 44 KB of data at this moment, it is OK to copy the data to the Debian installer's tmpfs:

cp -a /target /target-copy

Next, unmount the root partition so that it is ready to be formatted with F2FS:

umount /target

Format the Root Partition with F2FS

Install the f2fs-tools micro-deb package that is on the Debian installation medium. This package provides the mkfs.f2fs command in the installer's shell:

anna-install f2fs-tools-udeb

Optionally, invalidate the existing ext4 file system on the root partition:

dd if=/dev/zero of=/dev/sda2 bs=1M count=100 oflag=direct

Format the root partition with F2FS:

mkfs.f2fs -f /dev/sda2

Mount the Root Partition and Restore Its Content

The root partition now contains an empty F2FS file system. Mount the newly-formatted root partition back to the /target directory:

mount -t f2fs /dev/sda2 /target

If you didn't select the f2fs-modules component in the earlier step, the partition can't be mounted from the installer's shell until you install and enable the f2fs kernel module in the installer's kernel. You can install and enable the f2fs module with these commands:

anna-install f2fs-modules
depmod
modprobe f2fs

Restore the root partition's content that we previously backed up (the dot . after the source folder name in the cp command is important!):

cp -a /target-copy/. /target

Update the fstab

The installer created a fstab file on the root partition. We need to update the fstab file because the UUID and the file system of the root partition changed when we formatted the partition with F2FS:

nano /target/etc/fstab

The original fstab file may look like this:

A screenshot of the nano text editor showing the content of the fstab file

We need to do the following changes to the line with the root (/) mount point:

Because I can't easily copy-paste the new UUID value in the shell, and I could make a typo if I tried to enter the UUID manually, I enter "newuuid" (literally) as the UUID value. In the next step, I will use sed to rewrite the "newuuid" string to the actual UUID of the partition.

In my case, this is the original line that I want to edit:

A screenshot of the original line that corresponds to the root partition in the fstab file. The line contains: UUID=066f3e6a-d44f-472e-b4ac-d72cf1457010 / ext4 errors=remount-ro 0 1

The line will look like this after my edits:

A screenshot of the edited line that corresponds to the root partition in the fstab file. The line contains: UUID=newuuid / f2fs defaults 0 1

Save the file and exit the text editor (Ctrl+O followed by Ctrl+X).

One can run a blkid command to find the new UUID of a partition:

blkid -s UUID -o value /dev/sda2
A screenshot of the output of the blkid command

I used sed to replace the "newuuid" string in the fstab file with the actual UUID value:

sed -i "s/newuuid/$(blkid -s UUID -o value /dev/sda2)/" /target/etc/fstab

Check that the fstab file now contains the correct information for the root (/) partition:

cat /target/etc/fstab

Below is the content of my updated fstab file. The line that corresponds to the root (/) partition that I formatted with F2FS now contains the correct new UUID, file system type, and mount options. I left the other lines unchanged.

A screenshot of the fstab file contents after all edits have been made

Mount any Remaining Partitions

Next, mount any remaining partitions that we previously unmounted from the /target mount point. Consult the /target/etc/fstab file for the correct mount options. In my case, I need to mount the EFI partition with an umask=0077 mount option:

mount -o umask=0077 /dev/sda1 /target/boot/efi

Check the output of df and compare it with the output that we got before. The only difference should be that the file system type of the root partition changed from ext4 to F2FS.

df -hT
A screenshot of the output of the df command

Exit the Shell

The partitioning is complete. Exit the shell and return to the installer:

exit

Install the System

Now you can select the "Install the base system" option and continue the installation. You can select the default options for the remaining questions.

A screenshot of the Debian installer main menu with the Install the base system option highlighted

When prompted which software components to install, you can either select the components now, or you can select only the "standard system utilities" and install the rest using the tasksel command from the installed system. Someone might prefer to perform a minimal installation and install the remaining software components after the installed system successfully boots.

A screenshot of the Debian installer with the Software selection window (tasksel)

The Result

Once the installation is complete, you will be prompted to reboot into the newly installed system. Once the system boots up, you can show your friends that your Debian runs from F2FS!

A screenshot of the Gnome System Monitor showing that the root partition has the F2FS file system