A new version of this series has been published. Please refer to the new index for updated articles and ordering. This article is kept for historical reference, but should be considered out of date.
Important: This article is part of a series (see index here). Each post builds on the previous ones. I cannot make any promises as to your results if you have skipped something important, or have decided to build off of a completely different OS distribution.
Self-Promotion: I have recorded this series as a screencast for Pluralsight:
If you have a Pluralsight subscription, please consider watching it. Thanks!
A couple of years or so ago, I started looking into replacing the aging laptop that was acting as my home server; sharing files, media, and doing backups. Its fan was starting to sound less and less happy as time went by, and I knew it wouldn’t be long before it stopped working completely. Laptops use a lot less power than a desktop computer, so you’d think they’d make great servers, but they’re not really engineered to be on 24/7.
I’d seen a few posts about the Raspberry Pi and it seemed that it was capable of all the things my old laptop was doing while using even less power than a night light, and making no noise at all. I picked up my first Raspberry Pi at my local MicroCenter, and started putting it to work. It now spends its life mounted to a floor joist in my basement, right next to the wireless router.
What’s a Raspberry Pi?
So what is this thing, exactly? You can go to its website if you want the full rundown, but the gist is that it’s a Linux computer the size of a deck of cards (or a deck of Uno cards if you put it in a case). It’s not the prettiest computer in the world. The earlier models didn’t even really have a “front”. Because it’s so small, there were ports sticking off every side of the board.
Note: The newer models (B+, 2B, Zero) have consolidated the ports so that cables are only sticking out of one or two sides now.
The Raspberry Pi was designed as an affordable computer to teach students computer programming on. It has since caught on in the “maker” community for its ability to act as a cheap brain for a wide variety of electronics projects.
There are several different models currently for sale. The $25 model A has 256 MB of RAM, and 1 USB port. The $35 Model B has 512 MB of RAM, 2 USB ports, and a built-in Ethernet port. The B+ builds on the B and while it doesn’t change any of the key attributes of the system like RAM or CPU speed, it doubles the number of USB ports to four, moves some of the connectors around into a little nicer arrangement, and uses a bit less power. There was an earlier, 256 MB version of the Model B as well, but that was completely superseded by the 512 MB version.
Finally, there’s the Raspberry Pi Zero, which only costs $5, but has some serious limitations in both memory, speed, and connectivity. It’s a great choice for building small projects, or for fulfilling the Raspberry Pi’s original goal of teaching children to code, but it isn’t quite suitable for this project.
But I don’t know Linux
Yeah… that’s pretty normal. Let’s face it, Linux is not an OS you’d put in front of your grandmother or non-technical spouse. For people used to Windows or Mac machines, Linux is going to be very unfamiliar. You don’t get to just right-click on things and pick “Properties” to set stuff up. When you plug in new hardware, Linux doesn’t automatically download drivers from the internet and set them up for you.
For those of us that were around for the first wave of home computers in the 80’s, and remember tweaking out the settings in autoexec.bat to get the memory settings just right so that we could play a certain game, this will be like a wave of nostalgia. For the younger folks, this will seem very strange and foreign.
Linux is an enchanted land full of magic words that you have to get exactly right in order for them to work. You have to stand in the right spot, at the right time of night, under exactly the right moon, and you’d better be sure that the chicken you’re about to sacrifice is a lefty, or you’ll bring doom and destruction on all the land.
Okay, it’s not quite that bad, but if you are uncomfortable with the idea of following instructions that tell you to type an obscure string of commands and parameters with little or no explanation as to what they mean, you’ll need to get over that fear. The internet is your friend, and you can look up how to do just about anything, but there are a lot of things to configure, and people aren’t always going to tell you why something has to be phrased the way it is.
In this series, I’ll try my best to explain the meaning of the obscure commands as best as I can, at least the ones that I understand.
What hardware do I need?
Unless you bought some kind of bundle, your Raspberry Pi will need a few accessories before you can do anything with it. The Raspberry Pi doesn’t come with a power supply, or any kind of storage. When you buy a Pi, that’s all you get. A single-board computer, and nothing else.
You’ll need to supply your own monitor, keyboard, and mouse. The monitor can be anything with an HDMI or composite video input. There are adapters available to go from HDMI to VGA if that’s all you have available, but they can be pricey. Any USB keyboard will do, and if you’re planning to stick to the command-line interface, you won’t even need a mouse, but without one you won’t get to play with the X desktop, and it does come in handy at a few points in this series.
The power supply can be almost any Micro-USB phone charger, although it must provide at least 700mA (1000mA for the Pi 2). Since the quality of the power supply can directly affect the stability of the system, I’d recommend buying a high quality supply like the Raspberry Pi branded 1-Amp power supply. They’re only about $10, and will save you frustration later. I have some leftover chargers from old cell phones, and some of them claim to be full 1-Amp supplies, but can’t even power the caps-lock light on my keyboard. The better your supply, the better your experience will be. Trust me, it’s worth it.
Note: In general, you should try to avoid plugging things into the Raspberry Pi while it is running. Linux is more than capable of hot-plugging peripherals, but with such a small power supply, the Raspberry Pi has tendency to “brown out” and reboot when you plug things in. Your basic flash drive is probably safe, but plugging in a game controller might power-cycle the computer. You’ve been warned.
Storage comes in the form of an SD card. As part of this series, I’ll show you how to boot the Raspberry Pi from an external hard drive, so an SD card over 8GB is probably overkill. I used to say 4GB, but the newer Raspbian “Jessie” release needs a little more space. Once you’re booting from the hard drive, the speed of the card won’t matter anymore, either, but faster cards will make some of the initial setup noticeably faster. Larger cards will take longer to back up though, so I usually stick to an 8GB card while I do the build.
Finally, you may want to buy a case of some kind. There are plenty to choose from, and there are even plans you can print out and fold up to make a case out of card paper. Many people seem to like making cases from Lego bricks as well. I’d recommend a decent protective plastic case with keyhole slots on the back so that the whole thing can be mounted somewhere when you’re finished. You could also Velcro the Raspberry Pi to the side of the hard drive if you want.
What software do I need?
The Raspberry Pi has no built-in operating system of any kind. It expects to find its OS on the SD card when it powers up, so you’ll need to get an OS onto the SD card before it’s going to do anything.
Note: Older versions of these posts talked about using the Raspberry Pi Foundation’s “NOOBS” image, but that really does cause more problems than it solves when building a server, so I have removed that information. If you really want to read that stuff, then you can use the Internet Archive’s Wayback Machine:
These days, I only recommend getting a plain, Raspbian image from the Raspberry Pi Foundation’s download page, and writing it directly to the card using a program like Win32 Disk Imager. It will boot a little faster because there’s no pause for the recovery mode that you’re probably not going to use anyway, and the resulting SD card’s layout will be much simpler, with fewer partitions.
You’ll also want to go get the SD Association’s “SD Formatter” tool. This will help you reclaim the unallocated space on your SD card in the event that you need to start over again. When you write a 4GB image to a 16GM SD card, you can’t just stick it in a Windows machine, reformat it and expect to get all the space back. Windows is going to see an SD card with a 4GB partition, and 12GB of unallocated space which it will totally ignore. When you tell Windows to format the drive, it’s just going to format the 4GB partition, and leave the other 12GB alone. SD Formatter will format the whole card and get all your space back.
You can accomplish the same effect using something like diskpart on Windows or fdisk on Linux, and you’ll need them if things go really wrong, but in most cases, SD Formatter is all you need. See the supplemental post “SD Cards Gone Bad” for more information on using diskpart to recover corrupted SD cards.
That’s it for the introduction. In the next post, we’ll start building the initial OS image, and get the machine up and running.