Raspberry Pi
m (→Trying to reduce number of disk writes (SD card)) |
m (→My SD card data recovery procedure) |
||
Line 187: | Line 187: | ||
* I was just about to return the SD card, but for curiosity, I tried what happens if I re-install the (original) Raspbian image. To my surprise, Win32 Disk Imager did not report any error. And even more surprising, after writing the image, I was able to create an image of the whole disk without error. It looks like the card remapped some spare sectors. | * I was just about to return the SD card, but for curiosity, I tried what happens if I re-install the (original) Raspbian image. To my surprise, Win32 Disk Imager did not report any error. And even more surprising, after writing the image, I was able to create an image of the whole disk without error. It looks like the card remapped some spare sectors. | ||
* My Raspberry successfully booted from this new image. I then used <code>raspi-config</code> to expand the root-fs (I've done this on my first installation as well). With Linux I was able to <code>dd</code> my repaired image to the repaired SD. The card booted as if nothing had happened... | * My Raspberry successfully booted from this new image. I then used <code>raspi-config</code> to expand the root-fs (I've done this on my first installation as well). With Linux I was able to <code>dd</code> my repaired image to the repaired SD. The card booted as if nothing had happened... | ||
− | * But after some weeks, my Raspberry fried the SD card again, and some weeks later again ... And finally I could not get my pi to boot with this card. However, I can still read the data linux. Moving data to a new card... (easier said than done if the new card is slightly smaller... but, see below for resizing) | + | * But after some weeks, my Raspberry fried the SD card again, and some weeks later again ... And finally I could not get my pi to boot with this card. However, I can still read the data linux. Moving data to a new card... (easier said than done if the new card is slightly smaller... but, see below for resizing... and sometimes a fresh install is even less painful). |
===Reminders: dd, dd_rescue, losetup, mount and others=== | ===Reminders: dd, dd_rescue, losetup, mount and others=== |
Revision as of 22:39, 13 September 2014
Cookbook
My collection of hints, tips and tricks (supporting my memory and maybe also helping others).
External USB drives
- Automount USB-Drives in Raspbian
- One may use USBmount and autofs
- I prefer udevil, see below
- Install ntfs-3g if you need write access to ntfs file systems
- How to increase performance?
- Mount with option 'noatime' or 'relatime'
- Mount without option sync (e.g. keep default async)
- If using ntfs-3g (fuse) file system, try mounting with option 'big_writes', see for example http://obihoernchen.net/wordpress/tag/big_writes/
udevil
- example for manual mounting:
udevil mount /dev/sda1
- auto-mounting via udev-rule, see for example http://lsdlinux.org/wiki/doku.php?id=auto_mounting#using_udev_rule (I just copied the 95-udevil-mount.rules file from an OpenElec installation (http://www.raspberrypi.org/downloads) )
- my build-steps (maybe there's a simpler way, but this worked...):
- download 0.4.3/udevil_0.4.3-1_all.deb from https://github.com/IgnorantGuru/udevil/tree/pkg, e.g. using wget
- extract deb-package via
ar vx udevil_0.4.3-1_all.deb
- extract data archive
tar xzvf data.tar.gz
- change to tar usr/share/devil/src
- untar
tar xvfJ udevil-current.tar.xz
-
cd udevil-0.4.3
-
mv distros/debian
- execute
dpkg-buildpackage
- If all required packages are installed, this results in udevil_0.4.3-1_armhf.deb. If the build fails due to missing packages, install the missing packages, and re-do the dpkg-buildpackage step
- Install via
sudo dpkg -i udevil_0.4.3-1_armhf.deb
Samba server / NAS
- How to install?
- Slow disc performance?
- see 'Slow USB drives' above
- use Raspbian, etc without GUI to get as much CPU power for file-transfer as possible (OpenELEC or RaspBMC constantly use about 10-20% CPU load when idle, use top to check!)
- Configuration and tuning
- If your /var/log/samba/log.smbd fills up with printing/print_cups.c:110(cups_connect) Unable to connect to CUPS server localhost messages, try http://www.sotechdesign.com.au/samba-log-showing-error-failed-to-retrieve-printer-list/
I also created an empty/etc/printcap
to avoid Unable to open printcap file /etc/printcap for read messages.
- I don't need sound:
root@pi ~ # cat /etc/modprobe.d/snd-blacklist.conf # I don't need sound blacklist snd blacklist snd_pcm blacklist snd_soc_core blacklist snd_soc_bcm2708_i2s
Trying to reduce number of disk writes (SD card)
I'm using RRD with a cron job (currently observing pi's temperature and frequency). I hope that my SD card has proper wear-leveling (and currently my 8 GB card is less than half full), so that the frequent writing should not be a problem. But still, I want to reduce the number of writes to the SD card (in order to not bust it's lifetime).
Here's what I've done:
- Edit
/etc/default/cron
and setEXTRA_OPTS="-L 0"
to disable logging (I don't need these) - Avoid entries like
pam_unix(cron:session): session closed for user pi
in/var/log/auth.log
- Edit
/etc/pam.d/cron
and comment the line@include common-session-noninteractive
([1])
- Edit
- or
- Edit
/etc/pam.d/common-session-noninteractive
as shown here: http://ubuntuforums.org/showthread.php?t=1256801&p=10283830#post10283830
- Edit
- I've implemented a persist tmpfs as discussed in http://www.a-netz.de/2013/02/persistent-storage-with-ramdisks/ and http://www.observium.org/wiki/Persistent_RAM_disk_RRD_storage (and, I guess, many other sites)
- moved all the .rrd files as well as the created images to my persistent-ramdisk location
- moved some directories with frequent writes to my persistent-ramdisk location and added corresponding sym-links
-
/var/spool
-
/var/log
-
/var/cache/samba
-
- edited
/etc/insserv.conf
to add the persist-ramdisk as a requirement to $local_fs; the original definition can still be accessed as $local_fs_orig:
$local_fs_orig +mountall +mountall-bootclean +mountoverflowtmp +umountfs # we need the sym-link data in /var/log and /var/spool to be available $local_fs $local_fs_orig +persist-ramdisk
-
/etc/init.d/persist-ramdisk
depends on $local_fs_orig, and the other init-scripts keep their dependency to $local_fs. This ensures that /var/log and /var/spool are ok when starting & stopping other init scripts.
-
- set RAMTMP to yes in
/etc/default/tmpfs
to get tempfs based/tmp
- set RAMTMP to yes in
Before changing /tmp
:
- But still,
iostat
shows quite some data written to the SD card, according toiotop
its jbd2, the ::journaling part of ext4 (pi is 'idle', only some services run, and the ext4 partition is mounted with noatime). - I need to do more digging...
- But still,
After changing /tmp
:
- It looks like the unwanted writes to SD are gone. I'll watch it for some time...
Useful stuff and Q&A
- Q: Why does my Pi restart when hotplugging a USB drive?
- Q: Does Raspberry support WOL?
- A: No: the Ethernet chip is connected via USB (http://www.raspberrypi.org/forum/viewtopic.php?f=53&t=39714)
- Q: The new password is to short, or too simple
- A: Try adjusting the PAM settings in
/etc/pam.d/common-password
:- remove the 'obscure' setting for pam_unix.so, and add your desired minimum length (e.g. minlen=2)
password [success=1 default=ignore] pam_unix.so sha512 minlen=2
- !! This is not recommended if your box is connected to the internet or if it contains private data noone should know !!
- But it's nice for testing (if you cannot or do not want to use auto-login.)
- !! This is not recommended if your box is connected to the internet or if it contains private data noone should know !!
- Q: How to configure static IP?
- A: In /etc/network/interfaces:
iface eth0 inet static address 192.168.0.31 netmask 255.255.255.0 gateway 192.168.0.1
- Q: How to read core temperature, etc?
- A: vcgencmd:
vcgencmd measure_temp vcgencmd measure_clock arm
- External USB HDD spin down
- hdparm does not work with my WD Elements (SG_IO: bad host status: 0x7)
- hd-idle works:
hd-idle -a sda -i 600
- for details, see for example http://blog.is-a-geek.org/festplatten-in-den-standby-modus-versetzen-unter-ubuntu-desktopserver-mit-hd-idle (German)
- Q: How to avoid update of a certain package?
- A: Put package on hold ([2] (German)):
echo <packagename> "hold" | dpkg --set-selections
- wikipedia:Raspcontrol with nginx
- Q: How many bytes are written to my (SD) disc?
- A: Use
iostat
http://www.mybinarylife.net/2012/08/linux-iostat-command.html - A: Use
iotop
http://guichaz.free.fr/iotop/ - A: Raw data of the kernel can be found in files
/proc/diskstats
and/sys/block/DEVNAME/stat
https://www.kernel.org/doc/Documentation/iostats.txt
Overclocking
- I only set overclocking via
raspi-config
- Turbo: (Short) Raspberry stress test were ok. But I got an SD card error/corruption when doing a download and a dd-image of the SD card (according to http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=57907 the SD card error could be OC related.)
- Luckily, I could recover all my data, see below.
- Medium: Raspberry is stable. I've observed two file system corruption which might be related to overclocking (see [3] and its links).
- Underclocking to 600 MHz
echo "600000" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
- Raspberry was stable for some hours, but it got frozen later on. I don't now if really related to underclocking. As the temperature did not drop significantly (stayed around 45°C), and the Raspberry CPU has no sleep modes either (for power saving), I did not retry.
- Adjusting the ondemand-governor
- https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt
- set
/sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
to 10 [4]- I had hoped this reduces the 1-wire CRC errors/device-disconnects problems, but with heavy (IO-) load (e.g. backup), 1wire sensors still get disconnected.
Stress test and benchmarks
My SD card data recovery procedure
After my (Turbo-overclocked) Raspberry fried my 8 GB SD card, I had not hoped to to be able to recover any data, but I tried anyway. The card was only 1 week old, I have not written that much data too it (<4 GB, mainly the Raspbian image).
- Creating a binary image of the SD card with my PC using Win32 Disk Imager resulted in IO errors at about 17%.
- The partition table of my SD card was still ok. I hoped to at least recover some text data of my ext4 partition, and thus I created an image using
dd conv=sync,noerror if=/dev/sdb2 of=rasp-image.img bs=1M
on my Linux machine (optionconv=noerror
ignores any errors, sync pads read-errors with zeros). The resulting image could not be mounted using a loop device. - Fortunately,
fsck.ext4 raspberry-image.bin
was able to repair the image, which I then could successfully mount on my Linux machine usingmount -o loop rasp-image.img /mnt
, and at a first glance, everything looked ok. So, I was at least able to get to my data. - On a later 'event', I dd-ed the repaired image back to the Raspberry, and could boot again.
- On another a later 'event', I just fsck-ed the /dev/sdb2 using Linux, and could boot again... but I did not have luck this time - some files were gone.
- I was just about to return the SD card, but for curiosity, I tried what happens if I re-install the (original) Raspbian image. To my surprise, Win32 Disk Imager did not report any error. And even more surprising, after writing the image, I was able to create an image of the whole disk without error. It looks like the card remapped some spare sectors.
- My Raspberry successfully booted from this new image. I then used
raspi-config
to expand the root-fs (I've done this on my first installation as well). With Linux I was able todd
my repaired image to the repaired SD. The card booted as if nothing had happened... - But after some weeks, my Raspberry fried the SD card again, and some weeks later again ... And finally I could not get my pi to boot with this card. However, I can still read the data linux. Moving data to a new card... (easier said than done if the new card is slightly smaller... but, see below for resizing... and sometimes a fresh install is even less painful).
Reminders: dd, dd_rescue, losetup, mount and others
- Example partition table printed by fdisk:
/dev/sdb: 7861 MB, 7861174272 bytes, 15353856 sectors Units = Sektoren of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Gerät boot. Anfang Ende Blöcke Id System [...] /dev/sdb3 15288320 15353855 32768 83 Linux
Byte-offset of sdb3: 7827619840 = 15288320 * 512
- Mount partition to /dev/loopN partition for repair, etc.
losetup -o 7827619840 --find --show /dev/sdb
--show prints the used /dev/loopN device
- Directly mount partition using loop device:
mount -o loop,offset=7827619840 /dev/sdb /mnt
- http://www.garloff.de/kurt/linux/ddrescue/
- http://softwarebakery.com/shrinking-images-on-linux
- http://www.tehfear.com/2007/10/08/resize-loop-disk-image/
- http://wiki.ubuntuusers.de/dd (German)
- http://askubuntu.com/questions/69363/mount-single-partition-from-image-of-entire-disk-device
Some 1-Wire Stuff
Temperature Sensor DS1820
- How to?
- http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/temperature/
- https://www.raspiprojekt.de/anleitungen/schaltungen/9-1wire-mit-temperatursensor-ds18b20.html?showall=&start=1 (German)
- http://kopfkino.irosaurus.com/tutorial-ds18s20-temperatur-sensor-an-einem-raspberry-pi/ (German)
- http://raspberrywebserver.com/cgiscripting/rpi-temperature-logger/
- http://elinux.org/RPi_Low-level_peripherals
- I have two DS18B20 and log temperatures using rrdtool.
- When copying data via samba, I frequently get read-errors (CRC errors), or device-disconnects (/sys/bus/w1/devices/<id>/w1_slave temporarily not available).
- Q: Is this due to overclocking with using dynamic governor?
- A: No - also occurs without overclocking (but less frequent?)
- Q: Or is this due to voltage-problems?
- A: No - also occurs without over-voltage
- Q: Or something else?
- A: I have the impression that this is connected to electrical problems (e.g. timing, voltage) on my 1-wire when there's a lot of IO (USB, ethernet). Using 3 sensors works almost all the time (without overclocking), but using 4 or more sensors (2 connected star topologies, very bad for 1-wire GUIDELINES FOR RELIABLE LONG LINE 1-WIRE NETWORKS), almost always fails to read values on most of the sensors.
- A:Implement multiple 1-wire interfaces (see below), using 1 for each star-topology solved the problem. Reading 2x3 works perfect!
Multiple 1-wire buses
- Inspired and guided by http://www.raspberrypi.org/forums/viewtopic.php?p=513312#p513312, I've patched
arch/arm/mach-bcm2708/bcm2708.c
(patch file http://holyhead.de/RaspberryPi/bcm2708-multiple_w-1.patch-3.12.21.txt). - I've cross-compiled the kernel on a linux-VM, using the instructions of http://elinux.org/RPi_Kernel_Compilation (compiling on the RaspberryPi takes 6 hours [5] or much more [6]).
- Inspired and guided by http://www.raspberrypi.org/forums/viewtopic.php?p=513312#p513312, I've patched
Some 1-wire internals
- https://www.kernel.org/doc/Documentation/w1/w1.generic
- GUIDELINES FOR RELIABLE LONG LINE 1-WIRE NETWORKS
- http://blog.gegg.us/2013/03/4-different-methods-of-1-wire-access-on-raspberry-pi/
Compiling own kernel
- Some hints on cross-compiling:
- http://elinux.org/RPi_Kernel_Compilation
- https://github.com/raspberrypi/linux/tree/rpi-3.12.y/arch/arm/mach-bcm2708
- https://github.com/notro/rpi-source/wiki
- https://github.com/notro/rpi-source/wiki/Examples-on-how-to-build-various-modules
- http://www.raspberrypi.org/forums/viewtopic.php?f=44&t=19489&start=75
- http://www.bootc.net/projects/raspberry-pi-kernel/
- http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/
- http://www.satsignal.eu/raspberry-pi/kernel-recompile.html
- http://www.satsignal.eu/raspberry-pi/kernel-cross-compile.html
- http://www.gtkdb.de/index_36_2087.html
What about updates?
As I always forget this
-
apt-get update
- update package lists -
apt-get upgrade
- upgrade installed packages -
rpi-update
- update kernel and modules
- use
SKIP_KERNEL=1 rpi-update
to update the RPi firmware, but keep the current kernel
- use
Kernel Sources
- https://github.com/notro/rpi-source gets the source data from https://github.com/Hexxeh/rpi-firmware and https://github.com/raspberrypi/linux/
Todo and Miscellaneous
Attach a LCD display
LCDProc hints
Collection of stuff to check - things I might) try sometime
- also works in RasPi emulator, e.g. http://www.heise.de/ct/inhalt/2014/7/160/ (German, teaser to article)
- NAS/Samba
- try adjusting 'socket options' in (/etc/samba/smb.conf) to increase NAS performance: some websites recommend to disable the 'socket options', some recommend to set:
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536
Things done
- Adjust swap file (size, location -> (ext4) HDD - too slow?): http://manpages.ubuntu.com/manpages/hardy/man8/dphys-swapfile.8.html
Some links (aka bookmark lists)
Project sites
Blogs, forums, etc
- http://www.raspberrypi.org/phpBB3/
- Stm Labs Forum / Raspbmc
- Wel!s Blog (German)
- Raspberry Pi Blog of Jan Karres (German)
- http://www.forum-raspberrypi.de/ /(German)
- http://raspberrycenter.de/ (German)
Miscellaneous
Manuals