Tuesday, 13 November 2012

Transfering an image file to a SD card via Linux CLI

The objective for this blog is very straight forward, and the title should be self-explanatory. In my previous blog (here) I discussed downloading the distribution image file. (we used this one) I also explained how to unzip the image file.

The next step is to copy the image from your PC to your SD card.

Before I describe the process (all one command) it may proof useful to discuss what type of SD card to use.

Personally I don't like have a lump of SD sticking out of the side of my RPi, so one of my personal mod's is to get a Micro SD converter and use a Micro SD card instead.

These aren't that expensive and can be bought from ModMyPi. (I'd also suggest adding heatsinks, whist your in modification mode) ;-)

Now to the class of Micro SD... I have read in several forums that the class of SD make no difference when used with the Raspberry Pi. I tend to disagree. It is true that RPi's will work fine using the cheaper class 4 cards. It is also true that the class speeds listed refer to serial read\write speeds, and not the random nature of a RPi's file system. But with all that said, in my experience, and by only using two RPi's side by side I personally felt that using a class 10 Sandisk Micro SD was noticeably faster than using a cheap ADATA class 4 Micro SD card.(my only benchmarking test was to watch them booting. The hardware is the same, but each time I tried, the Sandisk RPi gave me the log on prompt first!)

This really falls down to personal choice, and I confess to buying several of the class 4 cards as my local Maplin's had them on offer. ;o) Annoyingly, there are now selling 32G class 10 cards for the same price; here.

So back to the image file, you should now have the unzipped image file in the directory your working in.

You can check this with "pwd"








You can also check the file name of your image using the "ls" command.

We are now ready to transfer this image to our SD card (or MicroSD in my case).
First we need to identify the device name given to our card.

To do this, enter the "df" command, but instead of looking at the space being used, look at the volumes mounted. (df is a command to display the free disk space).

Adding the "-h" makes the results human readable.

If you run the command before inserting you SD card, and then again after what ever volumes are new are related to you SD card.


























If you look at the second "df -h" you'll notice the highlighted is "/dev/mmcblk0".

This is the device name for your SD card. Sometimes if you have partitions on your SD card you may find it ends with "p0" or "p1". This is how Linux identifies partitions. We are only interested in the volumes device name as we have partitions within our image file.

You will need to unmount this partition before we start the transfer.

unmount /dev/mmcblk0

If you have multiply partitions, add p0 or p1 or whatever partions you have and unmount each partition.

You can check again with the "df -h" command
Now to the image transfer.

*********************************************************************************************************************************
Warning, you can damage you working PC if you get this command incorrect! be very very careful!
*********************************************************************************************************************************
The "dd" command follows the following format ;

dd if=<source> of=<target> bs=<byte size>

In my example I typed "sudo dd bs=1M if=/home/anon/RaspberryPi/2012-10-28-wheezy-raspbian.img of=/dev/mmcblk0"

If we break that down, it contains the following;

"sudo" This command should be run with root privileges.

"dd" Data Destroyer!! you have been warned! :-p Seriously, I have no idea why dd, probably because cc was already used in C. But for us, this is the command we're executing!

"bs-1M" this is the byte size. you could try 4M, or if you've lots of spare time try reducing the size. With the 4G file we're using, I find 1M chunks works fine, but does take a little while. (gives me time to write this blog) ;-)

"if=/home/anon/RaspberryPi/2012-10-28-wheezy-raspbian.img" is the location of your image file. it is important to get the absolute location. I've included my '/home/username/filedirectory' to make it easier to understand instead of using '~/filedirectory'

"of=/dev/mmcblk0" is the location we're copying our image file to... basically the volumes device name. we identified this earlier using the "df" command.

If you get your "if" and "of" the wrong way around, you will be copying the contents of your SD card onto your harddrive. (great for backing up your RPi, but risky if you get your absolute locations wrong!)

Once this process starts, be patient! transfering 4G in 1M chunks can take a while, so go do some light reading.

I suggest looking here as they do a much better job of explaining this than me.

My next blog will discuss that all important first boot!


Thursday, 1 November 2012

Raspberry Pi Madness...

When my first Raspberry Pi (RPi)was finally delivered, I decided I wasn't going to blog too much about it. There are plenty of well written, and self explanatory blogs out there which are very helpful and informative.

Since then, I have ordered two more RPi's and tried various distributions.

Whilst playing, I found there were certain tasks which I performed on every build regardless of the distribution.

During a conversation with a friend, the only other RPi owner I know personally (We geeks are a rare breed) I realised that some of the tasks I consider run of the mill may not be that obvious to some people.

So the objective of this blog is to discuss some of the steps I take when I first build a new image on the RPi. To keep things simple, I'm going to use the Rasbian image as an example, but most of these steps are applicable to other distributions. (also on other Linux based machines).

First some ground rules, I have written this blog from my home point of view. Personally I no longer use Windows on any of the machines I own. (my work laptop belongs to my company, so is the exception.) Therefore all my set-up steps are performed on Linux based machines. If you intend to follow this blog as a guide, you will need to use Linux PC. If you don't currently have one, I suggest searching for one of the many LiveCD distributions or create a Linux image on a USB drive.(http://www.pendrivelinux.com/)
If not, refer to one of the many other guides aimed at Windows users.

Also to avoid this turning into a mammoth blog, I'm going to fragment it into sections.

This section will cover downloading your image file. ;-)

So for this you can open your favourite browser and go to the downloads page and select your preferred image.
At the time of writing, this is currently found here;
http://downloads.raspberrypi.org/images/raspbian/2012-10-28-wheezy-raspbian/2012-10-28-wheezy-raspbian.zip 

Once you down load the file, it is always a good idea to check you downloaded the file without any errors. You can do this with the following command;

sha1sum ~/2012-10-28-wheezy-raspbian.zip

This will give you a checksum value which you can check against the download directory.
 For the supplied image it should be;

SHA-1 3ee33a94079de631dee606aebd655664035756be

This also confirms to important facts, 1) the file was downloaded correctly. 2) the file is the same as the file uploaded by the image provider.

It is possible to skip this step, but it can save time later if you know your image file is not corrupt!

Next, it is VERY important you know where this file is located.

I normally transfer the zipped file to a raspberry directory in my home folder.
My directory path is ~/RaspberryPi/

You will need to know this when we transfer the image to a SD card, but for now we need to unzip the image file. This can be done using the "extract here" option in your file manager (nautilus) but I prefer to do things in CLI as shown below;








For those of you who like to cut + paste the command is;

unzip 2012-10-28-wheezy-raspbian.zip

at this point you should have the 2012-10-28-wheezy-raspbian.img file in you ~/RaspberryPi/ directory.
 

Now we need to get this image onto a SD card. I'll cover this off in my next blog.