Improving Ubuntu 16.04 with an F2FS root filesystem:

Started by mahesh, Dec 05, 2023, 06:26 AM

Previous topic - Next topic

mahesh

Moderator comment:

Do not use this "tutorial" - see close note below in post #5


Improving Ubuntu 16.04 with an F2FS root filesystem:


F2FS offers major benefits and advantages over other filesystems when used on a flash device like an SSD.

Ubuntu has had the ability to read F2FS for quite some time (12.04), but the provided installers (even 16.04) don't have F2FS modules loaded;
One cannot select F2FS partitions as an install destination even if they are created beforehand...


Thankfully, we can still use an F2FS root without too much effort, we just need the kernel to load the f2fs module at boot, then point grub to an f2fs partition.
There may be other ways to accomplish this, but I was not able to find any working solutions via Google-fu.


Start the ubuntu installer normally,


At the selection for install destination, select 'Something else', then manually partition:


sda1 /boot 512MB ext4
sda2 /swap 8GB (Whatever ram size is)
sda3 DNU 10GB RAW (prevents you having to move it or have a gap later when you delete the ext4 partition)
sda4 / 10GB ext4


If you have a separate disk installed:

sda1 /boot 512MB ext4
sda2 /swap 8GB
sda3 DNU Rest of drive space
sdb1 / 10GB ext4


If you have a separate disk, be sure to adjust the mount points listed below.


Complete the installation normally, then reboot


Editing the grub defaults is optional, but if you mess up somewhere you'll be able to see where things went kerfuffle.
leaving the splash and quiet options on mean you'll only see the error and not what was happening before it.


Open (alt+f2, gksudo gnome-terminal) or switch to a terminal (Ctrl+F1-F5, F6 returns to GUI)

Code:
        sudo gedit /etc/default/grub
                  GRUB_DEFAULT=0
Comment out the hidden grub menu setting so we can see the damned thing;
You might have to do this before you are able to start a grub command line to run vbeinfo.
Make sure you update-grub before you reboot if this is the case.

Code:
            #GRUB_HIDDEN_TIMEOUT=0
            #GRUB_HIDDEN_TIMEOUT_QUIET=true
Turn down the timeout. 3 seconds is AGES. 10 is for people who have the reaction time of a corpse.
Code:
            GRUB_TIMEOUT=3
            GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
            GRUB_CMDLINE_LINUX_DEFAULT="text"
            GRUB_CMDLINE_LINUX=""
uncomment the graphics mode line.
change the entry to whatever optimal resolution your display supports. you can get this from the grub command line 'vbeinfo'
Code:
GRUB_GFXMODE=1366x768x32
uncomment the text only line
Code:
GRUB_TERMINAL=console
save the grub defaults file
Code:
update-grub
to pull the new defaults into the grub configuration on /boot

now we install f2fs and setup the module in initramfs

The next two lines prepare the current installation to boot a F2FS root.
We want to do this before we copy the installation to the F2FS root.
Without the f2fs module, grub will fail to mount the f2fs partition, leaving you stuck at an initramfs prompt.

Update apt's sources, then install f2fs-tools and gparted

Code:
sudo apt update && sudo apt install f2fs-tools gparted
Tell initramfs to load the F2FS module at boot (rather than on demand)

Code:
sudo echo f2fs >> /etc/initramfs-tools/modules && sudo update-initramfs -u
        sudo reboot
now that the installation is ready for f2fs boot, re-enter the terminal

Code:
sudo gparted
select sda3, format to F2FS the same size or larger than your ext4 partition,
copy the UUID from the partition information dialog
now we add the UUID to the fstab
Code:
sudo gedit /etc/fstab
comment out the ext4 line
paste the UUID you copied (or run blkid to find it) followed by
Code:
/    f2fs    rw,relatime,background_gc=on,user_xattr,acl,active_logs=6    0    0
this is what my fstab looks like
Code:
       # /etc/fstab: static file system information.
        #
        # Use 'blkid' to print the universally unique identifier for a
        # device; this may be used with UUID= as a more robust way to name devices
        # that works even if disks are added and removed. See fstab(5).
        #
        # <file system>    <mount point>    <type>    <options>    <dump>    <pass>
        # / was on /dev/sda4 during installation
        #UUID=71f42e33-6984-4905-9932-17cd4adb7b41    /    ext4    errors=remount-ro    0    1
        UUID=84e54b79-8671-4acb-9dbc-f89b17667cf6    /    f2fs    rw,relatime,background_gc=on,user_xattr,acl,active_logs=6    0    0
        # swap was on /dev/sda2 during installation
        UUID=0a3b409b-f7bf-4a22-a05f-0dc35e1bb111    none    swap    sw    0    0
if you want to check root filesystem at boot, change trailing 0 to 1
if you just want to wing it and check at boot yourself, touch /forcecheck to make init clean the filesystem at next boot. util-linux will delete the forcecheck file when it finishes.

We can't update-grub yet because the f2fs partition is still empty; grub-probe will ignore it for obvious reasons.
So, we need to copy the current root to the new f2fs root;

Reboot to Live USB/CD
switch to a terminal.

make dirs and mount our stuff to them
Code:
        sudo mkdir /media/ext4
        sudo mkdir /media/f2fs
        sudo mount /dev/sda4 /media/ext4
        sudo mount /dev/sda3 /media/f2fs
copy the installation to the f2fs partition
Code:
sudo cp -a /media/ext4/* /media/f2fs
The following lines set up the chroot so update-grub doesn't misinterpret our intention (or just fail catastrophically)

Code:
        sudo mkdir /media/f2fs
        sudo mount /dev/sda3 /media/f2fs
        sudo mount /dev/sda1 /media/f2fs/boot
        sudo mount --bind /dev /media/f2fs/dev
        sudo mount --bind /proc /media/f2fs/proc
        sudo mount --bind /sys /media/f2fs/sys
        sudo chroot /media/f2fs
the prompt should change from $ to #
Code:
update-grub
Grub will probe for partitions, pause for gyrations, call it's mum, then pass the new uuid you added to /etc/fstab into the grub configuration stored in /boot

If you're feeling saucy, delete the ext4 partition in gparted and run update-grub inside the chroot again.
This removes unnecessary entries in the grub menu.

Exit the chroot, make sure to cross those stubby fingers.


Code:
exit
umount /media/f2fs/*
If you forget to unmount the bound directories, issuing a reboot takes forever (something about graceful dismounts? maybe someone else can explain)

Code:
sudo reboot
That's it! If everything went smoothly, you should now be at the login prompt or desktop; if you run mount in a terminal you will see /dev/sda3 is mounted as F2FS to /


if you reboot and end up at an initramfs prompt with the following error:


Target filesystem doesn't have requested /sbin/init.
No init found. Try passing init=bootarg.


Check to be sure you are

installing f2fs, and apt is not failing for whatever reason
inserting f2fs into /etc/initramfs-tools/modules
inserting the new UUID and options into /etc/fstab
running update-grub from chroot after copying the installation to sda3