Setup Raspbian on Raspberry Pi

This resource explains how to install Raspbian operating system and setup a Raspberry Pi. You will need another computer with an SD (or MicroSD) card reader to install the image.

Install Raspbian

Download the Image

Raspbian is the Raspberry Foundation’s official supported operating system and can be download from Raspberry Pi website Downloads page.

After downloading the .zip file, unzip it to get the image file (.img) for writing to your SD card. And you can write this image to SD card with the help of Win32 Disk Imager in Windows.

Setup for HDMI Output

Once the write is complete, edit config.txt in boot partition as following for HDMI output.

hdmi_safe=1
hdmi_group=2
hdmi_mode=16
hdmi_drive=2
config_hdmi_boost=4
dtparam=audio=on

Once you’ve steps above, place the SD card into your Raspberry Pi, plug in the HDMI monitor, any keyboards and mice, and then the power cable. Your Raspberry Pi should begin to boot and you should be able to see Raspbian on your screen.

Setup the Pi

Basic Raspbian Setup

When you first turn on your Raspberry Pi with it's fresh Raspbian image on the SD card, you will likely want to tweak the system settings. There's a tool called raspi-config which makes everything super-easy to set up. The tool must be run in a terminal with:

sudo raspi-config

It has the following entries (this is the layout from raspi-config version 20160508, May 2016). It may be different on other Raspbian images:

     Raspberry Pi Software Configuration Tool (raspi-config)
 
1 Expand Filesystem             Ensures that all of the SD card storage is av...
2 Change User Password          Change password for the default user (pi)
3 Boot Options                  Choose whether to boot into a desktop environ...
4 Wait for Network at Boot      Choose whether to wait for network connection...
5 Internationalisation Options  Set up language and regional settings to matc...
6 Enable Camera                 Enable this Pi to work with the Raspberry Pi ...
7 Add to Rastrack               Add this Pi to the online Raspberry Pi Map (R...
8 Overclock                     Configure overclocking for your Pi
9 Advanced Options              Configure advanced settings
0 About raspi-config            Information about this configuration tool
 
                 <Select>                   <Finish>

Resize Flash Partitions

The first option on the blue dialog that follows is titled Expand Filesystem, with the description "Ensures that all of the SD card stroage is available to the OS".

Setup Timezone and Language

You can set up timezone in the 5th option titled Internationalisation Options.

Setup tmpfs for Longer Life of SD card

SD cards are said to have a finite life. If you are planning on running a Raspberry Pi 24x7x365, there are some steps that you can take with GNU/Linux to extend the life of the card: here are some ideas.

tmpfs can write to RAM instead of the local disk (in this case, the SD card). Using it is simple. All that needs to be done is add an entry to the /etc/fstab file (to mount the folder you wish to have written to RAM) and reboot (so that each mount is cleanly mounted before services start writing files).

The kernel will do the rest for you by managing the writes to the RAM on this virtual filesystem. The really neat part about this is that the kernel will only use the amount of RAM required for writing files, not the entire size of the mount.

There are a variety of locations that GNU/Linux likes to make frequent writes. This is a list of entries below that I use as a starting point that should fit for most distributions.

tmpfs    /tmp        tmpfs    defaults,noatime,nosuid,size=100m            0 0
tmpfs    /var/tmp    tmpfs    defaults,noatime,nosuid,size=30m             0 0
tmpfs    /var/log    tmpfs    defaults,noatime,nosuid,mode=0755,size=100m  0 0
tmpfs    /run        tmpfs    defaults,noatime,nosuid,mode=0755,size=2m    0 0
tmpfs    /var/spool/mqueue    tmpfs    defaults,noatime,nosuid,mode=0700,gid=12,size=30m    0 0

As you can see I make use of the "size=" parameter to avoid using up huge amounts of RAM in case something tries to save a huge amount of data. The "noatime" and "nosuid" parameters are also recommended for security and performance, and "mode=" along with "gid=" matches the permissions and group of the original filesystem to what was located on the SD card originally.

One additional point to keep in mind is that anything mounted with tmpfs will be lost on a reboot. So, logs in /var/log in the example above will be wiped out if the computer is shut down or rebooted. So you will not want to save any files with tmpfs that need to be persistent among reboots.

I'm actively using these settings and so far having great results. Hope you can enjoy your Raspberry Pi.

References

  • https://www.raspberrypi.org/documentation/installation/installing-images/
  • http://victorchee.github.io/blog/raspberry-pi-setting/
  • http://www.zdnet.com/article/raspberry-pi-extending-the-life-of-the-sd-card/
Contact Us
  • Room 614, Zonghe Building, Harbin Institute of Technology
  • cshzxie [at] gmail.com