📜 ⬆️ ⬇️

Reduced read / write operations on the Raspberry Pi

Introduction

So, on the Internet you can find articles about the fact that in Raspberry flash drives "live" for 2-3 months, after which they become unusable. The proposed solutions are to replace the standard microSD card with a USB HDD. The solution is simple, reliable, plus increases the speed of reading / writing. But why flash drives die so fast? Can the same factors harm the hard drive? And so begin!

Materiel
Flash drives have a limited number of write cycles. It means that if linux constantly writes something to it, it can fail prematurely. Hard drives work on a different principle. But for them, small read / write operations are also not particularly useful. The head of the hard disk can be parked if it is not used for a certain period of time, the system can do it, and it can also be embedded in the gland. In the case of small read / write operations, the hard disk constantly cannot park the head (not critical) or park the head, and immediately starts something to read / write (this is already worse).

Information is written in pages. The usual page size is 4 kB. So if we want to write one byte, then either it will fit into the buffer, or 4 KB will be written. If the buffer is full, the page is written and the further record goes to the next page, which is in RAM.
')
The recording of small pieces of information is used when logging the file system (it gives the opportunity not to lose information in case of failure, for example, power off), as well as logging functions (they store information about certain system events, or program events). In raspberry, logging is done by rsyslog [ 1 ]

There are two daemons in Raspbian that can be disabled to reduce the load on the root media. Turning them off can win in the write operations, but lose in the reliability and the possibility of recovery. These are the file system logging daemon and rsyslog. So if there is valuable data that will be stored in the root disk, then it is better not to disable the logging service. If raspberry is used as a toy or it is possible to quickly replace the main disk, then file system logging can be disabled. As for logging, it is similar, if you don’t know why it is needed, then it’s enough to say that if something doesn’t work, then the fault must be looked for initially in the logs. If you want to ask a question to someone on the forum, you will most likely be asked to drop logs. So if everything works or it is easier for you to reinstall the system than to figure out what “spilled” - you can safely turn off the logs.

You can use the iotop utility to view drive accesses. To do this, run it with the parameters:

sudo iotop -o -a 

Iotop installation
 sudo apt-get install iotop 

Disable logging

To disable logging, open:

 sudo nano /etc/rsyslog.conf 

and comment on it in two lines in the MODULES section:

 $ModLoad imuxsock # provides support for local system logging $ModLoad imklog # provides kernel logging support 

It should turn out like this:
 # /etc/rsyslog.conf Configuration file for rsyslog. # # For more information see # /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html ################# #### MODULES #### ################# #$ModLoad imuxsock # provides support for local system logging #$ModLoad imklog # provides kernel logging support #$ModLoad immark # provides --MARK-- message capability # provides UDP syslog reception #$ModLoad imudp #$UDPServerRun 514 # provides TCP syslog reception #$ModLoad imtcp #$InputTCPServerRun 514 ########################### #### GLOBAL DIRECTIVES #### ########################### # # Use traditional timestamp format. # To enable high precision timestamps, comment out the following line. # $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat # # Set the default permissions for all log files. # $FileOwner root $FileGroup adm $FileCreateMode 0640 $DirCreateMode 0755 $Umask 0022 # # Where to place spool and state files # $WorkDirectory /var/spool/rsyslog # # Include all config files in /etc/rsyslog.d/ # $IncludeConfig /etc/rsyslog.d/*.conf ############### #### RULES #### ############### # # First some standard log files. Log by facility. # auth,authpriv.* /var/log/auth.log *.*;auth,authpriv.none -/var/log/syslog #cron.* /var/log/cron.log daemon.* -/var/log/daemon.log kern.* -/var/log/kern.log lpr.* -/var/log/lpr.log mail.* -/var/log/mail.log user.* -/var/log/user.log # # Logging for the mail system. Split it up so that # it is easy to write scripts to parse these files. # mail.info -/var/log/mail.info mail.warn -/var/log/mail.warn mail.err /var/log/mail.err # # Logging for INN news system. # news.crit /var/log/news/news.crit news.err /var/log/news/news.err news.notice -/var/log/news/news.notice # # Some "catch-all" log files. # *.=debug;\ auth,authpriv.none;\ news.none;mail.none -/var/log/debug *.=info;*.=notice;*.=warn;\ auth,authpriv.none;\ cron,daemon.none;\ mail,news.none -/var/log/messages # # Emergencies are sent to everybody logged in. # *.emerg :omusrmsg:* # # I like to have messages displayed on the console, but only on a virtual # console I usually leave idle. # #daemon,mail.*;\ # news.=crit;news.=err;news.=notice;\ # *.=debug;*.=info;\ # *.=notice;*.=warn /dev/tty8 # The named pipe /dev/xconsole is for the `xconsole' utility. To use it, # you must invoke `xconsole' with the `-file' option: # # $ xconsole -file /dev/xconsole [...] # # NOTE: adjust the list below, or you'll go crazy if you have a reasonably # busy site.. # daemon.*;mail.*;\ news.err;\ *.=debug;*.=info;\ *.=notice;*.=warn |/dev/xconsole 


After rebooting, the system will stop logging. Checking:

 sudo iotop -o -a 

The output is no longer rsyslog.

Disable logging

There is a small complexity - the partition must be unmounted. To do this, you can use:


In the case when you have a microSD card - the partition on which the system stands will be defined as mmcblk0p2.

Here mmcblk0 is the card itself, and p2 is the second partition on it (the first default is boot). If you are using a USB drive, then the partition is defined as sda2. If you boot from another computer, then most likely it is defined as sdb2.

Next, perform:

 sudo umount /dev/sdb2 sudo tune2fs -O ^has_journal /dev/sdb2 sudo e2fsck -f /dev/sdb2 

After that we check:

 dmesg | grep EXT4 

Issues:

 [ 5890.967580] EXT4-fs (sdb2): mounted filesystem without journal. Opts: (null) 

Boot from our drive, enter:

 sudo iotop -o -a 

And we see that LXDE only occasionally refers to the hard disk. Since these messages are not systematic (we will observe minutes 5-10), we can say that the load on the drive has decreased to almost zero.

Source: https://habr.com/ru/post/330160/


All Articles