Install an Operating System - Raspberry Pi: A Quick-Start Guide, 2nd Edition (2014)

Raspberry Pi: A Quick-Start Guide, 2nd Edition (2014)

Chapter 2. Install an Operating System

Like every computer, the Raspberry Pi needs an operating system, and Linux is the preferred one for the Pi. That’s partly because it’s free, but mainly it’s because Linux runs on the Pi’s ARM processor while most other operating systems work only on Intel architecture. Still, not every Linux distribution will run on the Pi, because some don’t support the Pi’s particular type of ARM processor. For example, you can’t install Ubuntu Linux on a Pi. In this chapter, you’ll first learn what your operating system options are.

Choosing an operating system is only a first step; you also have to install it. The installation procedure on the Pi is quite different from what you’re probably used to, but it’s not difficult: you need to install the operating system on an SD card. In this chapter, we’re going to install the latest Debian Linux distribution, but the process is the same for all operating systems. You can actually create several SD cards, each with a different operating system, so in the end you’ll have a pretty versatile system that you can turn into completely different machines by simply replacing the card.

See What’s Available

Linux is still the most popular choice for an operating system on the Pi, and it helps you to get the most out of your Pi. Also, many people are already familiar with Linux, whereas the other operating systems running on the Pi are a bit more exotic.

Even if a Linux distribution runs on the Pi, it will often look and behave differently from its regular desktop PC equivalent, because it might use a windows manager that doesn’t need a lot of resources. Also, you won’t find all of the applications you’re used to, such as many popular web browsers or office products.

In addition, you’ll face some limitations around installing the operating system. Modern operating systems are fairly big, and they ship on DVD or are available as ISO image downloads. These images and DVDs contain the full installation process for the operating system; they start a program that detects your computer’s hardware, and then they copy all files needed to the hard drive. Unfortunately, you can’t insert a DVD into the Pi and install it, because the Pi has no BIOS. (See What the Pi Does Not Have.) You can’t boot from an external USB drive, either. You also can’t copy an ISO image of a DVD to an SD card. Instead, you need a snapshot of a system that has already been installed and that you can boot from.

So, you have to create or find an image of a Linux distribution that you can copy to an SD card, and it has to be compatible with the Pi. The easiest way to get such an image is to visit the download page of the Raspberry project.[26] At the time of this writing, you can find images for Raspbian (Debian wheezy), Arch Linux ARM, Pidora, and RISC OS. More operating systems will certainly appear in the future; at the least, Bodhi Linux[27] and openSUSE[28] are already available. Also, some clever folks are currently trying to port Google’s Chrome OS.[29]

At the moment, the best choice for your first steps with the Pi is Raspbian (Debian wheezy). It fully supports the Pi’s hardware, it comes with a full-blown desktop (see Figure 6, The Raspbian (Debian wheezy) desktop), and it contains some useful applications, such as a web browser.

image


Figure 6. The Raspbian (Debian wheezy) desktop

On top of that, it has a powerful package manager that makes it very easy to install more software. We’ll use Debian in the rest of this book, and in the next section you’ll learn how to install it. Note that we’ll use the names Raspbian and Debian interchangeably.

The other distributions are very interesting, too, but they target a different audience. Still, I’ll briefly describe them in the following sections.

Arch Linux ARM

Arch Linux[30] is very minimalist and assumes that you already have a fair amount of Linux knowledge. Arch Linux doesn’t use many resources, and it has a nice package manager, so it’s a good choice when you want to use the Pi as a server. For a desktop system, Debian is more convenient, though, because by default Arch Linux doesn’t ship with a desktop environment. You have to install and configure it yourself.

RISC OS

The Pi doesn’t only run Linux; it also runs RISC OS,[31] for example. This comes as no surprise, because RISC OS was one of the first operating systems designed for the ARM architecture. It still has a lot of fans and is definitely worth a look. RISC OS is not free software, but it is available free of charge to Raspberry Pi users.

Coder

Coder[32] isn’t really an operating system. In fact, it’s just Raspbian, but with a special purpose. Some Google employees created it to offer an easy environment for people who are interested in learning about web development.

If you or your children are interested in developing web applications using HTML5, CSS3, and JavaScript, you should take a look at Coder.

In addition to regular distributions, special-purpose distributions are common in the Linux world. In Chapter 7, Turn the Pi into a Multimedia Center, you’ll get to know Raspbmc, a Linux distribution that will turn your Pi into a multimedia center.

Even though you can’t change the Pi’s hardware easily, you can still turn it into many different machines within a second: simply insert an SD card containing another operating system.

If you don’t know what operating system works best for you, you might want to try a few before settling down. Don’t worry, because in the next section you’ll learn how to play around with various operating systems using NOOBS.

Have a Look Around with NOOBS

The number of different operating systems available for the Pi can be a bit overwhelming for new users. Thanks to the New Out Of Box Software (NOOBS) project, it’s easy to try out various operating systems.

NOOBS is an automatic installer for the Pi’s most popular operating systems. At the time of this writing, it supports Arch Linux, OpenELEC, Pidora, RISC OS, Raspbmc, and Raspbian. Two different versions of NOOBS are available on the Raspberry Pi’s download page.[33] You can download a fairly big zip archive (more than 1GB) that already contains all supported operating systems. Alternatively, you can download NOOBS Lite, which contains only the installer. It will download the operating systems as needed. To make sure you’ve downloaded NOOBS from a trustworthy server, check the zip file’s SHA-1 checksum. (You can learn how to do this in Prepare a Bootable SD Card.)

You need an SD card with a capacity of at least 4GB to install NOOBS. Before you install NOOBS, you have to format the SD card with the FAT file system. If you’re not familiar with formatting SD cards on your operating system, take a look at the official tools for Windows[34] and Mac OS X.[35] On Linux, it’s best to use gparted.[36]

After you’ve formatted the SD card, you can extract the zip archive and copy its content to the SD card. When you extract the zip archive, the content will be stored in a directory named NOOBS_v1_3 or something similar. Make sure you copy only the directory’s content to the SD card, and not the directory itself.

That’s all you have to do to install NOOBS. You can now put the SD card into your Pi and start it. NOOBS will greet you with a simple menu (see the following figure) showing all available operating systems. Use your mouse or your keyboard to choose as many as you like, and NOOBS will start a fully automated installation process. This installation process takes a couple of minutes.

image


Figure 7. You can choose from a lot of operating systems in NOOBS.

In some rare cases, NOOBS will not detect the correct output mode for your display. Usually, you can fix this by pressing one of the following four number keys:

1. Sets the display mode to its default value—that is, HDMI.

2. Selects the HDMI safe mode. It may help when you’ve connected the Pi to a display using HDMI.

3. Try this option if you’ve connected your Pi to a display using composite PAL.

4. This option is for users who have connected the Pi to a composite NTSC display.

Also, NOOBS allows you to start a minimal web browser, so you can search the web for solutions to potential problems. If you’ve installed Raspbian using NOOBS, you can also edit /boot/config.txt from the main menu. In Chapter 4, Configure the Firmware, you’ll learn what this file is for.

After NOOBS has finished the installation, boot the Pi, and it will allow you to boot one of the operating systems you’ve installed (see the following figure).

image


Figure 8. You can choose which operating system you’d like to boot.

If you’d like to remove an operating system or install another operating system, hold the Shift key while booting the Pi. This will open the NOOBS menu so you can choose another candidate. Note that currently NOOBS will always reinstall all operating systems, so you’ll lose all of your data!

NOOBS is great for getting an overview of the Pi’s best operating systems, but it has some disadvantages, too. For example, it doesn’t support all operating systems available, it doesn’t always contain the latest versions, and it needs some space on your SD card. So, it’s often better to cleanly install your favorite operating systems directly on an SD card. In the next section, you’ll learn how.

Prepare a Bootable SD Card

As you saw in Chapter 1, Meet the Raspberry Pi, the Raspberry Pi doesn’t have a BIOS or internal persistent storage. It has only an SD card slot. You use a separate computer to install the Pi’s operating system on an SD card that you then use to boot the Pi. Fortunately, people have done this already for several operating systems, and they’ve kindly made available the content of such SD cards for free on the Internet. In this section, you’ll learn how to transfer an SD card image to an SD card.

You’ll need a PC with a card reader (which is quite a misnomer, because you can use it for writing, too) to modify the SD card. Some PCs have built-in readers, but you can also get USB readers for a few dollars. It doesn’t matter which operating system you use, and we’ll look at how to create the SD card on all major platforms. If you have access to a Windows box, I strongly suggest you use it, because it’s easier and more convenient than Mac OS X or Linux for this particular purpose. Preparing an SD card on Mac OS X or Linux isn’t rocket science, but you have to invoke a fairly dangerous command, and you can easily delete some important files. Also, on Windows you’ll get more feedback while copying the card image.

No matter what operating system you plan to use for the installation process, you have to download the Debian image from the official download site.[37] You can download it using HTTP or via torrent. After the download has finished, you should have a file named 2014-01-07-wheezy-raspbian.zip on your local hard drive. (The filename might vary if a new version has been released.)

The procedures described in the following sections will be the same for images of all operating systems compatible with the Pi. You have to replace only the name of the image file.

Prepare an SD Card on Windows

Preparing the SD card on a Windows box is the most convenient alternative, because of Win32 Disk Imager.[38] This small application is free, has a nice user interface, and has a single purpose: writing images to SD cards. You don’t even have to install it; you can just download the zip file from the project’s website and unzip it to a directory of your choice. Double-click Win32DiskImager.exe, and you’re ready to go.

Before you write the SD card image to an SD card, you can check whether the image is valid. So, you have to calculate the zip file’s SHA-1 checksum. To do this, install the fciv command; Microsoft’s support site has a lot of information about it.[39] After you’ve installed fciv, you can use it as follows:

!

C:\>fciv 2014-01-07-wheezy-raspbian.zip -sha1

//

// File Checksum Integrity Verifier version 2.05.

//

9d0afbf932ec22e3c29d793693f58b0406bcab86 2014-01-07-wheezy-raspbian.zip

If the long hexadecimal number is the same as on the download page, the zip file has not been compromised, and you can safely proceed. Otherwise, download the image from another location.

After the application has started, select the Debian image and your card reader’s drive letter. Make sure you don’t choose the wrong drive! If you do, you risk losing important data. Then click the Write button, and you should see something like the following image. Writing the image will take a few minutes, but then you’ll have an SD card you can use to boot the Pi.

image


Figure 9. Win32 Disk Imager in action

Prepare an SD Card on Linux

Preparing an SD card for the Pi on a modern Linux system isn’t too difficult, but you have to be very careful when performing the following steps, because you can easily destroy important data! Do not insert the SD card into your card reader right now. You’ll do it later in the process to determine your reader’s device name.

Download the zip file containing the Debian image from the official download site, open a terminal, and change to the directory containing the zip file you’ve just downloaded. Although it’s not necessary, it doesn’t hurt to check the integrity of the file you’ve downloaded.

!

maik> sha1sum 2014-01-07-wheezy-raspbian.zip

9d0afbf932ec22e3c29d793693f58b0406bcab86 2014-01-07-wheezy-raspbian.zip

If the long hexadecimal number is the same as on the download page, the zip file has not been compromised, and you can safely proceed. Otherwise, download the image from another location.

The following command unzips the image file to the current directory:

!

maik> unzip 2014-01-07-wheezy-raspbian.zip

Archive: 2014-01-07-wheezy-raspbian.zip

inflating: 2014-01-07-wheezy-raspbian.img

Next you have to determine your card reader’s location. Run the following command to get a list of all storage devices currently connected to your computer:

!

maik> df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda1 63G 15G 46G 24% /

udev 494M 4.0K 494M 1% /dev

tmpfs 201M 740K 200M 1% /run

none 5.0M 0 5.0M 0% /run/lock

none 501M 124K 501M 1% /run/shm

Insert the SD card into your reader and run the command again.

!

maik> df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda1 63G 15G 46G 24% /

udev 494M 4.0K 494M 1% /dev

tmpfs 201M 772K 200M 1% /run

none 5.0M 0 5.0M 0% /run/lock

none 501M 124K 501M 1% /run/shm

/dev/sdc2 1.6G 1.2G 298M 81% /media/18c27e44-ad29-4264-9506-c93bb7083f47

/dev/sdc1 75M 29M 47M 39% /media/95F5-0D7A

As you can see, on my system the SD card is named sdc, and it has two partitions named sdc1 and sdc2. Of course, this will vary on your system; that is, you might have more or fewer partitions, and your SD card might be named sdd, for example. Before you proceed, you need to unmount all partitions, so in this case you’ll have to invoke the following commands:

!

maik> umount /dev/sdc1

maik> umount /dev/sdc2

As a final step, copy the image to the SD card. You have to run the following command with root privileges and make sure you’re using the right device name for the of option.

!

maik> sudo dd bs=1M if=2014-01-07-wheezy-raspbian.img of=/dev/sdc

[sudo] password for maik:

2825+0 records in

2825+0 records out

2962227200 bytes (2.9 GB) copied, 460.427 s, 12.1 MB/s

Copying the image will take a few minutes, but if everything went fine, you’ll have a bootable SD card that will bring Debian to your Pi!

Prepare an SD Card on Mac OS X

Preparing an SD card containing Raspbian on a Mac is very similar to preparing one on Linux, but there are a few important differences. You have to run only a few commands, but you have to be focused.

Do not insert an SD card into your card reader right now. You’ll do it later to determine your reader’s device name. Download the latest zip file containing the Raspbian image from the official download page. Open a terminal and change to the folder you’ve saved the zip file to. Then generate the file’s fingerprint using the following command (this step is optional if you trust your download source or if you got the zip file from another trusted source):

!

maik> shasum 2014-01-07-wheezy-raspbian.zip

9d0afbf932ec22e3c29d793693f58b0406bcab86 2014-01-07-wheezy-raspbian.zip

If the hexadecimal number printed to the terminal isn’t the same as the number on the download page, the zip file might have been compromised, and you should download it from another location. Otherwise, you can safely proceed. Unzip the file to the current directory.

!

maik> unzip 2014-01-07-wheezy-raspbian.zip

Archive: 2014-01-07-wheezy-raspbian.zip

inflating: 2014-01-07-wheezy-raspbian.img

Now you need to identify your card reader’s name. Run the following command to see all disk drives currently connected to your Mac:

!

maik> diskutil list

/dev/disk0

#: TYPE NAME SIZE IDENTIFIER

0: GUID_partition_scheme *256.1 GB disk0

1: EFI 209.7 MB disk0s1

2: Apple_HFS Macintosh SSD 255.2 GB disk0s2

3: Apple_Boot Recovery HD 650.0 MB disk0s3

/dev/disk1

#: TYPE NAME SIZE IDENTIFIER

0: GUID_partition_scheme *500.1 GB disk1

1: EFI 209.7 MB disk1s1

2: Apple_HFS Macintosh HD 499.2 GB disk1s2

3: Apple_Boot Recovery HD 650.0 MB disk1s3

/dev/disk2

#: TYPE NAME SIZE IDENTIFIER

0: FDisk_partition_scheme *500.1 GB disk2

1: Apple_HFS macback 500.1 GB disk2s1

/dev/disk4

#: TYPE NAME SIZE IDENTIFIER

0: GUID_partition_scheme *1.5 TB disk4

1: EFI 209.7 MB disk4s1

2: Microsoft Basic Data MEDIA 1.5 TB disk4s2

Your system’s output will vary, but you need it only to identify your SD card reader. Insert the card into your card reader now, and after a few seconds, run the command again.

!

maik> diskutil list

/dev/disk0

#: TYPE NAME SIZE IDENTIFIER

0: GUID_partition_scheme *256.1 GB disk0

1: EFI 209.7 MB disk0s1

2: Apple_HFS Macintosh SSD 255.2 GB disk0s2

3: Apple_Boot Recovery HD 650.0 MB disk0s3

/dev/disk1

#: TYPE NAME SIZE IDENTIFIER

0: GUID_partition_scheme *500.1 GB disk1

1: EFI 209.7 MB disk1s1

2: Apple_HFS Macintosh HD 499.2 GB disk1s2

3: Apple_Boot Recovery HD 650.0 MB disk1s3

/dev/disk2

#: TYPE NAME SIZE IDENTIFIER

0: FDisk_partition_scheme *500.1 GB disk2

1: Apple_HFS macback 500.1 GB disk2s1

/dev/disk4

#: TYPE NAME SIZE IDENTIFIER

0: GUID_partition_scheme *1.5 TB disk4

1: EFI 209.7 MB disk4s1

2: Microsoft Basic Data MEDIA 1.5 TB disk4s2

/dev/disk5

#: TYPE NAME SIZE IDENTIFIER

0: FDisk_partition_scheme *15.9 GB disk5

1: Windows_FAT_16 RECOVERY 1.3 GB disk5s1

2: Linux 33.6 MB disk5s3

3: Windows_FAT_32 BOOT 62.9 MB disk5s5

4: Linux 14.5 GB disk5s6

As you can see, on my Mac the SD card can be found at /dev/disk5. On your Mac, it might be at a different location. So, in the following command, replace /dev/disk5 with the location of your SD card:

!

maik> diskutil unmountDisk /dev/disk5

Unmount of all volumes on disk5 was successful

After you’ve unmounted the SD card, you can finally copy the Raspbian image to it. WARNING: the following command will copy the image to the device you specify with the of option. If you specify the wrong device—for example, your Mac’s main hard drive or an external USB drive containing your most precious photos—all data will be lost. If you’re absolutely sure that you’ve chosen the right target, run the following command:

!

maik> sudo dd bs=1m if=2014-01-07-wheezy-raspbian.img of=/dev/disk5

Password:

2825+0 records in

2825+0 records out

2962227200 bytes transferred in 496.170855 secs (5970176 bytes/sec)

The command will run silently, and it won’t emit any progress messages. As you can see in the previous output, it took several minutes to copy the image to the card, so be patient.

When you create the SD card, watch out for one thing: some people have experienced read/write errors or unrecognized cards with SDHC cards on recent MacBooks and MacBook Pros with internal card readers. Using an external card reader should solve these problems.

Finally, you can eject the card.

!

maik> diskutil eject /dev/disk5

Disk /dev/disk5 ejected

That’s it! You’ve created a bootable SD card containing Raspbian on your Mac.

Next Steps

Regardless of what operating system you’ve used, you should now have a bootable SD card containing Debian Linux. You also know how to transfer the image of every operating system that is compatible with the Pi to a bootable SD card. In the next chapter, you’ll learn how to start Debian on the Pi for the first time.

Footnotes

!

[26]

http://www.raspberrypi.org/downloads

[27]

http://jeffhoogland.blogspot.co.uk/2012/06/bodhi-linux-arm-alpha-release-for.html

[28]

http://news.opensuse.org/2013/09/09/opensuse-arm-gets-new-raspberry-pi-images/

[29]

http://www.cnx-software.com/2012/04/19/building-chromium-os-for-raspberry-pi-armv6/

[30]

http://www.archlinux.org/

[31]

http://en.wikipedia.org/wiki/RISC_OS

[32]

http://googlecreativelab.github.io/coder/

[33]

http://www.raspberrypi.org/downloads

[34]

https://www.sdcard.org/downloads/formatter_4/eula_windows/

[35]

https://www.sdcard.org/downloads/formatter_4/eula_mac/

[36]

http://gparted.sourceforge.net/

[37]

http://www.raspberrypi.org/downloads

[38]

http://sourceforge.net/projects/win32diskimager/

[39]

http://support.microsoft.com/kb/841290