Debian Root Drive on an F2FS Filesystem

F2FS is a filesystem that was initially developed by Samsung for flash devices.  I’ve seen several benchmarks (e.g. xda-developers) that seemed to imply that F2FS was faster than EXT4 on flash devices, so I decided to try it, as my EXT4 USB was very slow.  Writing this on an F2FS Debian root on a USB flash drive right now, I can attest to the fact that it is much snappier than a similar installation using EXT4.

As of this writing, Grub2 doesn’t support booting to an F2FS partiton, so the trick to getting an F2FS root is to have an EXT4 partition for your /boot, which loads the drivers and chroots into your root.

I haven’t worked out all the kinks yet, but here is the basic outline:

  1. Partition your flash drive with 3 partitions:
    1. /dev/sdX1 as EXT4 – your boot partition
    2. /dev/sdX2 as F2FS – your root (/) partition
    3. /dev/sdX3 as your swap
  2. Debootstrap /dev/sdX2, chroot, and mount sdX1 under /boot
    1. More specifically, I mounted sdX1 under /mnt, and then bind-mounted the /mnt/boot subfolder to /boot (mount --bind /mnt/boot /boot).  You might not have to do this; I’d think it should work with just /boot, but I haven’t tested it.  I copied /vmlinuz and /initrd.img from the host to /mnt/, so Grub would be able to find them easily.
  3. In your chroot, make sure you have /dev bind-mounted from the host, and have mounted /proc, /sys, and /dev/pts
  4. apt-get all of the packages you need, configure the system, etc.
  5. Be sure you change the root password with passwd, or create a new user account with sudo privileges!  Otherwise, you won’t be able to log into your system (guilty as charged).
  6. Build the f2fs driver into your initramfs
    1. echo f2fs >> /etc/initramfs-tools/modules
    2. update-initramfs -u
  7. apt-get install grub2 (if you haven’t already), and then do a grub-install /dev/sdX
  8. Do an update-grub2
  9. Make sure you have updated your /etc/fstab to mount the proper drives.  I like to use blkid to get the UUIDs of the drives for my fstab, but that’s up to you.
  10. Unmount everything and try to boot
  11. For some reason, Grub completely found the wrong hard drive, which brought me to a grub rescue> prompt.  I made it boot by using the following (my USB was on hd0 — YMMV):
    1. set root=(hd0,msdos1)
    2. set prefix=/boot/grub
    3. insmod normal
    4. normal
  12. Now you should have the normal Grub menu.  Then, I had to manually edit the default menu item, by pressing e.
    1. I replaced all instances of hd1,msdos1 with hd0,msdos1, and for some reason it was mounting my F2FS partition as ro — I changed that to rw.
  13. Now hit Ctrl+X to boot
  14. If all goes according to plan, this should boot into the Debian system.
  15. I re-installed Grub for good measure: grub-install /dev/sdX && update-grub2
  16. Now, I had to manually edit /boot/grub/grub.cfg to make the changes I specified above — replacing hd1,msdos1 with hd0,msdos1, and setting my F2FS partition as rw
    1. NOTE: these changes will be overridden whenever update-grub2 is run (either by you or by updating your packages).  This is why I said I “haven’t worked out all the kinks” yet.  This is only a temporary fix.