Prepare the microSD for the final application

This article contain a list of tips to avoid the rootfs corruption on your microSD during the lifetime of your Linux application.

Consider that the default Debian microSDs, suggested on this site, are configured for developing or evaluation activities and not for the final application

By default the microSD is treated as a normal hard disk without any restriction on writing operations on it. In this way you can write code, install or update packages and make any operation you need in the most confortable class='acmetable' way.

When your application became ready for the real world you have to become aware about the microSD real nature and its limits.

Tip #1 - Mount the rootfs in read-only

The best way to avoid rootfs corruptions is to avoid to write on it at all.

To set all the root partition in read-only mode just add ro option in /etc/fstab.

/dev/mmcblk0p2 / ext4 noatime,ro 0 1

Reboot and check any writings error. Try to understand what is the service that generate it and change its configuration to avoid it.

I you need to remount the rootfs in read-write mode on the fly type:

~# mount -o remount,rw /

to set it again rin read-only type:

~# mount -o remount,ro /

More tips are available on this article

Tip #2 Send the logs on tmp filesystem located in RAM

If you need to have the latest log messages you could mount the /var/log and /tmp directory in a small filesystem allocated in ram.

Edit the file /etc/default/rcS with this line:

RAMTMP=yes

Then add this two line in /etc/fstab in this way:

tmpfs /tmp     tmpfs nodev,nosuid,size=1M,mode=1777 0 0
tmpfs /var/log tmpfs nodev,nosuid,size=1M,mode=1777 0 0
tmpfs /var/tmp tmpfs nodev,nosuid,size=1M,mode=1777 0 0

Contributes

From Stefan Krüger

to allow to use a regular user and be able to use sudo conveniently it makes sense to add

tmpfs /var/lib/sudo/ tmpfs nodev,nosuid,size=1M,mode=1777 0 0

and if you try and want to use any dhcp services (in client or AP mode) you need an additional

tmpfs /var/lib/dhcp/ tmpfs nodev,nosuid,size=1M,mode=1777 0 0

Send your tip

If you have more tips please share them with the other users sending a brief description to us to add on this page. Thanks.

Related links