Chapter 4. Installing and Configuring an Operating System

The operating system (also called the OS, pronounced oh-ess) is the most important software on your computer because it represents the interface between you, running software programs, and the machine’s underlying hardware.

To put this discussion in a more meaningful context, let’s say that you want to send an email message from your computer or mobile device. You compose and send your message by using a web browser or a dedicated email application. The computer’s operating system translates your keystrokes and mouse movements into instructions that are understood by your application.

When you click Send, the OS then conducts the message through a number of subsystems, including translating your message data into an intermediate format that your computer’s network interface card (NIC) device driver software can process.

The NIC driver and the networking protocol stack further segments the email message and ultimately transmits binary digital data in the form of 0s and 1s across the network communications media through the NIC hardware.

Figure 4.1 shows the conceptual relationship between the user, the application, the operating system, the device driver, and the device itself.

Image

FIGURE 4.1 The operating system orchestrates data flow between the user, applications, device drivers, and the underlying computer hardware.

Let me briefly explain the layers shown in Figure 4.1:

Image OS: The operating system orchestrates the communication among all the other layers.

Image User: The computer operator provides input to and received output from the computer.

Image Application: The program or application enables the user, operating system, and hardware to get work done.

Image Drivers: Each hardware device needs platform-specific software that enables the OS to interact with it. In Linux, the OS kernel often integrates device drivers into its code.

Image Hardware: Hardware can be either permanently part of the computer (like a motherboard) or an attached peripheral (like a mouse).

Like any other computer, the Raspberry Pi includes an operating system as well. Therefore, the OS skills that you’ll pick up in this chapter are abilities that you will apply every single day in your work with the Pi. In later chapters we’ll apply your Linux operating system skills as we undertake various Pi-related projects.

Common Operating Systems

Truly, operating systems are not at all voodoo magic, although their underlying structure can sometimes get complicated. The bottom line is that any end user of a computer system interacts with an operating system of one type or another.

For instance, a Mac user deals with the Apple OS X (pronounced oh ess TEN, not oh ess EX) operating system. A PC user generally uses a version of the Microsoft Windows operating system—for example, Windows 8 or Windows 7. Mobile device users might run one of the following operating systems, depending on the make and model of their mobile hardware:

Image Apple iOS

Image BlackBerry

Image Google Android

Image Windows Phone

Image Windows RT

You might know already that the Raspberry Pi runs none of these. What’s going on here? Well, as it happens, the RasPi uses a particular distribution of Linux.

Understanding Linux

Linux (LIH-nix) is an open source operating system originally developed by the Finnish computer scientist Linus Torvalds (LEE-nus TUR-valds) in 1991. Linux was built from the ground up as a free operating system that any interested party could tinker with, improve upon, and re-release under the GPL license (discussed back in Chapter 1, “What Is the Raspberry Pi?”).

At some point you might have heard a nightmare story or two about how difficult it is to use. There was a time when the only people who would touch Linux were computer science nerds or grizzled government employees. Believe me, friends: Linux has gotten much more user-friendly over the past 10 years or so.

Thanks to Linux vendors like Red Hat and Canonical, Linux has become much more mainstream, often to the chagrin of the original Linux fanatics who prefer a less corporate, structured approach to OS development and distribution. In point of fact, Canonical’s Ubuntu Linux, in its 12.10 version, bears a striking resemblance to Apple OS X (see Figure 4.2).

Image

FIGURE 4.2 Apple OS X above, and Ubuntu Linux below.

The OS X and Ubuntu Linux user interfaces are quite similar indeed. As you will learn pretty soon if you haven’t already, I’m a big believer in using (brief) unordered lists to teach concepts. Allow me to summarize what I see as the chief advantages of Linux:

Image Generally more secure than proprietary OS software such as Windows and OS X because the community quickly squashes bugs and vulnerabilities.

Image Gives the operator control of every aspect of OS operation, right down to the bare kernel level.

Image The OS and most available software are free.

Image You can do the vast majority of stuff in Linux that you are accustomed to doing in Windows or OS X.

In addition to these factors, it’s also true that people who write malicious software tend to target the most popular operating systems simply because there are more available targets. Consequently, the relatively “niche” status of Linux in the consumer/enthusiast environment gives the platform a security advantage over mainstream OSs.


Note: But What About Office?

Long-time Linux users typically gravitate toward OpenOffice (http://is.gd/AxqDKr) or LibreOffice (http://is.gd/ORAFcy) as open source (and therefore free) alternatives to the proprietary Microsoft Office productivity suite.


As Bret Michaels sang in the 1980s, “Every rose has its thorn....” Here are what I see as the essential disadvantages of Linux:

Image To access the raw power of Linux, you must learn how to use the command line, which involves a number of highly cryptic command-line tools.

Image The graphical user interface in Linux is generally not as polished or intuitive as, say, Windows 7 or OS X.

Image Configuring driver support for new hardware is sometimes problematic to Linux beginners due to the common requirement of manual driver installation and configuration.

Image You can run Windows or OS X apps under Linux; however, doing so is not considered to be a beginner-level task. In general, the variety of software that is available to Linux is far less than what is available to, say, Windows or OS X.

Despite the challenges that running Linux has for us, I submit that Linux is truly the ideal operating system platform for the Raspberry Pi. Remember that the Pi is intended as a learning environment—what better way to discover the relationship between an OS and hardware than in an open-source situation where the underlying source code and hardware schematics are freely available to you?

Also, as we’ll see momentarily, you have quite a bit of flexibility in terms of which Linux distribution you might prefer to run on our Pi.

Linux and Raspberry Pi

Remember when I said earlier that Linus Torvalds gave us Linux as a platform for community development? We call those Linux variations, those that come from the development community, remixed or forked distributions.

The Raspberry Pi Foundation put together an official Linux distribution that is optimized for Raspberry Pi; this distribution is called Raspbian (RASS-pian). The name Raspbian bears a bit of an explanation. Raspbian is a portmanteau, which is a mash up of two or more words derived from two separate technologies:

Image Raspberry Pi: The $25/$35 computer upon which this book is based

Image Debian: The Linux distribution used as a base for Raspbian (http://is.gd/lgF8Ft)

Personally, I’m overjoyed that the Foundation used Debian as a base Linux for the Pi. Number one, Debian includes one of the most powerful and flexible package managers in the industry (more on that in the next couple chapters). The Raspbian user interface is shown in Figure 4.3.

Image

FIGURE 4.3 The Raspbian Linux distribution includes the LXDE graphical user interface (GUI).

Number two, Debian is one of the more user-friendly Linux distros in existence. As a matter of fact, Ubuntu Linux is also based on Debian.

But can we go ahead and install the “real” Debian or Ubuntu on the Pi? Unfortunately, no—at least not without some major kernel hacking. Remember that the Pi board uses an ARM CPU. Most desktop computers today, at least in the retail space, use the Intel processor. As of this writing in spring 2013, neither Debian nor Ubuntu Linux supports the ARM processing architecture.

The Kernel and Firmware

If the operating system constitutes the software “body” of a computer system, then the kernel represents the brain. Specifically, the kernel is the OS subcomponent that functions most intimately with installed hardware devices.

What’s cool about Linux is that you can customize and recompile the kernel to suit different situations. For instance, the Raspberry Pi Foundation modified the Debian Linux kernel to accommodate the ARM processor and other components included on the Pi board.

The Linux kernel is called firmware because it is software that is semi-permanently written to the first partition of your Raspbian SD card. I say semi-permanently because the firmware data persists after you power down the computer. However, you can update the firmware to a more recent version if need be.

We can contrast data that is stored on the SD card with data that is stored in random access memory, or RAM. RAM-based data persists only as long as the Pi is powered up; unless you save RAM contents to the SD card, that data is permanently lost if the Pi is turned off or rebooted.

Raspberry Pi uses its own custom-built firmware that “blends” the proprietary Broadcom BCM2835 system on a chip (SoC) with the Raspbian operating system. In point of fact, the BCM2835 SoC actually has two sets of firmware flashed onto the SD card. The first is responsible for managing the hardware resources on the Pi, and the second is charged with controlling the behavior of the Pi’s graphical processing unit (GPU).


Note: I’m Floating!

The original Raspbian code was not optimized in the kernel to process floating-point (decimal) numbers in hardware. This “soft float ABI (application binary interface)” situation, which involves emulating math co-processing in software, bothered experienced Linux users who wanted to use the Pi to perform more complex math. Fortunately, the current versions of Raspbian now contain a “hard float” ABI, which means that instructions for processing floating-point numbers are performed in hardware using the math co-processor chip. Needless to say, hard float is orders of magnitude faster than soft float.


Updating the Raspberry Pi kernel firmware is covered in the next chapter.

Raspberry Pi’s Other Operating Systems

Keeping in spirit with the “do it yourself” philosophy of Linux, you can run a number of specially crafted Linux distros on the Pi. Raspbian is considered to be the reference operating system because it was built from the ground up for learning software and hardware programming with the Pi board. However, alternatives exist that are optimized for other uses. Let’s take a brief look at a few of them:

Arch Linux ARM (http://is.gd/6EJlou): This distro is an ARM-specific branch of the Arch Linux OS that is aimed at experienced Linux users. Its structure is lightweight and is intended to provide the user with as much control as possible.

Fedora Remix (http://is.gd/Nj0Iys): This distro is an ARM port of the highly successful Fedora Linux OS. In particular, check out the Pidora distribution (http://is.gd/2TfKjx). Many Linux users swear by Fedora, so its ability to run on the Raspberry Pi pleases many enthusiasts.

Occidentalis (http://is.gd/t79m03): This distro, pronounced ocks-ih-den-TAIL-is, was developed by Adafruit and includes lots of OS “extras” to make hardware hacking easier. Adafruit is one of the best Raspberry Pi education sites out there; they sell extension hardware and provide detailed instructions on how to use it with your Pi.

OpenELEC (http://is.gd/KpaeqS): This distro, pronounced open ee-LECK, has a single aim—to run the Xbox Media Center (XBMC) as efficiently as possible. OpenELEC and XBMC are discussed in great detail in Chapter 12, “Raspberry Pi Media Center.”

RaspBMC (http://is.gd/KyBKzy): This distro is like OpenELEC inasmuch as it is intended only to run Media Center software on the Pi.

RISC OS (http://is.gd/6EJlou): This distro, pronounced risk oh ess, was developed by Acorn, who you’ll remember is the manufacturer of the BBC Micro microcomputer, the Raspberry Pi’s inspiration.

Of these alternative Linux distros for the Raspberry Pi, I personally like Occidentalis the best because the environment is optimized for use with the Adafruit Learning System (http://is.gd/efFtD7). Be sure to visit and bookmark the Adafruit website; they offer almost every conceivable Raspberry Pi hardware add-on. Figure 4.4 shows the Occidentalis user interface.

Image

FIGURE 4.4 Adafruit’s Occidentalis Linux distribution, which includes plenty of hardware hacking tools.

Please note that the Raspberry Pi-compatible operating systems suggested here represent only part of what’s available. Check out the RPi Distributions page at the Embedded Linux Wiki (http://is.gd/3yHQZ2) for a more complete rundown.

Installing Raspbian on Your Raspberry Pi

My first computer, the Tandy TRS-80 Model III, and the Commodore 64 had no persistent, onboard storage. That is to say, anything you wanted to save permanently, such as a BASIC program that took 12 hours to type in, had to be saved to some external media to survive a system shutdown or restart.

It was a great day in the early 1990s when Intel-based personal computers began shipping with fixed internal hard drives! Suddenly you could boot an operating system, load programs, and save data to your heart’s content, free of the worry of losing all of your work when you turned off the computer!

Believe it or not, the Raspberry Pi board also does not contain an internal disk drive to boot the OS and save user data. Instead, the Foundation included an SD card slot.

If you read Chapter 3, “A Tour of Raspberry Pi Peripheral Devices,” you have all the information you need to purchase your SD card. I formally suggest you stay with the Standard SD card form factor (see Figure 4.5), but you can make use of the Mini or Micro cards with the appropriate adapters.

Image

FIGURE 4.5 You can learn much about an SD card by studying its sticker label. Here we can see the brand, capacity, and speed rating in a single glance.

Building a Raspbian SD card is not as easy as copying a bunch of files from a folder on your PC or Mac to the SD card. Instead, you download a binary OS image file and flash that image onto your SD card in one pass.


Note: What Type of SD Card Should I Use?

I suggest you purchase a name-brand SD card of at least 4GB capacity. Moreover, I recommend that the SD card speed be rated at Class 4 or higher. You can visit the Embedded Linux website (http://is.gd/Ym6on0) to view a comprehensive compatibility index of Raspberry Pi-compatible SD cards.


You’ll need the following ingredients to create a Raspbian OS image SD card:

Image PC or Mac computer

Image SD card reader (some computers include these in the case)

Image SD image burning tool or command-line equivalent

Image Official Raspbian OS image (http://is.gd/6EJlou)

The following sections take you through the process of setting up an SD card with Raspbian.

An All-in-One Solution

Because the process of installing an operating system to the Raspberry Pi can be so tedious and scary for computing newcomers, some developers have taken it upon themselves to build tools to lessen this learning curve.

Take the New Out Of Box Software (NOOBS) project (http://is.gd/0n2yZv), for example. This is a tiny boot loader that makes installing an OS on your Raspberry Pi a breeze.

As you can see in Figure 4.11, the NOOBS user interface presents a simple menu from which a user can install any of the following Pi-tailored operating systems:

Image Arch Linux

Image OpenELEC

Image Pidora

Image RaspBMC

Image Raspbian

Image RiscOS

Image

FIGURE 4.11 The NOOBS utility makes it much easier to load an OS on your Raspberry Pi.

After you’ve used NOOBS to install an OS on your Pi, the boot loader remains resident on your SD card such that you can reinvoke it at any time by holding down the Shift key during bootup.

If nothing else, NOOBS provides a quick, convenient, and easy way to test out a number of different OSs on the Pi to help you find your “comfort zone.”

Testing Your New Raspbian Image

The best way to verify that your newly created Raspbian image works correctly is to insert it (carefully) into the SD slot on your Pi’s circuit board and plug the Raspberry Pi into your power supply. You’ll also want to plug in a keyboard, mouse, and monitor/TV, as discussed in Chapter 2, “Hardware Components Quick Start.”

If all goes well, you’ll see the Raspi-Config interface as shown in Figure 4.12.

Image

FIGURE 4.12 First-time Raspberry Pi setup is accomplished by using the Raspi-Config script.

If for some reason the Raspberry Pi doesn’t boot directly into Raspi-Config, then simply issue the command sudo raspi-config from the Terminal prompt.

You learn the details of Raspberry Pi first-time configuration next in Chapter 5, “Debian Linux Fundamentals—Terminal.”

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset