So I searched for some solutions in order to avoid wearing out the sd card too quickly . Raspbian seems to have overlayfs built into the raspi-config. For Arch Linux however, the solution seems more complicated since not many people uses Arch on a arm device.
https://github.com/ghollingworth/overlayfs
https://github.com/nils-werner/raspi-overlayroot
https://github.com/bluerider/liveroot
Three projects were found and the third oneseems to be noteworthy and mentioned
here. Unfortunately the author Bluerider has not been active for a quite long time and
liveroot lacks decent documentation.
Some discussions were found
here where on the third page someone did a somewhat detailed guide on how to install it (If someone is actually trying to follow this, I would suggest you to first read every thing in that forum discussion). I used a different method which seems to work fine, although several questions remained open as I do not have a decent amount of knowledge of how these file systems work.
To install, I first followed the regular procedure for installing AUR packages
git clone https://aur.archlinux.org/liveroot.git
Then I pulled everything in the github repo and moved it into a folder called
src.
cd liveroot
mkdir src
cd src
git clone https://github.com/bluerider/liveroot.git
After that do the normal makepkg -si, it would provide you with three options. I chose
y, which used the
compiler (a shell script) and the author said that "the installed oroot will be highly specific to your system based on what it read off the current kernel cmdline." I am not sure what it means exactly.
Then I checked both /usr/lib/initcpio/hooks/oroot and /usr/lib/initcpio/install/oroot and found that the file named oroot is there already (the github instruction said that you have to copy the file to it manually)
After that I went to edit /etc/mkinitcpio.conf, here comes the great confusion: what modules do I need exactly? I was guessing that I definitely need overlay, zram seems to be only required if you chose to use live or compressed option. In the guide written in the forum discussion the user wrote
MODULES="zram ext2 btrfs overlay"
My guess was that btrfs is only needed for using btrfs, but what about ext2? Is it because most usb sticks is formatted in ext2? If there were using ext2, then they were not using btrfs. So why are both modules listed? I was using ext4 for my root partition, should I add ext4 to the MODULES array? Maybe I should have added
ext4? to the line (the ? will prevent an error from being thrown when the module cannot be found).
In the end I chose to only have
MODULES=(overlay)
and I added oroot to the HOOKS array so it became
HOOKS=(base udev oroot autodetect modconf block filesystems keyboard fsck)
Then I add to the end of /boot/cmdline.txt
oroot=raw
As I thought it was the simplest option.
Then I issued
mkinitcpio -p linux-raspberrypi4
and rebooted (the option followed -p can be found under /etc/mkinitcpio.d/).
After reboot df showed me that the root fs was gone and a new tmpfs appeared. The system seems to be working correctly. Then I realized I actully have more than 4GB of data in my root fs, so how did the overlay handled it? This is my second question.
Then I removed the option in /boot/cmdline.txt and rebooted again (I actually also attempted to back /etc/mkinitcpio.conf but then I realized that it would not write to the disk. I forgot to test the overlay_flush function).
After reboot the system seemed to be running in the normal mode again. Here is my third question: the author did not say how to change back the setting. Do I modify /etc/mkinitcpio.conf and run mkinitcpio again or it is unnecessary? I am guessing that it will not damage the system as the guide in the forum discussion modified the grub parameter at boot as a temporary operation. Perhaps the only downside is the initial ramdisk environment loads a few unused module. However, too much blackbox operations I had been doing (and I think it is the most annoying thing when doing system operations) that I would not want the system using liveroot until I figure out whether this solution is even stable after 4 years.
Note: I guess having a separate partition for the root is a good idea, but I actually don't know how to do that without reinstalling the system... For now the only optimization I did is
this.
Comments
Post a Comment