Install Debian Jessie on F2FS Partition

NOTE from 2017-08-16: This guide covers only Debian 8 "Jessie" (now oldstable). There are more steps required to successfully boot newer Debian 9 "Stretch" from F2FS partition.

This article describes how to install Debian Jessie on F2FS formatted drive partition. It's very useful when Debian is going to be installed on a flash-based drive. Because Debian installer doesn't support it yet, the only way is to install it on partition with supported file system, backup all files, format the partition to F2FS and copy all files back.

Created
2015
Updated
July 9, 2016

Before Installation

I suppose that you are familiar with creating Debian installation medium and installing it on the computer's hard drive. So we only need to prepare the following things.

Installation

Install Debian as you would do normally. I prefer text-mode installation. Make sure to have /boot mounted on separate partition because F2FS doesn't have to be supported by boot loader (here it's GRUB). If you choose LVM automatic partitioning, /boot partition is created automatically. In this guide I don't use LVM, only regular partitions with default formatting options.

I recommend choosing only the base system packages (standard system utilities). It will save us some time during file copying, the remaining packages can be installed later using tasksel. You can see my Debian installation guide if you want.

Move from ext4 to F2FS

If using default format options during installation, we end up with ext4 formatted root partition. Once the installation is finished, we need to back up all files, reformat partition and move the files back. Some information can also be found in my Raspbian installation guide where I also use F2FS file system.

Install Required System Packages

We need to install some packages from the official repository for proper F2FS support. This step must be done before the file backup (otherwise the new configuration would not be transferred).

$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt-get install f2fs-tools

For F2FS to be supported at boot time, we must add F2FS module to initramfs file. Add f2fs at the end of /etc/initramfs-tools/modules file and rebuild initramfs.

$ sudo sh -c "echo f2fs >> /etc/initramfs-tools/modules"
$ sudo update-initramfs -u

Now let's modify /etc/fstab. Because the new partition format changes its UUID, we need to replace partition UUID with its mount point (find it by executing sudo blkid). Also, change ext4 to f2fs and errors=remount-ro to defaults.

File Copy And Partition Format

It is important to boot from live medium or connect the drive to another computer. I will use Debian live CD (standard, without GUI).

User/password combination is user/live. Use the following commands if you use LVM (I don't use it in this how-to, so we can skip this).

$ sudo apt-get update
$ sudo apt-get install lvm2
$ sudo modprobe dm-mod
$ sudo vgscan
$ sudo vgchange -a y [LVM-Group]
$ sudo lvs
$ sudo mount /dev/mapper/[LVM-Group]-[LVM-logical-volume-name] /mnt/drive
$ sudo mkfs.f2fs /dev/group1/volume1

We need only F2FS support to be installed.

$ sudo apt-get update
$ sudo apt-get install f2fs-tools

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/backup directory. Note: from now on your drive names may differ.

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

Create a new directory on your backup drive, for example debian.

$ mkdir /mnt/backup/debian

Now find what partitions need to be backed up. My computer's hard drive is /dev/sda.

$ sudo fdisk -l /dev/sda

To see what mount point the partition is assigned to, type mount. Mine is /dev/sda3. Now mount the drive to /mnt/drive.

$ sudo mkdir /mnt/drive
$ sudo mount /dev/sda3 /mnt/drive

Copy all files from computer's hard drive to our backup drive, unmount the source drive and format it to F2FS.

$ sudo cp -a /mnt/drive/* /mnt/backup/debian
$ sudo umount /mnt/drive
$ sudo mkfs.f2fs /dev/sda3

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

$ sudo mount /dev/sda3 /mnt/drive
$ sudo cp -a /mnt/backup/debian/* /mnt/drive

Make It Boot Properly

Let's switch to chroot environment.

sudo mount /dev/sda1 /mnt/drive/boot
sudo mount --bind /dev /mnt/drive/dev
sudo mount --bind /proc /mnt/drive/proc
sudo mount --bind /sys /mnt/drive/sys
sudo chroot /mnt/drive

Now update GRUB information. It might be useful to repeat this step once the system reboots.

$ sudo update-grub2

Now we are ready to reboot.