Installing the Operating System - Getting Started with the BeagleBone - BeagleBone For Dummies (2015)

BeagleBone For Dummies (2015)

Part I

Getting Started with the BeagleBone

Chapter 2

Installing the Operating System

In This Chapter

arrow Getting to know Linux

arrow Obtaining your Linux distribution

arrow Preparing your microSD card

arrow Preparing the onboard eMMC

The BeagleBone is a tiny computer with all the features of today’s computers, which ultimately means that it also needs an operating system (OS). Because BeagleBone is an open-hardware project, it runs on Linux — an open-source OS. Using free software makes using the board less expensive and creates the perfect tool to use to learn programming.

As with any other computer, you can use a BeagleBone to store files, surf the web, install applications, and do pretty much all the everyday stuff that you’re used to doing. The real advantage of your BeagleBone over a typical computer, however, is that the BeagleBone has input and output pins that bridge the gap between the realms of computing and electronics. With a BeagleBone, you can create and control interesting electronic projects with a very high degree of complexity. After all, the foundation of your project is a computer. Also, because the BeagleBone is a low-cost device, it doesn’t cost a fortune to replace it if you somehow break it!

This chapter explains which distribution of Linux to use, as well as where you can download it and how to install it. In Chapter 4 and Chapter 12, you dive deeper and see how to use the Linux shell and its desktop environment.

tip If your BeagleBone has just arrived, and you haven’t done anything with it yet, your board already has a fresh OS installed. To prevent unexpected issues, however, you should be running the latest version of the same OS shown in this book, so we recommend that you follow the instructions in this chapter to ensure that everything throughout the book works for you.

tip The BeagleBoard Black comes from the factory with an empty microSD card slot. We highly recommend that you buy a microSD card with at least 4GB of storage to install the new Linux distribution as described in this chapter. If you have a 2GB card handy, however, you can use it to get started. Keep in mind, though, that there’ll be very little space left on the card after you install Linux. You’ll be able to use it to work through the procedures in the following chapters, but eventually, you’ll need more memory.

Introducing Linux

Linux was created as a free OS for personal computers. Because of its many advantages, it quickly made its way into a plethora of applications. Nowadays, Linux is used on a wide range of hardware platforms, such as mobile phones, tablets, embedded systems, servers, and routers.

Linux is a good example of the strength of an open-source community. No company developed this OS. Instead, thousands of people all around the world contributed their knowledge to create and improve this software — at no cost at all.

Linux is hands-down the most popular software around for programmers and developers, mainly because anyone can have full access to the code, modify it, study it, and distribute it. Read Chapter 4 for a more detailed description of Linux, including its advantages and proper use.

remember The Linux kernel is the core of your computer’s software. It’s the lowest level of software that interfaces with the hardware; it’s the code that controls everything, translating whatever you do on your computer into a language that the hardware can understand.

Selecting a Distribution

A distribution is a complete Linux package that contains the Linux kernel and a couple of other pieces of open-source software that provide a wide variety of functionalities.

Knowing the factory defaults on your BeagleBone

technicalstuff We recommend that you follow the instructions in this chapter to install the latest Debian distribution, which is used throughout this book. Every new BeagleBone is configured to work out of the box by default, however. The original configuration depends on your board:

· The Original BeagleBone includes a microSD card that has the Ångström distribution installed.

· BeagleBone Black ships from the factory with Linux installed on the board’s eMMC memory and with an empty microSD card slot, which we recommend that you use to install Debian.

The Linux distribution depends on the board version:

· BeagleBone Black Rev A and Rev B have Ångström installed in the built-in memory.

· BeagleBone Black Rev C comes with Debian preinstalled.

We opted to use the Debian distribution for this book because Debian currently is the most-supported distribution in this embedded platform. The next sections of this chapter walk you through the procedure for installing Debian.

technicalstuff If you want to see a list of all OSes that are fully compatible with BeagleBone, visit http://elinux.org/Beagleboard:BeagleBoneBlack#Software_Resources.

warning Even though there are plenty of similarities between one Linux distribution and the next, there are also a few differences. The commands presented through this book assume that you’re using Debian, which means that some of the commands that we present won’t work in other distributions.

Downloading your Linux distribution

You need to use a computer to download the distribution from the Internet and flash your microSD card. (Flashing is the process used when you completely rewrite a data storage device rather than simply saving files on it.) You can use a Windows, Mac OS X, or Linux computer; we illustrate how to prepare your microSD card on all three systems. You can find the official distributions available for download at http://beagleboard.org/latest-images.

The distribution you need to work with on this book depends on how you intend to run Linux and is subject to change with future releases. Regardless, the process of downloading the newest image should be very similar, as should the respective filenames. You have two alternatives:

· If you’re booting Linux from a microSD card on a BeagleBone Black or an Original BeagleBone, download Debian using the file labeled as Debian (BeagleBone, BeagleBone Black - 2GB SD) 2014-05-14.

· If you’re booting Linux from your BeagleBone Black’s eMMC memory, download Debian eMMC flasher using the file labeled as Debian (BeagleBone, BeagleBone Black - 2GB eMMC) 2014-09-04.

If you have a BeagleBone Black and, thus, the chance to flash the eMMC memory, we recommend that you use the second option, which not only increases system performance, but is also much more practical. You won’t need to have the microSD card with you at all times.

tip If you don’t want to reflash the eMMC memory on the BeagleBone Black — in other words, if you want to keep the factory default OS — you can choose the standard Debian image and boot the OS directly from the microSD card.

You can download the distribution in two ways. The first way is much simpler but may take some more time than the second way. Here are your options:

· Web browser: You can download the distribution directly from your web browser by clicking the distribution name. When you click the name of the distribution, a new web page opens. After about 3 seconds, your file should start downloading.

· BitTorrent: BitTorrent enables you to download larger files faster. It gathers all the small pieces of the file you want and starts downloading your file from people who already have them, maximizing the transfer speed. To use this method, you must have a BitTorrent application on your computer. When you open the BitTorrent link, a torrent file that’s compatible with the BitTorrent application is downloaded to your computer.

tip You can find a free BitTorrent application that works in all three OSes at www.utorrent.com.

Decompressing your Linux distribution

The Linux distribution you download is compressed in an .xz file. You have to decompress the .xz file so that you can access the .img file contained inside. The procedure you use to decompress the file depends on your computer’s OS.

Windows

If you’re using a Windows PC to decompress your Linux distribution, you need to install the application 7-Zip. Follow these steps:

1. Go to www.7-zip.org/download.html.

2. Download the .exe file.

3. Run the .exe file to install 7-Zip.

With 7-Zip installed, you’re ready to decompress your .xz file. Follow these steps:

1. Open the 7-Zip application.

2. Click the Extract icon.

The Extract dialog box opens (see Figure 2-1).

9781118992913-fg0201

Figure 2-1: Decompressing your Linux distribution by using 7-Zip for Windows 8.1.

3. Navigate to the folder where you saved your Linux distribution.

4. Save the file in your preferred folder, and click OK.

Your .img file is extracted.

Mac OS X

If you’re using a Mac to decompress your Linux distribution, follow these steps:

1. Go to the App Store.

2. Search for and install the free application The Unarchiver.

3. Navigate to your Downloads folder.

4. Double-click your .xz file.

The decompressing process starts immediately.

Linux

If you’re using Linux, you don’t need to install a new decompression application because Linux already has built-in software that can decompress .xz files. You see how to extract the .img file in Linux later in section “Flashing a microSD Card in Linux.”

Flashing and Inserting Your microSD Card

Chapter 1 suggests that you buy a microSD card for your BeagleBone. If you followed that recommendation, you should have a 4GB microSD card of at least Class 4 with an adapter. You have two options for writing the .imgfile to a microSD card:

· If your computer has an SD card slot, insert your microSD card into a microSD card adapter (see Figure 2-2) and connect it to your computer.

· If your computer doesn’t have an SD card slot, you need an external SD card writer. Insert your microSD card into a microSD card adapter (see Figure 2-2); then insert your SD card into your external SD card writer and connect it to your computer.

9781118992913-fg0202

Figure 2-2: A microSD card, microSD card adapter, and external SD card writer.

Flashing an image file to your microSD card isn’t like copying a photograph or document to your common flash drive. You need to use a special program that converts the Linux distribution to a couple of files that your BeagleBone is able to read. The following sections explain how to properly use programs to flash data storage devices.

warning You have to be really careful while flashing your microSD card. Before pressing Enter or Return, you need to be completely sure you are selecting the right device name. Selecting the wrong device name results in irreversible data loss, such as erasing your computer’s hard disk.

warning Flashing your microSD card completely erases it. Make sure that you’ve copies of any files on the microSD card that you may need later.

Flashing a microSD card in Windows

Flashing a microSD card in Windows requires an application called Win32 Disk Imager (see Figure 2-3), which is available for free download.

9781118992913-fg0203

Figure 2-3: Flashing a microSD card on Windows by using Win32 Disk Imager.

Follow these steps to install it:

1. Go to the Win32 Disk Imager download page at http://sourceforge.net/projects/win32diskimager.

2. Click the Download button to retrieve the installer.

3. Run the Win32 Image Writer application installer.

With Win32 Disk Imager installed, you’re ready to write the .img file to your microSD card. Follow these steps:

1. Connect your microSD card to your computer.

2. Open Win32 Disk Imager.

3. Select your Linux-distribution .img file.

4. Select your microSD card as the device.

warning This process erases and overwrites the selected device. Be certain that you’ve selected the microSD card, and be certain that you have copies of any files that you need from the card. We can’t stress this enough: Be certain that the microSD card is the device you chose!

5. Click Write to start writing the image to the microSD card.

This process takes between 10 and 20 minutes, depending on your microSD card class number and your SD card writer’s transfer speed.

Flashing a microSD card in Mac OS X

On a Mac, you can use the Terminal application to copy the image to your microSD card, as shown in Figure 2-4.

9781118992913-fg0204

Figure 2-4: Flashing a microSD card on a Mac by using Terminal.

Follow these steps:

1. Navigate to /Applications/Utilities.

2. Double-click Terminal to open a new Terminal window.

3. Connect your microSD card to your computer.

4. Type df -h to get a listing of the devices connected to your computer.

5. Find out which device is your microSD card.

It will be something similar to /dev/sdisk2s1.

warning Be very careful that you choose the right /dev device. Using an incorrect device name results in permanent data loss from the device you choose. You can even overwrite the disk that contains your computer’s OS. We can’t stress this enough: Be certain that the microSD card is the device you choose!

6. Type sudo diskutil umount /dev/disk2s1 to unmount your micro SD card.

tip The command is umount even though you say “unmount.”

warning For the next command, you have to ignore the device number. For this example, /dev/disk2s1 becomes /dev/disk2.

7. Run sudo dd if=~/<downloads folder>/<filename>.img of=/dev/disk2 bs=1m.

This process takes between 10 and 20 minutes, depending on your microSD card and your SD card writer’s transfer speed.

Flashing a microSD card in Linux

With Linux, you don’t have to install extra applications; the OS already has everything you need to decompress the .xz file and flash your microSD card with the latest OS (see Figure 2-5).

9781118992913-fg0205

Figure 2-5: Flashing a microSD card on Linux by using the terminal in Ubuntu.

To flash a microSD card in Linux, follow these steps:

1. Press Ctrl+Alt+T to open the terminal window.

2. Connect your microSD card to your computer.

3. Type cd to navigate to your Downloads folder (cd /Downloads).

4. Type xz -dk <filename>.img.xz to decompress your .xz file.

5. Type df -h to get a list of the devices connected to your computer.

6. Find out which device is your microSD card.

It will be something similar to /dev/sdb1.

warning Be very careful that you choose the right /dev device. Using an incorrect device name results in permanent data loss from the device you choose. You can even overwrite the disk that contains your OS. We can’t stress this enough: Be certain that the microSD card is the device you choose!

7. Type sudo umount /dev/sdb1 to unmount your micro SD card.

technicalstuff The command is umount even though we say “unmount.”

warning For the next command, you have to ignore the device number. For this example, /dev/sdb1 becomes /dev/sdb.

8. Run sudo dd if=~/<downloads folder>/<filename>.img of=/dev/sdb bs=1m.

This process takes between 10 and 20 minutes, depending on your microSD card and your SD card writer’s transfer speed.

Inserting your microSD card

When your microSD card is all set, you need to insert it into your BeagleBone. The card slot is on the back of your board, right next to the MicroHDMI port, as shown in Figure 2-6. Just press the card gently into the slot until you feel a click. Done! Your BeagleBone now happily boots with the freshly installed Debian distribution.

9781118992913-fg0206

Figure 2-6: Inserting a microSD card into a BeagleBone Black.

remember If you’re going to boot Linux directly from a microSD card with your BeagleBone Black, you need to hold the user boot button down (see Figure 2-7) for about 5 to 7 seconds every time you power on your BeagleBone Black. Otherwise, the BeagleBone Black boots from the preinstalled OS on the onboard eMMC memory.

9781118992913-fg0207

Figure 2-7: The user boot button on the BeagleBone Black.

Flashing the Onboard eMMC

If you’re using a BeagleBone Black and want to flash your onboard eMMC memory, you need to do one more thing.

tip If you’re going to boot Linux directly from a microSD card or you are using an Original BeagleBone, you can skip this section and go straight to Chapter 3.

technicalstuff The amount of built-in storage of your BeagleBone Black depends on the board revision:

· BeagleBone Black Rev A and Rev B have 2GB.

· BeagleBone Black Rev C comes with 4GB.

tip When we talk about using built-in storage, we mean something slightly different from running your OS on your microSD card. You don’t need to worry about the fact that BeagleBone Black Rev A and Rev B have only 2GB of onboard eMMC memory.

To flash your BeagleBone Black’s eMMC memory, follow these steps:

1. While your BeagleBone Black is powered off, insert your microSD card into the microSD slot (refer to Figure 2-6).

2. Hold down the user boot button of the BeagleBone (refer to Figure 2-7).

3. While holding the user boot button, press the power button on your board. When the board is powered up, you should continue to hold the user boot button for 5 to 7 seconds and then release it.

The USR LEDs blink during this process.

Flashing can take about 30 to 40 minutes. When this process is finished, all four USR LEDs will be off.

4. Unplug your board.

5. Remove the microSD card.

warning If you don’t remove the microSD card the next time you boot your BeagleBone Black, or if you remove the microSD card while the flashing process is occurring, your eMMC memory can get corrupted and your BeagleBone Black won’t boot. If the card does become corrupt, you have to repeat this section again to flash your BeagleBone’s eMMC memory properly.

You’re done! The next time you plug in your board, it boots with the new OS.