#Prepare the microSD for the final application

<img src="./microsd.jpg"/>

<span class="abstract">
This article contain a list of tips to avoid the rootfs corruption
on your microSD during the lifetime of your Linux application. 
</span>

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 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__.

<pre class="minicom">
/dev/mmcblk0p2 / ext4 noatime,<b>ro</b> 0 1
</pre>

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:

<pre class="minicom">
~# <b>mount -o remount,rw /</b>
</pre>

to set it again rin read-only type:

<pre class="minicom">
~# <b>mount -o remount,ro /</b>
</pre>

More tips are available on [this article](https://sites.google.com/site/linuxpendrive/rorootfs) 

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

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

Edit the file <b>/etc/default/rcS</b> with this line:

<pre class="minicom">
RAMTMP=yes
</pre>

Then add this two line in <b>/etc/fstab</b> in this way:  

<pre class="prettyprint">
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
</pre>

## Contributes

From Stefan Krüger

<blockquote markdown="1">
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
</blockquote>

## Send your tip

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


## Related links

* [Read-only Root Filesystem](https://sites.google.com/site/linuxpendrive/rorootfs) 
* [http://wiki.debian.org/ReadonlyRoot](http://wiki.debian.org/ReadonlyRoot)
* [http://www.raspberrypi.org/forums/viewtopic.php?f=29&t=22596](http://www.raspberrypi.org/forums/viewtopic.php?f=29&t=22596)
