Raspberry Pi basic setup with Raspbian

I just got my first Raspberry Pi and read a lot of guides on how to set it up but I’ll think I will write this down myself to have as a future reference. This is done with OS X 10.8.

This will set up a Raspberry Pi model B to run Raspbian and have the file system on a USB device instead of running on sensitive SD-Cards.

There are two reasons to do this. As I mentioned the SD-Cards are more sensitive to power breaks and USB-devices and you can end up with a corrupt file system if you are unfortunate.
The second reason is write speed, USB are faster so you end up with a overall faster RPi if you run a lot disc io operations.

What you need:

  • Raspberry Pi Model B
  • SD-Card (at least 2GB)
  • USB device (pen, flash memory, hard drive etc)

Start off by downloading Raspbian here >>
Unzip the downloaded file.

Insert the SD-card into your computer and find out it’s location (open Disc Utility and running a check on it will display the location). In my case the location is /dev/disk2.
Open terminal.

#Unmount it
diskutil unmountDisk /dev/disk2

#Flash it with the unzipped image
#this will take some time.
sudo dd bs=1m if=~/Downloads/2013-02-09-wheezy-raspbian.img of=/dev/disk2

The next step is to insert the SD-card and your empty USB-device into the RPi and start it.
I don’t have a monitor to spare so I just SSH into it to set everything up. Find its IP (download Pi Finder to do that if you cant login to your router or run arp -a to find it’s IP).
And then SSH into it from your computer.

ssh pi@your.ip
#The default password is "raspberry"

Now we’re in!

First run

sudo raspi-config

to set up timezone, locales etc.

Now it’s time to copy everything from your SD to the USB-device and instructing the RPi to use it as the root file system.
At the same time we write protect the SD-card to be sure that nothing gets written to it.
The actual booting will be done from the SD but after the boot you can remove it if you like.

Run these:

#Find USB location. Close to the end of the output you'll find your USB device with something like sda:sda1
dmesg

#When you have your USB location, copy everything from the SD-Card to it. Change sda1 to whatever yours is. This takes a while
sudo dd if=/dev/mmcblk0p2 of=/dev/sda1 bs=512

#Time to tell the RPi to make the root partition the USB device. Change the line where it says root=/dev/mmcblk0p2 to root=/dev/sda1
sudo nano /boot/cmdline.txt




#Next step is to point /dev/sda1 to /. You do that by editing /etc/fstab. 
sudo nano /etc/fstab

It should look like this:

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults,ro       0       2
#/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/sda1       /               ext4    defaults,noatime  0       1

You do three things here. First you make /boot read only. Second you comment out the SD-Card pointing to / and last you make the USB device point to /.

Now restart. (sudo reboot)

Connect to it again and if you run “df -h” you see something like this:
orreMBA 2013-04-04 kl. 19.39.39

The USB-device only has a total size of 1,8GB.
Lets change that and take advantage of it’s full capacity.

sudo resize2fs /dev/sda1

And look!
orreMBA 2013-04-04 kl. 19.42.58

Now we’re done and can start playing around.