In my last post I glossed over the process of creating a disk image. This is not too hard, but it is not what most computer users might expect. In the world of desktop or laptop PCs if you want to install the operating system from scratch you probably now start with a CD, DVD or a USB stick, boot from that media and it will prompt you to create the disk image on the hard disk that the computer normally boots from. Raspberry Pi is different.
I normally use Linux - usually Ubuntu which is a derivative of Debian Linux. Debian Linux is available for R-Pi, so that was my first choice. R-Pi loads from an SD card, so the operating system needs to be installed on an SD card. This needs to be 2GB at least, but that would not leave much free space for any files that need to be added, so I use a 8GB SD card. I decided to use the command line tools in Linux which give a step by step view of the process.
The disk images for a few different set ups have been created and they can be found on the downloads page of the Raspberry Pi web site. From there I downloaded the Debian "squeeze" image which was debian6-19-04-2012.zip when I looked. Also published there is the SHA-1 hash for the .zip file. To check that the file you have downloaded is intact run
and compare the resulting hash against the hash on the web site. If they match the downloaded file should be fine.
Windows gives every logical disk drive a drive letter, Linux doesn't. When a removable drive is inserted it gets mounted as part of the directory structure, in Ubuntu's case as a folder in the /media folder. The name is logical, but not always obvious. The command df displays the file systems available, run it without the SD card inserted and then with the SD card inserted to see the name of the device. If there are multiple partitions already on the SD card df shows them with a number at the end. In my case the SD card was device /media/sdb (ignoring the numbers).
I then took the .img file from out of the zip file that was downloaded, placed it into the raspi folder under my home and knowing what the SD device is called I could copy it to the SD card with the command:
sudo dd bs=1M if=~/raspi/debian6-19-04-2012.img of=/dev/sdb
It is important that I got the device name right. If I had copied the image file over an existing disk partition, it would have been wiped out of course. If you do this, be careful.
After a few minutes the command finished and I had partitions on the SD card, but if I use that card in R-Pi it would only see a 2GB disk, and ignore the remaining 6GB. So now I needed to extend one partition to fill the remaining space on the card. I started by using parted to see what the partitions on the card looked like. You need to have the card inserted in the card reader (or SD slot) but not mounted. I ran
sudo parted /dev/sdb
which starts parted. I use the unit chs (cylinders, heads, sectors) view and then print which showed three partitions, a FAT boot partition, which I left alone, the main ext4 partition which was nearly 2GB and a swap partition. I wanted to extend the main ext4 partition so first I needed to move the swap partition to the end of the space to make room. The exact numbers I used would vary on different cards as the size of storage varies from card type to card type. The command I had to issue was move 3 118223,0,0. This moved the third partition (the swap) to the end of the available space. Now the ext4 partition needed to be resized, so two commands to remove and recreate the partition are needed. This does not delete the data, just alters some pointers that a later step could use. The commands were rm 2 followed by mkpart primary 1232,0,0 118222,3,31 which used the whole space for the ext4 partition. The start point was the same as before but the end point was just before the newly moved swap partition. I quit parted. To check the partition was sound I ran
sudo e2fsck -f /dev/sdb2
This prompted me to make lost+found and I accepted that. The last step was to actually extend the partition with
sudo resize2fs /dev/sdb2
When this had run I had an SD card with a 7.7GB ext4 partition with over 6GB free space to save any data on.
When I inserted a card made like this into R-Pi the first time it booted it did some one-time changes and had to be restarted but then it worked well.
Making all of these changes on the command line will seem alien to Windows users who have been coaxed away from typing commands, but it makes more sense the more you do it. Describing, repeating and supporting command line style working is easier and often opens up more options. I do think the visualisation of a GUI interface would be easier to use for the moving of the SD card partitions, and of course they are available.