Raspberry Pi Day2: Setting it up


So unlike most of the computer I’ve bought in the past, the Raspberry Pi doesn’t come with its own operating system pre-installed (which actually saves me the time of removing, what is usual, Microsoft Windows). In fact the reason you can’t just plug in the Pi and boot it up first time is that the machine doesn’t have a hard drive. No hard drive means no storage, no storage means nowhere for an OS. Thankfully the Raspberry Pi OS is free and runs from a SD card, the ones you normally see in digital cameras etc. I’m going to be using a SanDisk SD 8G memory card I had laying around, hopefully its read/write speed rating of only 4 will be fast enough. I’m not sure what the Raspberry boys officially recommend, but they do say use at least a card with capacity of 4GB.

Downloading the Pi OS image

You’re not tied into a specific operating system for your Pi, however the Raspberry boys do recommend a few ‘flavours’ of Linux that they’ve rolled themselves. This means its a regular Linux distribution with a few small tweaks and modifications to boost performance on your Pi.

I went with the official Raspbian Wheezy release. The downloads about 500Mb, so may take a few minutes, but while that’s coming down the pipes you can continue getting the SD card ready.

Oh yeah and don’t forget to unzip it once it’s downloaded, that may take a while too.

Preparing your SD card for the Raspberry Pi

So first things first; you need a PC that is connected to the Internet and can write to your SD card somehow. My laptop has a SD slot, but if yours doesn’t you can pick up a dirt cheap USB SD card reader for as little as £3.

All the commands I’ll be listing here, and in future articles, will be Linux ones. If you’re developing on a Windows or Mac box you’ll have to use the equivalent ones.

Putting the SD card into my laptop, I can see the system detects the storage device by running the following from Terminal:

sudo fdisk -l

Thats a lowercase L at the end of that command if it isn’t obvious.

Below shows a truncated version of the output, showing the 8GB card.

Disk /dev/mmcblk0: 7948 MB, 7948206080 bytes
81 heads, 10 sectors/track, 19165 cylinders, total 15523840 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/mmcblk0p1 8192 15523839 7757824 b W95 FAT32

Formatting your SD card for the Pi OS

So in the example above, my storage device is listed as /dev/mmcblk0 (catchy!). Yours will definitely be different so don’t worry when you see something else after /dev/.

Your Linux box is likely to have been ‘helpful’ by auto-mounting the device ready for use. Sadly we need the device unmounted so we can format it ready for our image.

Run this command, replacing your device name where mine is

sudo umount /dev/mmcblk0

Now the device is unmounted, we can format it to an empty FAT partition. Run the following, again replacing my device name with yours. CAUTION: Using the wrong device name could wipe your entire hard drive by mistake… don’t do that!

sudo fdisk /dev/mmcblk0

Use the interactive fdisk program to delete any old partitions on the device before adding a single partition. When adding a partition (option ‘n’, don’t forget to change its type by pressing ‘t’ to FAT16, hex character 6). Then write the new table with ‘w’ and you’ll have a nice FAT16 SD card 🙂

Now remount the SD by entering

mkdir ~/PiSDCard
sudo mount /dev/mmcblk0 /home/Paul/PiSDCard

So far so good.

Writing the Raspbian IMG to the SD

Now the SD card is ready, its time to get that downloaded content onto it. After unzipping the file you downloaded, you can write it to the SD device with the following command.

(Just a note, it took a while on my machine and completely locked up my machine.)

sudo dd bs=4M if=~/Downloads/2012-12-16-wheezy-raspbian.img of=/dev/mmcblk0

It’ll take a while, but eventually you’ll see something like this:

462+1 records in
462+1 records out
1939865600 bytes (1.9 GB) copied, 1325.72 s, 1.5 MB/s

You can see it wrote the 1.9GB Raspberry Pi ‘Raspbian’ operating system to the SD card in just over 20 minutes. (Hardly fast)

Unmount your SD card as you did before and then you can put it into your Pi.

Now your SD card is set to boot your Raspberry Pi for the first time.

Connecting up your Pi for the first time

2013-08-22 21.47.21

The Pi doesn’t have a power switch, so it comes on when its plugged in. Keep the USB power supply switched off at the wall until you’ve plugged everything in.

With the micro USB power supply, a HDMI cable and a USB Wireless Keyboard/Mouse all plugged in I’m pretty much ready to rock. Oh yeah and don’t forget to put the SD card into the slot beside the USB power (not pictured).

Switch on the wall power supply and you should see a series of tiny bright lights flicker on, as well as your HDMI screen spring into action.

2013-08-22 22.42.30

After this you should be dropped in at the blue background raspi-config screen. I then ran the updates.

By selecting finish I had my first ever working Pi! Result

Although sadly by now (due to TV distractions) its pretty late. So no more playing with the OS. Time to issue a shutdown command and schedule this to post for tomorrow.

Hopefully next time I’ll get around to sniffing around the OS and setting some useful things up, like an SSH account, WiFi and maybe even a few cron scripts.

Leave a Reply

Your email address will not be published. Required fields are marked *