Yet Another Raspberry Pi Bootstrap

I'm a hacker, and I love to tinker. I bought a Raspberry Pi many months ago when they first came out, and put it on a shelf for far too long while I dealt with other projects.

This last weekend, I had an opportunity to fall in love with this little device, and after configuring several all weekend long, I'm comfortable talking about some of the bootstrap procedures you should be doing with each new install. (I have both the initial run Raspberry Pi Type B with 256mb of RAM, and 2 of the new 512mb models. I can't speak about Type A models and their lack of Ethernet ports.)

For now, I'm using the 2012-10-28-wheezy-raspbian.img image direct from the Raspberry Pi Downloads page. Some of these hacks may be ineffective with future releases. I won't talk about plugging in the cables, as I'll assume you have it plugged into a HDMI monitor, USB keyboard, and network jack hooked up for simple network updates. I can recommend you purchase a dedicated and powerful USB power supply for your Pi, as some USB Power Supplies don't supply enough AMPs to run the Pi reliably (it expects at a minimum 700ma, but we give it 1A).

Making a Raspberry Pi Boot SD

Again, the Raspberry Pi site has great instructions which I'm merely repeating here. I have a Mac, so I use any USB-SD Adapter to mount a fresh SD card on my machine. Run Disk Utility, where you can reformat the SD Card in MS_DOS (FAT) format, which is compatible between the Mac and Debian. Once reformatted, un-mount the resulting newly formatted disk (do not eject). Leave Disk Utility running while we do the next steps.

Run the System Profiler application from the same folder on your Mac. We need the BSD name of the SD Card you just formatted. Once the System Profiler is running, select the USB subheading under the Hardware list on the left column. Then find the Mass Storage Device that is your SD Card (same capacity) in the list of devices in the USB tree on the right hand side and select it. On the bottom of the frame will be detailed information about the device, and you're looking for the BSD Name. In my case, it was disk3. Quit System Profiler, we have the info we require.

Open the Terminal Application in your Utilities folder. We'll be using the command line utility dd to copy the diskimage to the SD card. At the prompt, type:

sudo dd if=

then find the downloaded Raspberry Pi disk image on your computer 2012-10-28-wheezy-raspbian.img ( it should end in .img, not .zip), and drag and drop it into the Terminal window. This saves you time by automatically typing the path to the disk image. At the end of the line, continue with:

of=/dev/diskn bs=1m

where diskn is replaced with the disk number. I would put disk3 in this case. Hit the enter key, and the Terminal will ask for your admin password, then do nothing for a long while silently copy the disk image onto the SD Card. When it's done (2-10 minutes?) it'll give you a readout of the work it's done. You're almost ready to boot your Raspberry Pi!

Switch to the Disk Utility application again, and now select the SD Card in the left hand column, and use the Eject button to safely eject it from your system. Remove the SD Card, and put that freshly burned OS into your Raspberry Pi!

Boot Your Raspberry Pi

Thankfully, this image immediately boots into raspi-config, where you can do most of the basic setup required for a stable, functioning Raspberry Pi. The ones you should definitely configure the first time are listed below:

  • expand-rootfs
    Use this to expand root partition to fill SD card. The disk image only takes up 2GB. If you copied it onto a card any bigger, you only get to use 2GB of space. This will happen upon reboot.
  • configure-keyboard
    Use this to set keyboard layout - don't be swayed by the list of UK only boards. Use the 'more...' to find US keyboards.
  • change_pass
    Change password for the default ‘pi’ user (this is you)
  • change_locale
    Set locale, so both you and your Pi agree on the languages and character encodings. I use US UTF-8
  • change_timezone
    Set timezone, so everyone agrees it's the right time. The Raspberry Pi gets it's time from a network server, and doesn't have an internal clock.
  • memory_split
    Change memory split (between CPU and GPU). You may not need to adjust this. Since I run my Raspberry Pi's headless, I decrease the memory given to the graphics (GPU) in favor of processing memory (CPU). The default is 64, I bump it to 32. If you were going to run your Raspberry Pi as a media player, you might bump this to 128 or higher.
  • ssh
    Enable or disable ssh server. If you'll be using the Raspberry Pi as a desktop replacement you may not need to turn this on. I need it on as I run them headless, and we'll secure this connection next.

Once you've made all your locale settings and changed the default password, you should reboot your Pi when it asks as you exit raspi-config.

Your Raspberry Pi will immediately reboot and once done it will allow you to login to the shell. This initial reboot may take abnormally long, especially if you re-sized the disk image size, but thankfully this happens only once.

To the Command Line!

Once we've logged into our newly booted Raspberry Pi (username: pi, password: the one we setup during raspi-config), we have some quick work to do by typing in some simple commands.

  1. Update/Upgrade Everything!

    Run these simple commands (you'll be asked for your password after each, and possibly if downloading more files is OK) to update and upgrade any slightly out-of date packages from this image. This will take a moment while it tunes the system.

    sudo apt-get update

    sudo apt-get upgrade

  2. Update the Firmware

    On this particular image, it will automatically assist in updating your Raspberry PI's firmware using the rpi-update package. It might not be neccessary with a shiny new Pi, but older board revisions might require updated firmware to access features or simply bring them in line with the current I/O offerings. One quick command, and your Pi will reboot when it's done.

    sudo apt-get install rpi-update

  3. Secure the default SSH keys

    The ssh keys that come with the Raspberry PI aren't secure (they're pre-generated and every Rasberry Pi running Debian has the same ssh keys). We'll dump the original ones, and re-generate new ones.

    sudo rm /etc/ssh/ssh_host_*
    dpkg-reconfigure openssh-server

    This will ask for responses a few times. Simply hitting the enter key is enough. You don't have to change much in this process. Once you've done this you'll need to either remove or edit the following file in your home folder. Having struggled with using the text-editor vi, we will be using the alternate editor nano, which is much easier to use.

    sudo nano /home/user/.ssh/known_hosts

    If you've only got a few entries, then just remove the file and it'll regenerate the next time you ssh into another computer. Control-O to save, Control-X to close the file, nano is easy!

  4. Reliable Memory on your Raspberry Pi

    One last trip to the command line, run this code to fine tune some Memory issues:

    sudo nano /etc/sysctl.conf

    Then at the bottom of the file, bump the following value to twice it's size (16,248)

    vm.min_free_kytes = 8192

    This setting reserves some memory so your Raspberry Pi shouldn't suffer from problems with network drop-outs (this has been reported with large downloads and torrent clients).

  5. Change Hostname

    You might as well configure this simple setting. This is the name of the machine, and greets you at every prompt.

    sudo nano /etc/hostname

    It's currently raspberrypi, change it to your new preferred name. Before you're done, you need to change this same name in this file:

    sudo nano /etc/hosts

    Then reinitialize the file to enable the changes.

    sudo /etc/init.d/ start

    You would need to logout and back in to see the new prompt.

Did I forget Something?

Leave a comment if I seemed to forget some obvious tune-up every Debian expert knows. I'm only starting with this brand new platform, and I quite enjoy the low-power and small size as benefits when developing for this micro-sized machine. If you're looking for next steps to do with your Raspberry Pi now that's it up and secured, check our shortlist of ideas below, all of which I used on my own Raspberry Pi with great success!