Disabling swap

sudo nano /etc/dphy-swapfile

sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo systemctl disable dphys-swapfile
sudo rm /var/swap

Move logs to tmpfs
Note: You need to recreate the folders and empty files with the correct permission to make this work or else the programs may refuse to start as they cannot find their log folders.


List the /var/log folders with their owners:

sudo ls -lh /var/log

Create directory:

sudo mkdir /var/log/apache2

Change ownership:

sudo chown -R www-data:www-data /var/log/apache2
sudo nano /etc/fstab

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults,noatime          0       2
/dev/mmcblk0p2 /               ext4    defaults,noatime  0       1

tmpfs /var/tmp tmpfs nodev,nosuid,noatime 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,size=64m 0 0
tmpfs /tmp tmpfs defaults,noatime,nosuid 0 0
tmpfs /var/spool/mqueue tmpfs defaults,noatime,nosuid,mode=0700,gid=12,size=30m 0 0

Enable the volatile log to systemd

sudo nano /etc/systemd/journald.conf

Migrating the filesystem to F2FS

sudo apt update
sudo apt install f2fs-tools

You need to plug in the Pi’s microSD to your PC or laptop preferably a GNU/Linux one so we can mount the partition and back it up.
Mounting the card:

mkdir ~/RPI
mkdir ~/RPI/BOOT
mkdir ~/RPI/ROOT
mkdir ~/RPIBK
sudo mount /dev/sdb1 ~/RPI/BOOT
sudo mount /dev/sdb2 ~/RPI/ROOT
sudo cp -rvpfa ~/RPI/BOOT ~/RPIBK/
sudo cp -rvpfa ~/RPI/ROOT ~/RPIBK/

Edit the ~/RPI/BOOT cmdline.txt

sudo nano ~/RPI/BOOT/cmdline.txt

change the rootfstype to f2fs and add noswap

Unmount the partitions and prepare for reformat

sudo umount ~/RPI/BOOT
sudo umount ~/RPI/ROOT

Caution: swap will not work in F2FS filesystem and we are going to ReFormat the second partition of the card!
Reformat the second partition of the microSD, use GParted and select the partition and Format -> Filesystem F2FS
or just use this command:

sudo mkfs.f2fs /dev/sdb2

Copy back the files to the new f2fs partition from the ~/RPIBK/ROOT

sudo mount /dev/sdb2 ~/RPI/ROOT
sudo cp -rvpfa ~/RPIBK/ROOT ~/RPI/

Edit the filesystem type in the /etc/fstab

sudo nano /etc/fstab

Change the ext4 to f2fs

Unmount and Eject the microsd and Insert to your Pi.

Except where otherwise noted, this work is licensed under Creative Commons Attribution-ShareAlike 4.0 International License (http://creativecommons.org/licenses/by-sa/4.0/).
I hope that this post is useful to you, if you liked this post you may support me via liberapay. Thank you for your support.

Donate using Liberapay