## Saturday, 2 June 2012

### Building a Raspberry PI Image Mac osx

I did some kernel tinkering earlier today and broke my main config so I decided to build two images on SD cards so I could have a stable vs un-stable boot image. The following discusses how to build an image using a mac book pro and the usual tools.

### Initial SD image

I'm going to use the debian "squeeze" image from here and the terminal on the mac.

First it is easier if we do these operations as root so in the shell type sudo su and enter your password. Next we need to identify the disk in the card reader. In my case I did this using the following commands

mount

/dev/disk0s2 on / (hfs, local, journaled, noatime)
devfs on /dev (devfs, local, nobrowse)
/dev/disk1s2 on /Volumes/home (hfs, local, journaled)
/dev/disk1s3 on /Volumes/spare (hfs, local, journaled)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
localhost:/udRZrWiR2BXDgRrkJFCx2X on /Volumes/MobileBackups (mtmfs, nosuid, read-only, nobrowse)
/dev/disk3s1 on /Volumes/UNTITLED (msdos, local, nodev, nosuid, noowners)


In my case the disk in /Volumes/UNTITLED which is the device /dev/disk3s1, this is a mounted device so the first thing we need to do is unmount the partition so we can write to it. To do this we use the following
diskutil unmount /dev/disk3s1


Now we can proceed to write the disk image. This is a long process and it doesn't give any feedback whilst it is operating, however at the end it will report how many block written

dd bs=1m if=debian6-19-04-2012.img of=/dev/disk3
1859+1 records in
1859+1 records out
1950000000 bytes transferred in 1349.801573 secs (1444657 bytes/sec)

Now this is done we should be able to put it into the pi and boot  (username pi password raspberry)

### Disk size

If we look at the partition on the disk we have just made you will see the following
As you can see there is quite a bit of space not allocated and this is a bit of a problem if you want to install lots of software to the pi. There are a number of options we can take such as creating a new partition on the spare space and use this for home, or resize the DISK3S2 partition to a larger size.

I want to re-size the partition for ease of having a large home / root partition. The simplest method I've found for doing this is by using the linux gui but as I'm trying to keep this to mac / pi only I will use the method outlined here basically if you follow these instructions it works fine.

### Getting updated

One of the first things you should do is update the packages installed. To do this we need to run the apt package manager. In the shell execute the following command

sudo apt-get update

I also decided to update my kernel to the latest version. The good news is that there is a really simple tool to do this, here I had to do the following to get it working
sudo apt-get install ca-certificates
sudo apt-get install git


To add a user we use the unix adduser command. In my case I wanted to use jmacey as my username to sync with all of my other machines at home and work
adduser jmacey
By default this user doesn't have access to the administrator (root) account, so we need to add it to the sudoers file. This is done by using the visudo tool. This will open up an editor and we can add our new user as shown
pi      ALL=(ALL) ALL
jmacey  ALL=(ALL) ALL

In my case I've placed my username below the pi username, whilst I've left the pi user in, for security you may wish to remove this as it is a well known and documented username / password. To exit the editor use ctrl+k x to save and exit.
You should now be able to login as the new user and become root.

### GPM

If you are used to other linux distros, you may be used to using the mouse in the terminal,  this is done using the gpm package. You can install it using
sudo apt-get install gpm

We now need to edit the config file to get the correct mouse device.
sudo vi /etc/gpm.conf
# now change the device line to
device=/dev/input/mouse0
# save then
sudo  /etc/init.d/gpm restart

This should now give you a mouse in the terminal