UPDATED: July 18th 2013
This blog entry will describe:
- The installation of the Raspbian Wheezy Linux Distribution on an SD card.
- Powering up the Raspberry Pi (RPi) board and connecting it to the network
- Remotely Accessing the RPi board via SSH
- Initial Configuration of the Rasbpian OS/ RPi board
- Remotely Accessing the RPi's graphical desktop environment (LXDE) via VNC
For starters you'll need a microUSB terminated AC adapter, an Ethernet cable & an SD card. I highly recommend that you use a 4GB SD card as a minimum. Also this tutorial assumes that you are running a Debian or Ubuntu Based Linux operating system on your PC. I myself run Crunchbang Linux 11, which is based on Debian Wheezy 7. If you are running a fresh install of Debian Wheezy please setup the sudo utility appropriately.
Installing Raspbian on your SD Card
- Plug in the SD card into the PC then run the following command in a terminal window: "sudo fdisk -l". This will list all of the available drives available on your PC as shown in Figure 1.
- From the output in Figure 1 you can see that the operating system detects two drives, "/dev/sda" is a 64.0GB SSD drive and the "/dev/sdb/" is our 8.0GB SD card.
- The next step is to download the latest Raspbian Wheezy Linux distribution image from this page. Take note of SHA-1 hash string and the username (pi) and password (raspberry) listed on the page.
- Once downloaded, in a terminal window, navigate to the folder containing the compressed Raspbian image with "cd".** **
- Type the following command: "sha1sum 20xx-xx-xx-wheezy-raspbian.zip". Where the 'x's should represent the compressed image version. After a few seconds, a long string will be printed in the console window. Compare this string with the one on the Raspbian download page. If the Raspbian image is complete and not not corrupted, then both strings (hash codes) should be identical.
- Now that you verified the file integrity of the compressed Raspbian image, uncompress it using the following command: "unzip 20xx-xx-xx-wheezy-raspbian.zip". You should end up with another file called "20xx-xx-xx-wheezy-raspbian.img".
- Copy the Raspbian image to the SD card using the following command: "sudo dd bs=1M if=20xx-xx-xx-wheezy-raspbian.img of=/dev/sdb". Make sure that you specify the correct device found using the fdisk command. This command will take a few minutes to complete.
- Once the "dd" command completes, type into the same terminal "sudo sync" to ensure the write cache is flushed properly and that you can safely remove the SD card. Remove your SD card from the card reader and plug it into your RPi.
Putting the RPi with Raspbian OS onto the network
- We will connect to the RPi over the network. This way we can access
both our Linux PC and the RPi through a single monitor....no need to
have multiple monitors and HDMI cables. This can be done in two ways:
- *Connect the RPi directly to the network via an Ethernet
- Power your RPi & connect it to your network (via an Ethernet port on an accessible switch connected to your home network) using the Ethernet cable. You should see the LEDs start to come up implying that the Raspbian image has been successfully started. Once the green "LNK" LED and the "10M" orange LED light up on the RPi board, we can assume that the Raspbian image booted and an IP address has been assigned to the RPi. To figure out the IP address assigned to the RPI by the DHCP server running on our router, we can use the IP Scanner tool nmap. Install nmap on your Linux PC :"sudo apt-get install nmap". Then type "sudo nmap -sP 192.168.0.2-254". This command lists all IP addresses that are up on your local network (typically a 192.168.0.0 network). Find the one that lists "Raspberry Pi Foundation" next to its MAC address (Figure 6). That is the IP address of the RPi. Keep record of it since we will need it to SSH into our RPi.
- *Connect the RPi directly to the network via an Ethernet Switch*
- *Share your PC's Internet Connection with the RPi*
- If there is an unused Ethernet port on the Linux PC, it can be used to allow the RPi to share the network/internet connection that the Linux PC is connected to through another WiFi /Ethernet port.
- To create this network bridge, open the Network Manager application. This can be done from the task bar and should open the "Edit Connections" dialog shown in Figure 2.
- Select "Wired Connection 1" and click on the "Edit" button. If you do not have a wired connection profile, click the "Add" button.
- Change the "Connection name" field to "Raspberry Pi Bridge". In the "Device MAC address" drop down list, select the MAC address of the unused Ethernet port (eth0 in my case). Then go to the IPv4 settings tab and in the "Method" drop down list, select "Shared to other computers".
- Under the IPv6 settings tab and in the "Method" drop down list, select "Ignore". and then press save.
- Now Power up the RPi & connect it via Ethernet cable to the unused Ethernet port on your PC. Once the green "LNK" LED and the "10M" orange LED light up on the RPi board, the Raspbian image has booted and an IP address has been assigned to the RPi.
- Now go back to the terminal and type "ifconfig -a".
- Note how the IP address on the eth0 interface is now 10.42.0.1. This implies that the Linux PC is basically acting as a router between the 10.42.0.0 network ( really only a point to point network ) on which the RPi and eth0 are attached, and the 192.168.0.0 network, which is attached to the internet & PC via the wlan0 interface. Also note that the mask for the 10.42.0.0 network is 255.255.255.0 . This means that the IP address of the RPi is somewhere between 10.42.0.2 & 10.42.0.254. To find the exact address we can use nmap "sudo nmap -sP 10.42.0.2-254". In my case, nmap reported that the my RPi has an IP address of 10.42.0.73 (Figure 6). If nmap is not installed, you can easily install it with "sudo apt-get install nmap".
Accessing the Raspberry Pi board remotely via SSH
- Now that we know the IP address of the RPi board, we we can login remotely via SSH. SSH is an encrypted version of telnet (with a few additional goodies) that can give us command line access to the RPi over the network. To login into the Raspberry Pi over SSH we need to type in our terminal: "ssh 10.42.0.73 -l pi" (or ssh firstname.lastname@example.org). Basically we're typing the name of the command "ssh" followed by the IP address of the RPi, followed by the username. Remember the default username for the Raspbian Distribution is "pi" and the password is "raspberry".
- Choose yes if asked if this is a safe connection ( first time to ssh into the RPi). If all goes well, our terminal window is logged into the RPi. Any commands that we type into that window from now on will affect the Raspberry Pi and not the Linux PC.
Configuring your Raspberry Pi over SSH
- The next step is to type "sudo raspi-config". (see notice in Figure 7) Once you do this, the raspi-config tool will run (figure 8).
- From the raspi-config menu, first select "8 Advanced Options" -> "A5 Update" & hit enter. This will update the raspi-config tool to the latest version.
- The Raspbian image is designed to expand into 2GB space on your SD card. This means that if you are using a larger SD Card, say 4GB or 8GB, the additional space is not part of the root file system partition. To use all the space on your SD card select "1 Expand Filesystem" and hit enter. This will expand the root file system partition to fill the entire SD card. The actual partition expansion will happen on reboot.
- The other major option is "8 Advanced Options" -> "A3 Memory split". Hit "Enter" and then choose an appropriate memory split ratio. I recommend using 64MB for the GPU, but you can change this depending on what you are doing.
- For the other options, I highly recommend that you explore them.....I don't recommend overclocking the RPi ( "7 Overclock" option) beyond 800MHz and I keep the default for the "8 Advanced Options" -> "A4 SSH" (run SSH server on start up) . For "3 Enable Boot to Desktop" I always choose to boot into the command line first.
- When you're done, use the right/left arrow keys (or tab key) to select <Finish>. This will cause the RPi to reboot with all the requested changes. This reboot might take an additional minute or two if you selected to expand the root file system partition. Note that when you reboot, you lose your SSH connection and your console window will now be associated with your Linux PC once more.
- When the RPi reboots, SSH into it again via "ssh 10.42.0.73 -l pi" as before.
- Once at the RPi prompt shown (Figure 7), type "sudo apt-get update" followed by "sudo apt-get upgrade" or alternatively we can do both at the same time "sudo apt-get update && sudo apt-get upgrade". The first command consults the /etc/apt/sources.list and updates the database of available packages. The second command checks updates for all installed packages and then prompts to download and install them. When it does this accept the updates (type Y) and hit enter. When the second command completes ,you will have the most up-to-date Raspbian Linux OS available for the RPi.
Remote login into the Raspberry Pi Using VNC
SSH is great if you want to remotely access the RPi from the command line. The Raspbian OS also comes with a Desktop GUI environment called LXDE. If can access the LXDE desktop over HDMI by typing "startx" in the command line window. This will not work over SSH. Luckily we can still remotely access the LXDE Desktop from the Linux PC, using the VNC protocol.
- First we need to install the VNC server software on the the RPi. To do this, SSH into the Raspberry Pi and type "sudo apt-get install tightvncserver". This will install the VNC server software on the RPi. Then type "tightvncserver" to configure the VNC server for the first time. You will then be asked to enter a password (8 characters only) & confirm it. I used "raspberr". You will then be prompted to enter an optional "view only password". This is not needed and you can choose to not set one by saying no. the next step is to type the following into the RPi SSH session to start the VNC server: "vncserver :1 -geometry 1280x720 -depth 24". This starts a VNC server on display number 1 with a resolution of 1280 by 720 and a color depth of 24. At this point the VNC server should be running on the Raspberry Pi.
- Now open another console window on your Linux PC and install a VNC viewer (client) on the Linux PC with the command: "sudo apt-get install xtightvncviewer ". Then in the same console window (Linux PC) type "xtightvncviewer &". The ampersand allows us the run the application in the background.
- This will open the VNC viewer on our Linux PC (a small messagebox...see Figure 9). Type in the VNC server address that you want to connect to i.e. the RPi IP address & display number "10.42.0.73:1". You will then be prompted to enter your VNC password. Type that in and press enter. You should see the window shown in Figure 10. You now have full control over your Raspberry Pi via both the command line with SSH and the desktop environment over VNC.
Another cool article on Setting up your Raspberry Pi can be found here: Raspberry Pi-ing, MacGyver Style