Part 05
-
Extra Configuration
On Your Raspberry Pi
Version: 2016-04-19
Raspberry Pi - Part 05 - Extra Configurations.odt Page 1 of 7
Less writing
To prevent your Raspberry Pi's from writing a lot of data, and thus, wearing the SD card, you
can do a couple of things.
tmpfs
The first one is to mount a few folders in RAM as tmpfs. The folders are the folders where
temp files and logging is written to. This means that you won't have syslog available, but
most of the time that is not a problem.
Edit /etc/fstab
sudo nano /etc/fstab
and add the following:
tmpfs /tmp tmpfs defaults,noatime,nosuid,mode=1755,size=10m 0 0
tmpfs /var/tmp tmpfs defaults,noatime,nosuid,mode=0755,size=10m 0 0
tmpfs /var/log tmpfs defaults,noatime,nosuid,mode=0755,size=10m 0 0
tmpfs /run tmpfs defaults,noatime,nosuid,mode=0755,size=100m 0 0
When you have finished press [Ctrl] + X. This will ask if you want to save the modified
files. Press 'Y' and then hit [Return] to save the file with the same name.
This will mount the above folders in RAM, with a max size of 10 megabyte. The noatime
option means that the access time of a file is not updated, saving a lot of writes as well.
You should also add the noatime option to your other partitions, for example on a standard
Raspbian:
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat ro,noatime 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
Here the /boot partition is also mounted read only (ro). The noatime option is added.
Issue a mount -a command or reboot the machine to make this active.
Disable swap
Linux divides its physical RAM (random access memory) into chucks of memory called
pages. Swapping is the process whereby a page of memory is copied to the preconfigured
space on the hard disk, called swap space, to free up that page of memory. The combined
sizes of the physical memory and the swap space is the amount of virtual memory
available.
Swapping causes a lot of writes to the SD card. You would want to turn it off to save
writes. The downside of this is that when there is not enough RAM available the linux OOM
(Out Of Memeoy) killer will randomly kill processes to save RAM.
Raspbian by default has a swap file, dynamically managed by the dphsys-swapfile utility.
You can turn off this utility by issueing the following commands:
dphys-swapfile swapoff
dphys-swapfile uninstall
update-rc.d dphys-swapfile remove
After a reboot the swap will be gone, which you can check with the free -m command:
total used free shared buffers cached
Mem: 484 243 241 0 42 162
-/+ buffers/cache: 38 446
Swap: 0 0 0
Raspberry Pi - Part 05 - Extra Configurations.odt Page 2 of 7
fsck at every boot
My Raspberry Pi's have a cronjob which reboots them once every seven days. This to apply
kernel updates and just a general good procedure to see if all still works after a reboot.
By default, fsck checks a filesystem every 30 boots (counted individually for each
partition). I decided to change this to every boot, so disk problems might be found earlier
and possibly fixed earlier.
To set up an fsck at every boot, execute the following command:
sudo tune2fs -c 1 /dev/mmcblk0p2
Where /dev/mmcblk0p2 is the Linux Raspbian partition.
NB: To reboot every day at midnight, type
sudo crontab –e
and add this line
0 0 * * * /sbin/reboot
When you have finished press [Ctrl] + X. This will ask if you want to save the modified
files. Press 'Y' and then hit [Return] to save.
Raspberry Pi - Part 05 - Extra Configurations.odt Page 3 of 7
Adding SAMBA for file access from your PC
To view handle files on a Pi from a Windows PC you need to install and configure a package
called SAMBA, which allows a UNIX file system to be seen by a Windows network client. The
following steps are based in information from http://elinux.org/R-Pi_NAS
sudo apt-get –y update
sudo apt-get –y install samba samba-common-bin
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old
Edit /etc/samba/smb.conf
sudo nano /etc/samba/smb.conf
add at the end of the file a definition of a share named "MyShare":
[MyShare]
comment = My Share for log files
path = /var/log
read only = yes
guest ok = yes
If you want write access, replace "read only" with "writeable"
writeable = yes
I found that I needed to grant access to the /var/log directory, which I did with a
chmod 777 /var/log –
Doubtless there are tighter protections I could have used. Now restart the Samba server
sudo /etc/init.d/samba restart
You now access the files from Windows just like any other network share, for example
C:\>dir \\RasPi-1\MyShare
Volume in drive \\RasPi-1\MyShare
Volume Serial Number is 04CA-A6BD
Directory of \\RasPi-1\MyShare
24/11/2012 12:03 <DIR> .
24/11/2012 12:03 <DIR> ..
24/11/2012 14:25 112,661 peerstats.20121124
24/11/2012 14:25 33,443 loopstats
24/11/2012 14:25 112,661 peerstats
24/11/2012 14:25 33,443 loopstats.20121124
4 File(s) 292,208 bytes
2 Dir(s) 1,826,832,384 bytes free
Raspberry Pi - Part 05 - Extra Configurations.odt Page 4 of 7
Installing Geany
To install the Geany Editor run following commands from a terminal:
sudo apt-get –y install geany
Installing Imagemagick
To install Imagemagick, run following commands from a terminal:
sudo apt-get –y install imagemagick
If you have a PNG format image that you want to convert to JPEG; this can be achieved from
the command line:
convert file.png file.jpeg
To resize an image to 150 pixels width, height is adjusted to scale
convert file.png -resize 150 150-file.png
To resize image to 150 pixel height and allowing width to scale accordingly:
convert file.png -resize x150 150-file.png
Installing office applications
If you like to use your Raspberry Pi as a full computer, you might find the lack of office
applications disheartening. While our favourite open source office suite will always be
LibreOffice, as Winkleink rightly points out above, it’s not the leanest or fastest option to use
on your credit card-sized PC.
AbiWord is an excellent Microsoft Word clone that has all the features you need in a package
light enough to run smoothly on your Pi. To install it all you need to do is type:
sudo apt-get –y install abiword
in a terminal window.
You’ll find it installed under ‘Office‘ once it’s installed
If you need to crunch numbers as well as letters, Gnumeric is by far the most popular Linux
solution, which adds the capabilities of Microsoft’s Excel application to your Raspberry Pi’s
repertoire. To install it simply type the following into a terminal window:
sudo apt-get –y install gnumeric
Like Abiword, you need to be within the Raspberry Pi’s desktop environment to use Gnumeric.
Raspberry Pi - Part 05 - Extra Configurations.odt Page 5 of 7
Installing Sonic Pi 2
Another essential piece of software for your Raspberry Pi is Sonic Pi 2. It allows you to make
music with your Raspberry Pi using easy-to-learn code.
There’s a wide range of effects and capabilities added with Sonic Pi 2, including the ability to
live code music, use samples and emulate even more cool synths.
Installing the latest (stable) pre-release version of Sonic Pi 2 is really easy. Within a terminal
window, type the following to download the package:
wget http://sonic-pi.net/sonic-pi-RC11.tar.gz
Next, unpack the ‘tarball’:
tar -xvzf sonic-pi-RC11.tar.gz
Then run it by typing:
./sonic-pi/bin/sonic-pi
You can find a really comprehensive getting started guide for Sonic Pi 2 on The Raspberry Pi
Foundation’s resources page.
Raspberry Pi - Part 05 - Extra Configurations.odt Page 6 of 7
Cleanup packages
When you install a package, apt-get retrieves the needed files from the hosts listed in
/etc/apt/sources.list, stores them in a local repository (/var/cache/apt/archives/), and then
proceeds with installation.
In time the local repository can grow and occupy a lot of disk space. Fortunately, apt-get
provides tools for managing its local repository: apt-get's clean and autoclean methods.
apt-get clean removes everything except lock files from /var/cache/apt/archives/ and
/var/cache/apt/archives/partial/. Thus, if you need to reinstall a package apt-get should
retrieve it again.
apt-get autoclean removes only package files that can no longer be downloaded.
sudo apt-get –y clean
sudo apt-get –y autoclean
Raspberry Pi - Part 05 - Extra Configurations.odt Page 7 of 7