Skip to content

Install the Software

Jason Charney edited this page Mar 21, 2017 · 14 revisions

SD Card formatting and image mounting

Click here for the TLDR version of these instructions.

Click here for the Windows version of these instructions


Download the image

I recommend getting the Raspbian image. I've also designed these instructions to do this from a Linux machine. If anyone knows how to do it on windows, shoot me a line. The less software installed, the better, as the Hacktop project is minimalistic.

Watch what you buy!

SD Cards come not only in various sizes but various speeds too! That 32 GB SD card you picked up for cheap might not be a Class 10 or U-1! Keep an eye on that number inside that "C". You could be picking up a Class 4 card.

I highly recommend a Class 10 or U-1 SD card or better. If you are using Raspberry Pi or Odroid you must get the MICRO SD CARD VERSION, and I would recommend any adapters that can come with it such as letting you use that microSD card as a Thumbdrive or regular SD card. Be very careful not to lose them as microSD cards are smaller than a dime and SD cards are about the size of a quarter. (It makes you wonder what the CIA uses these days.)

See what's on it

There are a few ways to see what devices are plugged into your computer. Our microSD card is what is know as a block device as it contains a block of memory. Character devices are generally input and output devices like keyboards and mice but we're not interested in that at the moment.

List your Block devices

On Linux our block devices generally will begin with /dev/sdX or /dev/sdXN where X represents a drive letter (if you are familiar with that concept on Windows) and N is a partition number. You could say that the "sd" part means "storage device", now that I think of it.

Let's pull up a list of our storage devices.

$ ls -l /dev/sd*
brw-rw---- 1 root disk 8,  0 Jan 19 22:25 /dev/sda
brw-rw---- 1 root disk 8,  1 Jan 19 22:25 /dev/sda1
brw-rw---- 1 root disk 8,  2 Jan 19 22:25 /dev/sda2
brw-rw---- 1 root disk 8,  3 Jan 19 22:25 /dev/sda3
brw-rw---- 1 root disk 8, 16 Jan 19 22:25 /dev/sdb
brw-rw---- 1 root disk 8, 32 Jan 19 22:25 /dev/sdc
brw-rw---- 1 root disk 8, 48 Jan 21 19:00 /dev/sdd
brw-rw---- 1 root disk 8, 64 Jan 19 22:25 /dev/sde

You may notice not every item on the list has a partition number. Thats OK. Generally the devices that are mounted are the ones that will have a partition number. A partition is a section the storage device. Partitions are generally allocated when we first install our system and it is generally not recommended to repartition (changing the size of a partition) a storage device unless you plan to wipe the disk.

Clearly, disk partitioning is not a task for the faint of heart or for new geeks. Partitions are sequential and are assigned by their block number at a low-level defintion of the drive of which most people really don't think about. High-level would be people doing their everyday stuff on the computer.

That ls command we did will show both mounted and unmounted devices. But if you just want to see the details about your mounted devices, consider this next command.

$ df -hT
Filesystem               Type      Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu-root  ext4      909G  202G  661G  24% /
none                     tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
udev                     devtmpfs  3.9G  4.0K  3.9G   1% /dev
tmpfs                    tmpfs     788M  1.5M  787M   1% /run
none                     tmpfs     5.0M     0  5.0M   0% /run/lock
none                     tmpfs     3.9G  355M  3.5G   9% /run/shm
none                     tmpfs     100M   60K  100M   1% /run/user
/dev/sda2                ext2      229M  151M   66M  70% /boot
/dev/sda1                vfat      190M  124K  190M   1% /boot/efi
/home/jrcharney/.Private ecryptfs  909G  202G  661G  24% /home/jrcharney/Private

You may be wondering "Where's /dev/sda3? Technically, /home/jrcharney/.Private is /dev/sda3. I added the -T argument to show the various filesystem types. This will be important later. Let's do this again only this time with the SD Card inserted.

On most Linux Desktop Environments (KDE, GNOME, MATE, and LXDE), the mounting process is automated. You plug in the SD Card and a window shows up. But if you are using something like Fluxbox, you probably won't even see a window. I'll try to talk about manually mounting devices later.

$ ls -l /dev/sd*
brw-rw---- 1 root disk 8,  0 Jan 19 22:25 /dev/sda
brw-rw---- 1 root disk 8,  1 Jan 19 22:25 /dev/sda1
brw-rw---- 1 root disk 8,  2 Jan 19 22:25 /dev/sda2
brw-rw---- 1 root disk 8,  3 Jan 19 22:25 /dev/sda3
brw-rw---- 1 root disk 8, 16 Jan 19 22:25 /dev/sdb
brw-rw---- 1 root disk 8, 32 Jan 19 22:25 /dev/sdc
brw-rw---- 1 root disk 8, 48 Jan 21 21:25 /dev/sdd
brw-rw---- 1 root disk 8, 49 Jan 21 21:25 /dev/sdd1
brw-rw---- 1 root disk 8, 64 Jan 19 22:25 /dev/sde

Depending on your distribution you may see /dev/sdd and/or /dev/sdd1 or some other letter where that second d is.

Next let's look at what df -hT has to say.

$ df -hT
Filesystem               Type      Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu-root  ext4      909G  202G  661G  24% /
none                     tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
udev                     devtmpfs  3.9G  4.0K  3.9G   1% /dev
tmpfs                    tmpfs     788M  1.5M  787M   1% /run
none                     tmpfs     5.0M     0  5.0M   0% /run/lock
none                     tmpfs     3.9G  365M  3.5G  10% /run/shm
none                     tmpfs     100M   60K  100M   1% /run/user
/dev/sda2                ext2      229M  151M   66M  70% /boot
/dev/sda1                vfat      190M  124K  190M   1% /boot/efi
/home/jrcharney/.Private ecryptfs  909G  202G  661G  24% /home/jrcharney/Private
/dev/sdd1                vfat       30G   32K   30G   1% /media/jrcharney/5630-C8FD

Generally, an SD card will use the vfat filesystem type, although the image will write an ext4 filesystem on it.

Other commands worth checking out

Another command that some people use to see what is on a device, be it mounted or not, is fdisk

$ sudo fdisk -l

WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1  1953525167   976762583+  ee  GPT

Disk /dev/mapper/ubuntu-root: 991.2 GB, 991151783936 bytes
255 heads, 63 sectors/track, 120500 cylinders, total 1935843328 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/ubuntu-root doesn't contain a valid partition table

Disk /dev/mapper/ubuntu-swap_1: 8547 MB, 8547991552 bytes
255 heads, 63 sectors/track, 1039 cylinders, total 16695296 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/ubuntu-swap_1 doesn't contain a valid partition table

Disk /dev/sdd: 31.2 GB, 31167873024 bytes
64 heads, 32 sectors/track, 29724 cylinders, total 60874752 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdd doesn't contain a valid partition table

I'm not a fan of fdisk, especially with the whole WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted. message. The Ubuntu forums has a thread dedicated to what that means. (What is really means is that they want you to use gdisk which is another version of fdisk, which I've never used.)

It is OK if fdisk reports that a disk doesn't contain a valid partition table. fdisk is supposed to show partitions by the partitions' block addresses. If you need to think about what a block address is, think of your hard drive as a sky scrapper that his home to several large companies, and think of each company as a partition. A company (partition) is located within a specific set of consecutive floors. Some companies may have empty floors (empty disk space) while some floors are occupied (used disk space). This does happen in real life by the way.

For instance, much of the new One World Trade Center in New York is unoccupied as of 2015. Thus, think of those empty floors empty disk partitions. The only time it is OK to partition a partition is of that partition is BLANK! Never repartition a partition that is occupied with data. You will lose it or you won't be able to access that partition. And definitely do not partition the harddrive you are currently using unless you don't want it to work ever again...or at least not function properly.

Partitioning is not a task for new users, and you would be better off only experiementing with it with blank data.

Wiping a (micro)SD Card

If you have your image file ready, and the SD card that you had was previously used, it might be a good idea to wipe it first. I hightly recommend doing this inside a terminal (GNOME Terminal, KTerm, URXVT, etc.) running a terminal multiplexer program such as tmux first. This will be important later when we use a kill command to check on the status of the system wipe.

These instructions assume you have that done and that you don't have an SD card plugged in. Let's begin. These instructions also assume you are not using Windows as your operating system but Linux or BSD.

  1. ls -l /dev/sd* to list the block devices that are storage devices.
  2. df -h to list the file partitions that are mounted.
  3. Insert the microSD card into your computer via a microSD card read or an SD Card adapter or USB adapter that will allow access the microSD card. If any new windows open, close them.
  4. Repeat steps 1 and 2 but take note of any new devices or partitions in that list. We'll call the device that shows up /dev/sdd and the first partition (if there is one) /dev/sdd1. If there is a /dev/sdd2, this device will likely need to be formatted first or you will need to use a different microSD card. If you have a used card that you are willing to format, continue to step 5.
  5. sudo umount /dev/sdd* to unmount all partitions on /dev/sdd and/or the device itself. But don't remove the microSD card. Take note that umount is spelled with only one "n" in it.
  6. Repeat steps 1 and 2 again. The df command will not show /dev/sdd or any of its partitions (if there were any), but the ls command will still show /dev/sdd as well as any of its partitions (if there are any) still in the /dev/ directory.
  7. This will be important for the next step. Type sudo echo "". The importance of this is so that when the pv command that is used in the next step is used, the sudo prompt is not called and exposes your root password or any other wierd behavior.
  8. Assuming you have Pipe Viewer,pv, installed, run this command to format the SD card: sudo dd if=/dev/zero bs=1G | pv | sudo dd of=/dev/sdd bs=1G. I'd also recommend doing this command inside of tmux so that you can CONTROL+B to another tab and do something else while you wait. This is probably the most dangerous step, but I'll explain why at the bottom. Basically, we are telling dd ("disk destroyer" as some people call it") write a bunch of zeros as the input file and it will write that to output file which is the entire disk obliterating any partitions on it. Using pv, we can see how much progress has been made, how much time has elapsed during this process, and the rate of which the format is being done.
  9. sync and remove the microSD card. The sync command will write any data buffered (saved) in the memory out the the disk and make it safe to disconnect the Micro SD card. This will be quick.

If for some reason the block device doesn't mount up again after a wipe, you may have to [mount the device manually](Mounting devices manually).

Also, if dd is still running, be sure to kill it. (sudo kill -9 <pid of the dd command>)

dd is DEATHLY DANGEROUS!

As I had previously stated, the very dangerous dd command. Misuse of this command will and can format the hard drive. Even a typo could wipe out some other drive EVEN YOUR HARDDRIVE if you are not careful.

To format an SD card do this command and then go do something else for a while because it will take some time.

Also, it is important that you use the bs (block size) attribute for the dd command. Setting bs to about 4M (four megabytes) is typical for most modern file systems. You could try 16M, but I definitely wouldn’t recommended it. I would recommend setting the bs setting because the default of 512 bytes is very slow!

Writing an image to the file.

The procedure for writing an image to an SD card is very similar to wiping it. Only instead of using this command on step 8:

sudo dd if=/dev/zero bs=4M | pv | sudo dd of=/dev/sdd bs=4M

You use this command

sudo dd if=kodos_linux_armhf-20150121.img bs=4M | pv | sudo dd of=/dev/sdd bs=4M

where kodos_linux_armhf-20150121.img is the name of the image file you created. (Obviously that is a fake file name. It's what I could come up with on such short notice.)

If it works when plug it in, there should be what looks like a file system set up on the device.

If you are read to move on to the next step: [Setup your Raspberry Pi »](Setup your Raspberry Pi)

Not sure if it will make a difference in performance, but try to put the MicroSD Card into the MicroSD-to-SD adapter. Maybe it is the MicroSD card reader on my computer, but for some reason the SD reader runs faster.

TLDR

  • Install pv to see what's going on.
  • Do a sudo echo before any dd | pv | dd command.
  • You might want to do this in a terminal multiplexer tmux such that the longer steps are done at the same time.
# 1. Go to https://www.raspberrypi.org/downloads/raspbian/
# 2. Get the latest stable image. It will take about 15 minutes to download.
#    It will likely download faster if you get it via torrent.
#    I really wanted to share curl instructions, but everytime I did that it sucked.
# 3. Once it is downloaded, if you did it via zip file do this command.
unzip 2015-11-21-raspbian-jessie.zip

# 4. While that's going on, in another terminal do the formatting.
# 5. Display the list of drives.
df -hT

# 6. Insert MicroSD card into the slot.  If a window opens, close it.
df -hT

# 7. unmount the new drive and any of its partitions that weren't there 
#    the first time we ran `df -hT`, in which our example is /dev/sdd
sudo umount /dev/sdd*

# 8. Format the card before buring the image. Using the command below.
#    Block sectors (`bs`) can be high. If you get a message stating 
#    it is a read-only file system, take the card out and go back to step 5.
#    This will take about 90 minutes even at its highest speed.
sudo echo ""; sudo dd if=/dev/zero bs=1G | pv | sudo dd of=/dev/sdd bs=1G

# 9.  When the you see this message show up
#	dd: error writing ‘/dev/sdd’: No space left on device
#     Don't do anything until the rest of the message shows up.
#     It should look something like this for a 64 GB card.
#	0+477121 records in
#	0+477120 records out
#	62537072640 bytes (63 GB) copied, 5462.24 s, 11.4 MB/s
#	58.2GB 1:31:02 [10.9MB/s]
#     When that shows up, you must run the `sync` command next
sync

# 9. Remove the card from the SD slot and put it back in.
#    If a window doesn't pop up that's OK.
#    If `df -hT` or `ls -l /dev/sdd*` don't show anything, that's OK too.
#    Everything should go back to working normally once we finish this next part.
#    If not, you can restart the computer later when you are done.

# 10. When the image is done downloading ad the disk is formatted,
#     we can burn (mount) the image to the microSD card.
#     Block sizes are much smaller now.
sudo echo ""; sudo dd if=2015-11-21-raspbian-jessie.img bs=4M | pv | sudo dd of=/dev/sdd bs=4M

# 11. Sync, remove, and plug it into the raspberry pi.
#     Proceed to the next page of the full instructions if you are doing a Rasbpian install.
sync

Backing up your system.

dd may be a dangerous command but it is also an important command to use.

You should find time to occasionally back up your file system image by using dd to create a .img file then use something like xz to compress it.

  1. Plug the microSD card into your card reader or adapter. Close any windows that may show up.
  2. dd if=/dev/sdd bs="16M" | xz > bill_clinton.img.xz Do not do this with a live system! You will have a bad time!

Partition Expansion

Don't worry about that. It's covered in [Setup your Raspberry Pi](Setup your Raspberry Pi)

Doing this in Windows

NOTE: These instructions are for mounting an .iso .img image to an SD card if you are using Windows.

I'll admit most of my audience is still using Windows. And for that reason, this section will deal with that issue. However, one of the many reasons I like to use Linux over Windows is that Windows doesn't work well with devices that have multiple partitions, which is just about any Linux system which has a small partition for the boot directory and a large partition where all your stuff is kept. Guess which partition Windows will only mount because it doesn't know any better?

On the other hand, if you are in that situation where Windows is your only option, consider using this method.

For burning our Raspbian .iso to our MicroSD card, we need three things:

  1. An Class 10/U1 Micro USB card, preferibly at least 32 GB or larger. I usually use a 64 GB.
  2. A Micro SD USB card reader. I have some kind of 5-in-1 card reader made by Gear Head that was $6 at Micro Center. You can also use the Micro SD card reader on your computer but I recommend using some sort of method were you can stick the Micro SD card into an SD card adapter because for some reason it seems to work better. Also, this doesn't seem to work if you plug it into the micro SD card slot. It needs to be a USB adapter.
  3. A copy of the Raspbian .img either downloaded from a .zip file a zip file thorough a .torrent file. I prefer Deluge as my BitTorrent Client.
  4. A mounting utility. In this tutorial, I'll be using Rufus.

With our items at hand, let's proceed to the assembly.

  1. Do not put the Micro SD USB adapter in the slot yet. Open Rufus first! Rufus will look like this.

Rufus1

  1. Now plug in the Micro SD USB adapter with the Micro SD card in it. Rufus will look like this. Also don't forget to close the window F:\ appears in when it shows up.

Rufus2

  1. We need to change some options. Change it so that it looks like this. But don't click the checkbox for "Create a bootable image" just yet or we won't be able to set the other settings.

Rufus3

  1. When that is done, you may now click on "Create bootable image". Remember to set it to "DD image".

Rufus4

  1. Don't forget to click on the Disk Icon next to the dropdown menu you set to "DD image" to tell Rufus what image to burn after formatting. Our image is located in D:\Torrents\2016-02-09-raspbian-jessie\2016-02-09-raspbian-jessie.img. When everything looks like this we will be ready! (Notice the bottom!)

Rufus5

  1. Click "Start". You will be prompted as to whether or not you want to destroy the image. Click OK to confirm.

Rufus6

  1. In about five or six minutes, F:\ will pop up. When that happens, right clicking on F:\ icon, and select "Eject".

Rufus7

  1. Proceed to the next set of instructions: [Setup your Raspberry Pi »](Setup your Raspberry Pi)

See Also

  • [cross compiled](Cross-Compiling for the Cowardly Coder)
  • [Mounting devices manually](Mounting devices manually)

External Links

Mainly some ideas.

Setup

  1. [Assemble the Hardware](Assemble the Hardware)
  2. [Install the Software](Install the Software)
  3. 🆙 [Setup your Raspberry Pi](Setup your Raspberry Pi)
  4. [Download the Missing Parts](Download the Missing Parts)

Typical Utilities

  • [Downloading and extracting with curl and tar](curl and tar)
  • [Browsing with ls and cat](ls and cat)
  • [Searching with grep and find](grep and find)
  • [Filtering with sed and awk](sed and awk)
  • [Piping with less, pv, and tee](less, pv, and tee)
  • Monitor your system with htop
  • Multiplex with tmux

Clone this wiki locally