Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Banana Pi Cookbook

You're reading from   Banana Pi Cookbook Over 25 recipes to build projects and applications for multiple platforms with Banana Pi

Arrow left icon
Product type Paperback
Published in Jun 2015
Publisher
ISBN-13 9781783552443
Length 200 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Ryad El-Dajani Ryad El-Dajani
Author Profile Icon Ryad El-Dajani
Ryad El-Dajani
RYAD E DAJANI RYAD E DAJANI
Author Profile Icon RYAD E DAJANI
RYAD E DAJANI
Arrow right icon
View More author details
Toc

Setting up the SD card on Linux

This recipe will explain how to set up the SD card using a Linux-based operating system. On Linux computers, you usually will not need any special software to uncompress archives or write the image to an SD card. To do these tasks, you usually need the command-line tools tar and dd that are preinstalled on almost any Linux distribution by default.

Getting ready

To prepare your image and the SD card on Linux, you will only need the following software ingredients:

  • A downloaded image from the Downloading an operating system for the Banana Pi recipe
  • The dd program
  • The tar program including gzip support
  • Optionally, the fdisk program

How to do it…

The following steps are required to unpack the image archive and write the image to the SD card:

Note

Use the following dd command very carefully. The dd command will overwrite anything on the output (the of parameter). In fact, you can damage your computer, if you choose the wrong output. So, make sure that the value of the parameter of is definitely the SD card.

  1. Unpack the downloaded .tar.gz or .tgz archive using the following command:
    $ tar -xzvf Raspbian_For_BananaPi_v1412.tgz
    
  2. If you have downloaded a .zip file, you use the following command:
    $ unzip Raspbian_For_BananaPi_v1412.zip
    
  3. Determine how your SD card is recognized by the system. You can check the correct path of your SD card by using the following command:
    $ sudo fdisk -l
    

    Tip

    To determine the correct device, you can compare the results before and after you plug in the SD card.

    The commands used in the next steps assume that your SD card is recognized as /dev/mmcblk0.

  4. Make a backup of the contents on your SD card.
  5. Unmount all partitions of the SD card, if any partition is mounted:
    $ sudo umount /dev/mmcblk0*
    
  6. Write the image to the SD card:
    $ sudo dd if=Raspbian_For_BananaPi_v1412.img of=/dev/mmcblk0 bs=1M
    

    The writing process takes a few minutes.

  7. On some systems, the SD card is automatically mounted after the writing process. Unmount the partitions of the SD card again:
    $ sudo umount /dev/mmcblk0*
    

When the writing process is finished, you can eject your SD card and put it into the SD slot of your Banana Pi.

How it works…

On Linux, you also need to unpack an image file and write the image to the SD card. Luckily, these tasks are much quicker and more easily done on the command line and you usually do not need to install additional software.

In fact, to unpack the image, you need the tar command and to write an image to the SD card you need the dd (disk dump) command. The tool tar is a program to pack or unpack archive files. The tool dd is a utility to convert and copy files from a source (the input file—the if parameter) to a destination (the output file—the of parameter). In contrast to a normal file copy, the actual order of the bytes is preserved.

The dd command is executed with root privileges (by using the prefix command sudo) to use the image file as input, the SD card as output, and to read/write with a block size (the bs parameter) of one megabyte. That block size value is a safe choice when writing images to or reading from SD cards. You can also try a block size value of 4M, which results in a faster but possibly unsuccessful writing process.

You do not need to format the SD card before issuing the dd command as dd also writes the whole partition information directly to the SD card.

Note

The output parameter has to be the whole SD card (/dev/mmcblk0 in our previous example). Make sure not to accidentally write to a partition of the SD card. This means do not use /dev/mmcblk0p1 or the like).

Moreover, depending on your computer, the SD card may be recognized as /dev/sdX and not /dev/mmcblk0. Use the fdisk -l command to determine the correct device file as mentioned in this recipe.

The dd command will take some time. If you want to check the progress, you can issue the following command in another shell:

$ sudo pkill -USR1 -n -x dd

This will output the current status on the running dd job.

See also

  • Type in the man dd command into a shell to show the manual page of dd:
    $ man dd
    
  • Type in the man tar command into a shell to show the manual page of tar:
    $ man tar
    
  • Type in the man fdisk command into a shell to show the manual page of fdisk:
    $ man fdisk
    
You have been reading a chapter from
Banana Pi Cookbook
Published in: Jun 2015
Publisher:
ISBN-13: 9781783552443
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image