In my quest to reduce SD-card wear (and yes I know, opinions vary as to the gravity or necessity of this, especially when using modern SD-cards), I have moved /var/log to tmpfs, made the /var/log on tmpfs persistent between reboots and now I have decided to turn off journaling on the ext4 part of my Raspberry’s SD-card.
Proceed at your own risk, but here is how:
If you are like me, your Raspberry will live somewhere in a closet, near your “network infrastructure” and you will manage it through SSH.
You have probably tried to remount your SD-card in a read-only way, only to be faced with the dreaded “root is busy”:
Because the whole of the Raspberry is relying on the SD-card, it is extremely difficult to get it into a read-only state. Please do not attempt to mount it read-only in fstab, as more than likely the PI’s networking stack will not be stood up (and no IP-address, and no connectivity and you are to edit it locally)
First, check which processes are possibly tying up the PI:
fuser -v ./
In my case, not a lot (as I took care of killing everything non-essential):
And bash is pretty essential. You know, for typing in commands and such 🙂 In other words, leave bash and SSH alone!
Now, we are in a catch 22. The unmount/remount will fail because “/ is busy”!
To the rescue comes sysrq-trigger. Please be careful, as it is a low-level way to access and change your system, and you can do some serious harm!
You can basically send a character (or rather, character code) to a /proc-mounted entry point and the system will interpret this as if it were given system commands directly. It is generally regarded as a last-resort kinda thing, so be careful.
That out of the way, the magic commands are “u” – remount all mounted filesystems as readonly, and “s” – to sync filesystems. Lastly, “b” will perform an immediate reboot, without syncing.
As we know the command for disabling journaling, the following sequence becomes your rescue:
(You should be proper root for this sequence (to avoid permission errors on the “>” commands). If you do not know how to do this, then this is not the sequence you are looking for.)
# echo u > /proc/sysrq-trigger # echo s > /proc/sysrq-trigger # tune2fs -O ^has_journal /dev/mmcblk0p2 # e2fsck -fy /dev/mmcblk0p2 # echo s > /proc/sysrq-trigger # echo b > /proc/sysrq-trigger
The e2fsck will yield some output, which is omitted here.
Pingback: A more permanent approach to reduce SD-card wear on Raspberry PI, using tmpfs and some scripting | waal70's corner of adoxography