Minimize SD Cad Usage on Raspberry Pi

Use fDisk

root@raspberrypi:/home/pi# sudo fdisk -l
Disk /dev/mmcblk0: 8068 MB, 8068792320 bytes
4 heads, 16 sectors/track, 246240 cylinders, total 15759360 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b5098Device Boot      Start         End      Blocks   Id  System/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)/dev/mmcblk0p2          122880    14878719     7377920   83  Linux
root@raspberrypi:/home/pi# tune2fs -c 0 /dev/mmcblk0p2
tune2fs 1.42.5 (29-Jul-2012)Setting maximal mount count to -1
root@raspberrypi:/home/pi#

 

Manage Linux system logs

using init-scripts:/etc/init.d/syslogd stop

We will first solve the usual corruption culprit and then move on to making sure we are covered when our programs decide to blow up.
The following two lines should be added to /etc/fstab:

      
/var/run        tmpfs   size=1M,noatime         0 0none        /var/log        tmpfs   size=1M,noatime         0 0

 

After this, /etc/fstab should look as follows:

proc            /proc               proc    defaults                    0   0/dev/mmcblk0p1  /boot               vfat    ro,noatime                  0   2/dev/mmcblk0p2  /                   ext4    defaults,noatime            0   1none            /var/run        tmpfs   size=1M,noatime             0   0none            /var/log        tmpfs   size=1M,noatime             0   0

 

Disable swapping

Run the following commands to disable swapping forever on your system:

sudo dphys-swapfile swapoff
sudo dphys-swapfile uninstall
sudo update-rc.d dphys-swapfile remove

#After doing this, call free -m in order to see your memory usage

pi@raspberrypi ~ $ free -m             

total       used       free     shared    buffers     cachedMem:           438         59        378          0          9         27-/+ buffers/cache:         22        416Swap:            0          0          0

 

see your memory usage:

free -m

 

You can tell it to keep no backups by specifying rotate 0 (or a lower number) for the specific log. Look in /etc/logrotate.d to find the specific configuration fragment. It’s been awhile since I’ve looked into logrotate but I think you can specify it to limit the size of files and such.Poszczególne logi zablokowałem # w pliku /etc/rsyslog.conf

I also changed:

/etc/logrotate.conf  >> rotate=0

Check Actual Disk IO

important:report from

iotop -obtaqqq > output.txt

14:50:27    37 be/3 root          0.00 B      4.00 K  0.00 %  0.77 % [jbd2/mmcblk0p2-]14:50:27 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:29    37 be/3 root          0.00 B      4.00 K  0.00 %  0.71 % [jbd2/mmcblk0p2-]14:50:29 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:30    37 be/3 root          0.00 B      4.00 K  0.00 %  0.65 % [jbd2/mmcblk0p2-]14:50:30 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:31    37 be/3 root          0.00 B      4.00 K  0.00 %  0.76 % [jbd2/mmcblk0p2-]14:50:31 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:33    37 be/3 root          0.00 B      4.00 K  0.00 %  0.71 % [jbd2/mmcblk0p2-]14:50:33 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:34    37 be/3 root          0.00 B      4.00 K  0.00 %  0.67 % [jbd2/mmcblk0p2-]14:50:34 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:35    37 be/3 root          0.00 B      4.00 K  0.00 %  0.63 % [jbd2/mmcblk0p2-]14:50:35 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:37    37 be/3 root          0.00 B      4.00 K  0.00 %  0.59 % [jbd2/mmcblk0p2-]14:50:37 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:38    37 be/3 root          0.00 B      4.00 K  0.00 %  0.72 % [jbd2/mmcblk0p2-]14:50:38 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:39    37 be/3 root          0.00 B      4.00 K  0.00 %  0.69 % [jbd2/mmcblk0p2-]14:50:39 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:41    37 be/3 root          0.00 B      4.00 K  0.00 %  0.66 % [jbd2/mmcblk0p2-]14:50:41 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:42    37 be/3 root          0.00 B      4.00 K  0.00 %  0.63 % [jbd2/mmcblk0p2-]14:50:42 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:43    37 be/3 root          0.00 B      4.00 K  0.00 %  0.65 % [jbd2/mmcblk0p2-]14:50:43 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:45    37 be/3 root          0.00 B      4.00 K  0.00 %  0.62 % [jbd2/mmcblk0p2-]14:50:45 15706 be/4 root          0.00 B      4.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:46    37 be/3 root          0.00 B      4.00 K  0.00 %  0.60 % [jbd2/mmcblk0p2-]14:50:46 15706 be/4 root          0.00 B      8.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:47    37 be/3 root          0.00 B      4.00 K  0.00 %  0.61 % [jbd2/mmcblk0p2-]14:50:47 15706 be/4 root          0.00 B      8.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:49    37 be/3 root          0.00 B     40.00 K  0.00 %  0.60 % [jbd2/mmcblk0p2-]14:50:49 15706 be/4 root          0.00 B      8.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:50    37 be/3 root          0.00 B     40.00 K  0.00 %  0.58 % [jbd2/mmcblk0p2-]14:50:50 15706 be/4 root          0.00 B     12.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:51    37 be/3 root          0.00 B     40.00 K  0.00 %  0.56 % [jbd2/mmcblk0p2-]14:50:51 15706 be/4 root          0.00 B     12.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:52    37 be/3 root          0.00 B     40.00 K  0.00 %  0.54 % [jbd2/mmcblk0p2-]14:50:52 15706 be/4 root          0.00 B     12.00 K  0.00 %  0.00 % python /usr/sbin/iotop -obtaqqq14:50:54    37 be/3 root          0.00 B     40.00 K  0.00 %  0.65 % [jbd2/mmcblk0p2-]14:50:54 15706 be/4 root          0.00 B     16.00 K  0.00 %  0.01 % python /usr/sbin/iotop -obtaqqq

jbd2

jbd2 is causing disk utilization

[https://bbs.archlinux.org/viewtopic.php?id=113516&p=2]

Add commit to /etc/fstab like this:/dev/sda1 / ext4 defaults,noatime,commit=60 0 1

Add commit to /etc/fstab like this:

/dev/sda1 / ext4 defaults,noatime,commit=60    0   1

 

or

cp /usr/lib/pm-utils/power.d/journal-commit /etc/pm/power.d/journal-commit

 

and then edit /etc/pm/power.d/journal-commit and change this value there.
Of course if you have pm-utils installed at all, but I guess it’s some opendesktop depedency.

Disable ext4 jurnaling

I decided to use Ext4 with disabled journal.

# Create ext4 fs on /dev/sda10 diskmkfs.ext4 /dev/sda10

 

Enable writeback mode. This mode will typically provide the best ext4 performance.

tune2fs -o journal_data_writeback /dev/sda10

 

Delete has_journal option

 

Required fsck

e2fsck -f /dev/sda10

 

Check fs options

dumpe2fs /dev/sda10 |more

 

For more performance add fstab opions: data=writeback,noatime,nodiratime
i.e:

/dev/sda10 /opt ext4 defaults,data=writeback,noatime,nodiratime 0 0

This step disables journal

# Delete has_journal optiontune2fs -O ^has_journal /dev/sda10

 

Or when creating:

mkfs.ext4 -O ^has_journal /dev/sda10

 

List of disks:

etc/fstab

proc            /proc           proc    defaults          0     0
/dev/mmcblk0p1  /boot           vfat    defaults          0     2
/dev/mmcblk0p2  /               ext4    defaults,noatime,commit=60  0     1

 

tune2fs -o journal_data_writeback /dev/mmcblk0p2
tune2fs -O ^has_journal /dev/mmcblk0p2

 

Required fsck

e2fsck -f /dev/mmcblk0p2

 

Check fs options

dumpe2fs /dev/mmcblk0p2  | more

 

References

http://crashmag.net/disable-filesystem-check-fsck-at-boot-timehttp://www.ideaheap.com/2013/07/stopping-sd-card-corruption-on-a-raspberry-pi/http://sirlagz.net/2013/03/10/script-automatic-rpi-image-downsizer/http://www.raspberrypi-spy.co.uk/2012/06/resize-sd-card-partitions/http://www.ediy.com.my/index.php/blog/item/61-resizing-sd-card-partitions-for-raspberry-pihttp://superuser.com/questions/826951/disable-logging-on-raspian-debianhttps://bbs.archlinux.org/viewtopic.php?id=113516&p=2http://fenidik.blogspot.com/2010/03/ext4-disable-journal.html

Advertisements