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.
Note: This article is part of a series. See the Index for more information.
Updates: Raspbian Jessie has been released. The installation process is still the same, but some minor adjustments will need to be made. Most importantly, Jessie boots straight to the desktop by default. You can run the new windowed version or raspi-config by clicking “Menu”, then “Preferences”, and then “Raspberry Pi Configuration”. You’ll want to change the “Boot” option to “CLI” and then click OK.
You can also exit the desktop by clicking “Menu”, then “Shutdown”, selecting “Exit to command line”, and then clicking “OK”. Once at the desktop, run raspi-config as usual and change the boot configuration so that the Pi boots to the command line.
Everything else should be more or less the same.
Self-Promotion: I’ve recorded this series as a screencast for Pluralsight:
If you have a Pluralsight subscription, please consider watching it. Thanks!
The first thing any computer needs is an operating system. There are several Linux distributions to choose from. You can think of a distribution as an “Edition” of Linux. Just like Windows comes in Home, Business, and Enterprise editions (or whatever they’re called this week), each Linux distribution consists of the same core OS, but with different combinations of additional features added. In the Linux world, these “features” could include things like the entire windowing system, so it’s a little more dramatic than Windows editions, but you get the point.
In this series we’ll be building on top of Raspbian, which is a Raspberry Pi variation on the Debian Linux distribution. It is available from the Raspberry Pi Foundation’s download page as an image, or as part of the “New Out Of Box Software” (NOOBS) package.
As mentioned in Part 1 of this series, NOOBS lets you pick more than one distribution and multi-boot between them. This can be useful for a Raspberry Pi that stays permanently attached to a television in your living room, allowing you to use it as both a media center and a gaming station. For a dedicated home server like this, though, it’s unnecessary.
Note: At this point, you can follow the directions at the Raspberry Pi Foundation’s own help pages. The tutorial there is very complete, and has videos to explain the process in greater detail than I’ll be going into here. In the interest of being complete, I’m going to summarize the instructions here as part of the series.
- A Raspberry Pi, power supply, etc.
- An HDMI or composite monitor, keyboard, and a mouse (optional)
- A wired network connection
- An SD card of at least 4GB
If you plan to boot from a hard drive, as covered later in the series, then you don’t need anything bigger than this.
Create the SD card
Decide whether you want to go with NOOBS or with the Raspbian image, and follow the appropriate instructions below.
Using an image file (recommended)
Go to the Raspberry Pi Foundation’s download page, and get the current Raspbian image. At the time of this post, that is the 6/20/2014 release. You can download this directly, or you can save the foundation some bandwidth costs and download via BitTorrent.
Get a copy of Win32DiskImager, and use that to write the Raspbian image to your SD card. More detailed instructions for multiple operating systems are available from the Raspberry Pi Foundation’s site. When you’re done, eject or “safely remove” the SD card from your computer.
Hook the Raspberry Pi up to your monitor, network, and keyboard (and mouse if you have one). Insert the SD card you prepared above. Finally, plug the power supply into the Raspberry Pi, and skip ahead to the “First Boot” section.
Using NOOBS (meh)
There are two versions of NOOBS. The Full version includes all the files needed to install any of the supported Linux distributions. The Lite version is much smaller, and will download the needed pieces at installation time. If you’re only planning to do this once, then the Lite version could save you some time. If you imagine that you’ll start over again several times before you’re happy with the result, then having the Full version around will cut out a lot of time spent re-downloading things again in the future.
Download your preferred version of NOOBS, and save it off somewhere. Format your SD card as a regular, Fat32 disk, preferably by using the SD Association’s SD Formatter tool. Copy the files from the NOOBS archive to the newly-formatted SD card, and “eject” or “safely remove” the SD card from your computer.
Note: If you have an SD card that gets corrupted, and even SD Formatter won’t bring it back to life, see my supplemental post “SD Cards Gone Bad” for some steps that might help you get your card back.
Hook the Raspberry Pi up to your monitor, network, and keyboard (and mouse if you have one). Insert the SD card you prepared above. Finally, plug the power supply into the Raspberry Pi, and allow it to boot to the NOOBS menu.
Note: In this screenshot, multiple operating systems have been selected for illustration.
You should see a list of operating systems, and some drop-downs for selecting your language and keyboard layout. I’m not exactly sure what the language options affect, since you’ll just have to set them again later on, but it wouldn’t be there if it weren’t important, right?
Pick your language settings, and check “Raspbian” in the list of distributions at the top. You could select multiple OSs, and get a menu at boot time, but for this server we’re only interested in Raspbian. Click “Install” at the top of the window, and go make lunch. This part is going to take a while, and even longer if you chose the “Lite” version of NOOBS, since it will have to download the OS at this point.
Eventually, NOOBS will finish setting up the OS, and you’ll be prompted to restart the Raspberry Pi. Clicking OK will reboot, and after a lot of scrolling start-up messages that may frighten users who are not used to seeing behind the curtain, you are ready to proceed.
Note: The screenshots that follow are taken from a remote, SSH session running through Putty for Windows. If you don’t know what that means, that’s fine, it’s just that my screenshots are going to have a window frame around them, and I thought you should know why.
This program allows you to make changes to the configuration of the OS itself, and certain hardware settings. Perform the following operations to configure the Raspberry Pi:
Go to “Advanced Options” from the main menu and then select “Update”
This will make sure that you’re using the latest version of raspi-config. It only takes a few minutes, and you never know what improvements they might have made since the last image was published. If you just downloaded the image, then you’re probably already up to date, but it doesn’t hurt to check anyway.
If you used NOOBS to create your SD card, then this was taken care of this for you. If you installed from an image file, though, you’ll want to select this option. Image files are typically shrunken down to take up less room, so if you put a 4GB image on a 16GB SD card, you’ll need to expand the file system to get the other 12GB of space on the card back.
From the main menu, select “Change User Password”
This will set the password for the user named “pi”. The default password is “raspberry”, but since “pi” is the all-powerful administrative user, you’ll want it to have a different password than everyone else’s, right?
Boot to Console
Go to “Enable Boot to Desktop/Scratch” from the main menu and choose “Console Text console, requiring login”.
Since this will be a server, you don’t want to waste resources displaying a desktop that no-one ever looks at. At the time of this writing, this is the default option, but I like to check just to be sure.
Set up language and locale options
Go to “Internationalization Options”
Set up all three options (Locale, Timezone, and Keyboard Layout) to match where you live. For the Locale, make sure that only the locale that matches your country is checked off.
In previous versions of raspi-config, overclocking was available, but voided your warranty. In the current version, this is no longer the case, and the Raspberry Pi is now capable of dynamically governing its own clock, turning it up when needed, and turning it down when the computer is idle or if it gets too hot. It does such a good job, that I usually give the Raspberry Pi free reign to go as fast as it wants whenever it wants.
CAUTION: The ability to overclock varies from board to board, and is affected by your power supply as well. If you are using some old leftover cell-phone charger you happen to have lying around in a drawer, this may not work for you. If you’ve invested extra money in a high-quality power supply, you’ll probably have better luck.
Until you know how your particular combination will behave, it’s probably safest to leave it running at the stock 700MHz. You can always come back to raspi-config later on and change it once you have everything stabilized.
Name that Pi
Go to “Advanced Options” from the main menu and then select “Hostname”.
Give your new Raspberry Pi a unique name. For this series, I am calling mine “RPHS” for “Raspberry Pi Home Server”.
Go to “Advanced Options” from the main menu and then select “Memory Split”
The 512MB of memory in the Raspberry Pi Model B can be used for graphics or by the CPU. During the initial setup steps, it can be useful to dedicate more memory to graphics to make the X windows desktop more responsive. Once the setup is complete, you’ll get better performance by dedicating less of the RAM to graphics processing. I set mine to 128MB during the initial setup phase, and then back down to 32GB when I’m done.
Go to “Advanced Options” from the main menu and then select “SSH”
Since this will eventually be a “headless” server with no monitor or keyboard, you’ll need a way to communicate with it. Enabling the SSH server will allow us to “terminal” into it using an SSH client program like like Putty for Windows. This will be just like sitting at the command like in front of the computer. It’s also how I’m getting the screen-shots for this series.
From the main menu, select “Finish”, and answer “Yes” when prompted to reboot.
The new settings will be applied, and the Raspberry Pi will reboot.
When the Raspberry Pi reboots this time, it will be more or less a working computer. It doesn’t have a lot of programs installed so far, but it’s a starting point. You should see a login prompt similar to the following.
Log in using the user name “pi”, and the password you set up earlier (or “raspberry” if you skipped that step). It’s not particularly good form to log in as the “pi” user all the time, since “pi” is an administrative user, not meant for daily use. One of the first orders of business will be to create a user account for yourself.
Type the following commands, substituting your name for the highlighted “USERNAME” where appropriate, and filling in the relevant information when prompted. You can just press enter to accept the defaults for things like room #, phone #, etc.
sudo adduser USERNAME sudo usermod -a -G users USERNAME sudo usermod -a -G sudo USERNAME
Let’s break down what that all means.
- “sudo” lets you run things with elevated privileges.
It’s actually a little more complicated than that, but you can think of it as the equivalent of Windows’ “run as administrator”. There is a lot more to the sudo command than that, but this definition is adequate for our purposes.
- “adduser” does just what it says, it adds a user with the specified name (USERNAME).
- “usermod” modifies the named user (USERNAME). Here, you are appending (-a) the user to the group (-G) “users”, and to the group “sudo”. The “sudo” group is the group of users who are allowed to use the sudo command. Not everyone can run things with elevated privileges. The “Pi” user had this ability out of the box, and now you’re granting it to your own account.
You now have a user account that is specific to you, but with the necessary rights and privileges to perform maintenance tasks on the machine.
Test out your new user by typing “logout”, and pressing enter. Enter your new username and password when prompted in order to log on as yourself. your prompt should now reflect your new user name as well as the new name of the machine. At this point, you can play around with all the Linux-ey things for a while, and realize just how much you’ve forgotten about command-line interfaces. It’s all right, we’ve all forgotten.
You can also type “startx” to start up the desktop, and poke around with a mouse. Go ahead and play. When you’re done, click the red “power” button in the lower-right corner and click “Logout”. You’ll be back at the command prompt, which is where we’ll spend most of our time in this series.
Note: While you’re installing and configuring software, it’s probably still a good idea to continue logging on as “pi”. There are certain steps where this is more important than others, but it’s simpler for this series of articles if you just keep using “pi” for installation and configuration tasks.
You’ve reached a milestone. The Raspberry Pi is now a fully-functioning computer. It has been localized, and somewhat personalized. Now is the ideal time to take a backup.
Shut down the Raspberry Pi “politely” with the following command
sudo shutdown –h now
This tells the compute to shut down “hard”, and to do it now. There are a few different shutdown options, including the ability to schedule a shutdown for a specified time and date in the future. This is the command you’ll use most often, though. After the screen turns off, wait a few more seconds for the Raspberry Pi to finish up any last-minute tasks, make sure all the lights have stopped blinking, unplug the power, and transfer the SD card to your primary computer.
Using Win32 Disk Imager, “Read” the contents of the SD card into a backup file for safekeeping.
I’ll recommend making these checkpoint saves after pretty much each post in this series.
In the next post, we’ll configure the OS and set up remote connectivity so that the Raspberry Pi can be removed from the monitor and keyboard and transplanted to a more permanent home away from your desktop.