Install Raspbian on f2fs root

this may be combined with solve raspbian SD card corruption issues with read-only mounted root partition in order to minimize SD card corruption on a raspberry pi or if your raspberry is usually shut down regularily, you might still want to consider this because f2fs was specifically optimized for flash memory storage and supposedly should help to extend the life of such storage devices significantly.

here is a quick step by step howto how i installed raspbian from the minimal image onto an f2fs sd card

  1. download image and dd it onto the sd card
  2. boot raspberry pi from sd card and expand partition by using raspi-config
  3. now shut down using the shutdown
  4. insert sd card again into your pc. from here on, we suppose the sd card is /dev/sdf. in order to find its name on your system, you can use lsblk
  5. format 2nd partition with f2fs:
    mkfs.f2fs /dev/sdf2
  6. mount it
    mkdir /tmp/sd
    mount -t f2fs /dev/sdf2 /tmp/sd/
  7. mount second partition from image (see also mount_a_single_partition_from_a_dd_disk_image):
    mkdir /tmp/image
    kpartx -av raspbianimage.img
    mount /dev/mapper/loop0p2 /tmp/image
  8. now copy the os to the sd card
    rsync -aHvx /tmp/image/ /tmp/sd/
  9. find the partition uuid by using blkid and copy the “PARTUUID” number
  10. edit fstab:
    nano /tmp/sd/etc/fstab

    and replace ext4 in the root mount line with f2fs, also update the PARTUUID with the one you found in the previous step.

  11. unmount it all again
    umount /tmp/sd /tmp/image
  12. mount boot partition and edit boot options:
    mount /dev/sdf1 /tmp/sd
    nano /tmp/sd/cmdline.txt

    and now replace ext4 with f2fs in here and paste the correct PARTUUID as well.

  13. cleanup:
    umount /tmp/sd
    rmdir /tmp/sd /tmp/image
  14. insert the sd card into your raspberry pi and finally start configuring it :)