Raspberry Pi Home Server: Part 2, Installing the OS

Article Obsolete

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:
(http://www.pluralsight.com/courses/raspberry-pi-home-server)
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.

Prerequisites

  • 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.

First Boot

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.

image

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:

Update raspi-config

Go to “Advanced Options” from the main menu and then select “Update”

image

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.

Expand Filesystem

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.

Change password

From the main menu, select “Change User Password”

image

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”.

image

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”

image

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.

image

Overclocking

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.

image

Name that Pi

Go to “Advanced Options” from the main menu and then select “Hostname”.

image

Give your new Raspberry Pi a unique name. For this series, I am calling mine “RPHS” for “Raspberry Pi Home Server”.

Memory Split

Go to “Advanced Options” from the main menu and then select “Memory Split”

image

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.

Enable SSH

Go to “Advanced Options” from the main menu and then select “SSH”

image

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.

Finish

From the main menu, select “Finish”, and answer “Yes” when prompted to reboot.

image

The new settings will be applied, and the Raspberry Pi will reboot.

Second Boot

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.

RPHS login:

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

image

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.

Wrapping up

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.

image

I’ll recommend making these checkpoint saves after pretty much each post in this series.

What’s next?

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.

This entry was posted in Computers and Internet, Home Server, Raspberry Pi and tagged . Bookmark the permalink.

15 Responses to Raspberry Pi Home Server: Part 2, Installing the OS

  1. Pingback: Raspberry Pi Home Server: Index | MelGrubb.ToBlog()

  2. Pingback: Raspberry Pi Home Server: Part 1, Meet the Raspberry Pi | MelGrubb.ToBlog()

  3. Pingback: Raspberry Pi Home Server: Part 3, Configuring the OS | MelGrubb.ToBlog()

  4. Pingback: Raspberry Pi Home Server: Part 10, CrashPlan | MelGrubb.ToBlog()

  5. Pingback: Raspberry Pi Home Server: Part 10, CrashPlan | MelGrubb.ToBlog()

  6. cheese says:

    i have a problem when i use “startx” to log in as a new username the UI is a bit different and i can’t play minecraft using this user while the “Pi” user can , why?

    • Mel Grubb says:

      Did you add the new user to the users and sudo groups? You may want to check the permissions settings on Minecraft itself. It’s possible that it’s only runnable by the Pi user by default. I haven’t tried it myself, since this series is about building a home server. ________________________________

  7. cheese says:

    and its a little bit weird to do things in the new user UI compare to the Pi user ,the app are not on the desktop and the Pi store needs a registration thingy.

  8. Indeed, I cant tell how much I forgot of command line… (smile)
    But I’m realy excited about this series of articles. I found it two weeks ago and I’m trying to find time to replicate what you did.
    Anyway, just wanted to say thanks! Awsome articles.

  9. Oran says:

    “I set mine to 128MB during the initial setup phase, and then back down to 32GB when I’m done.”
    Typo: Should be 32MB

    Also, with Jessie just released I’m not sure that users should still “Update raspi-config” to the latest version.

    Incredible guide though. Keep it up!

  10. gilad says:

    For Jessie you mention to get out of the desktop to run raspi-config, however for someone not familiar tot he system (as probably most readers of this series) this operation is a mystery – ctrl-alt-F1 (had to look it up somewhere else). Also need to mention that you need to run “sudo raspi-config” because at this stage the sudo concept is yet unknown

    • Mel Grubb says:

      You can exit from the top menu, too. It’s an option in the shutdown menu. I intend to update the posts in-place, but work has been a bit hectic, and I thought the updates would at least tide folks over until I can do the big revision.

  11. DavidA says:

    Just a suggestion: the intro about Jessie reads ‘You can simply exit the desktop …’, I think it would be helpful to say how exactly to do that (Logout?).

  12. Pingback: CrashPi – An off-Site backup for the whole family | MelGrubb.ToBlog()

  13. I repeatedly got an error stating that WinDisk was unable to lock the file error 5. A ‘net search shows that others are having the same problem.
    Here’s what worked for me:
    1. Run WinDisk as administrator (may not be necessary)
    2. Create a folder to contain your backups, not on your C: drive if possible. Again, I don’t know if this is necessary, but I have a Data drive (E:) so I did it.
    3. Close all Explorer windows in which the SD card or your destination folder appear (may not be necessary).
    4. And I think this is the key, don’t browse to your destination folder in WinDisk. Type the whole path, including the drive into the browse window. be sure you add to the end of the path the name you want the .img to have, something like the date, Mel’s blog post number, or something else to identify it when you need to restore it. And you will need to, or wish you could.
    I’m not sure how much other than creating a folder and typing, not browsing, to it are really necessary, but as we say in parts of the Bronx, “It vouldn’t ‘oit”
    Hope this helps someone,
    Kirk

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s