13
As all Raspberry Pi users should know, operating system runs from SD card.
This can result in a problem, because if the card is written many times constantly, it will reduce SD lifespan for quite little time. If I remember correctly, Flash Memory usually has an expectation of only about 10,000 writing operations.
Well, with this I would like to know if the Raspbian makes written on the SD card even when it is idle.
And in case you have any operation, perhaps logging, how can I disable this operation that is compromising the life of SD?
I’m doing a project that will never (hopefully!) be shut down.
I already have a system with PIC microcontroller, and in this not even the EEPROM memory is being written for that reason. However, the PIC is not capable of new requests for operations.
I found an answer for Debian, but it is outdated for Raspbian:
Tips for running Linux on a flash device by David Härdeman
If you are running your NSLU2 on a USB flash key, there are a number of Things you Might want to do in order to reduce the Wear and tear on the underlying flash device (as it only Supports a Limited number of Writes).
Note: this Document Currently describes Debian etch (4.0) and needs to be updated to Debian Squeeze (6.0) and Debian wheezy (7.0). Some of the hints may still apply, but some may not.
The ext3 filesystem per default Writes Metadata changes Every five Seconds to disk. This can be increased by Mounting the root filesystem with the
commit=N
Parameter which Tells the kernel to delay Writes to Every N Seconds.The kernel Writes a new atime for each file that has been read which generates one write for each read. This can be disabled by Mounting the filesystem with the
noatime
option.Both of the above can be done by Adding e.g.
noatime,commit=120,...
to/etc/fstab
. This can also be done on an already Mounted filesystem by running the command:mount -o remount,noatime,commit=120 /
The system will run updatedb Every day which creates a database of all files on the system for use with the locate command. This will also put some stress on the filesystem, so you Might want to disable it by Adding
exit 0
Early in the
/etc/cron.daily/find
script. syslogd will in the default installation Sync a Lot of log files to disk directly after logging some new information. You Might want to change/etc/syslog.conf
only that Every filename Starts with a-
(Minus) which Means that Writes are not synced immediately (which increases the risk that some log messages are Lost if your system crashes). For example, a line such as:kern.* /var/log/kern.log
would be changed to:
kern.* -/var/log/kern.log
You also Might want to disable some classes of messages altogether by logging them to
/dev/null
Instead, see syslog.conf(5) for Details.In addition, syslogd Likes to write
-- MARK --
Lines to log files Every 20 minutes to show that syslog is still running. This can be disabled by Changing SYSLOGD in/etc/default/syslogd
so that it readsSYSLOGD="-m 0"
After you’ve made any changes, you need to Restart syslogd by running
/etc/init.d/syslogd restart
If you have a swap Partition or swap file on the flash device, you Might want to move it to a Different part of the disk Every now and then to make sure that Different Parts of the disk gets hit by the Frequent Writes that it can generate. For a swap file this can be done by Creating a new swap file before you remove the old one.
If you have a swap Partition or swap file stored on the flash device, you can make sure that it is used as little as possible by Setting
/proc/sys/vm/swappiness
to zero.The kernel also has a Setting known as laptop_mode, which makes it delay Writes to disk (initially intended to allow laptop Disks to spin down while not in use, Hence the name). A number of files under
/proc/sys/vm/
Controls how this Works:
/proc/sys/vm/laptop_mode
: How Many Serconds after a read should a writeout of changed files start (this is based on the Assumption that a read will cause an otherwise spun down disk to spin up Again).
/proc/sys/vm/dirty_writeback_centisecs
: How often the kernel should check if there is "Dirty" (changed) data to write out to disk (in centiseconds).
/proc/sys/vm/dirty_expire_centisecs
: How old "Dirty" data should be before the kernel considers it old enough to be Written to disk. It is in general a good idea to set this to the same value asdirty_writeback_centisecs
above.
/proc/sys/vm/dirty_ratio
: The Maximum amount of memory (in Percent) to be used to store Dirty data before the process that generates the data will be Forced to write it out. Setting this to a high value should not be a problem as writeouts will also occur if the system is low on memory.
/proc/sys/vm/dirty_background_ratio
: The Lower amount of memory (in Percent) Where a writeout of Dirty data to disk is allowed to stop. This should be quite a bit Lower than the abovedirty_ratio
to allow the kernel to write out Chunks of Dirty data in one go.All of the above kernel Parameters can be Tuned by using a custom init script, such as this example script. Store it to e.g.
/etc/init.d/kernel-params
, make it Executable withchmod a+x /etc/init.d/kernel-params
and make sure it is executed by running
update-rc.d kernel-params defaults
Note: Most of These Settings reduce the number of Writes to disk by increasing memory Usage. This increases the risk for out of memory situations (which can Trigger the dreaded OOM killer in the kernel). This can Even happen when there is free memory available (for example when the kernel needs to allocate more than one contiguous page and there are only fragmented free pages available).
As with any tweaks, you are advised to Keep a close eye on the amount of free memory and Adapt the tweaks (e.g. by using Less aggressive caching and increasing the swappiness) Depending on your Workload.
The time constraint to answer the question itself (which I believe is valid only for new users) is to prevent abuses or common errors - for example so that the author [who is not yet familiar with the platform] tries to continue adding content in the form of a forum (i.e. several posts instead of editing your question). But just a couple of votes in favor for you remove this (and other) restrictions.
– mgibsonbr
Okay, thank you!!!!
– user3394963