Expanding Arch Linux ARM image to fill SD Card for Raspberry Pi

Standard images for use with the Raspberry Pi come in a 2GB size.  That’s big enough to get a basic system up and running, without being too big so that (a) users can’t use smaller cards and (b) it doesn’t take an age waiting for the image to be written to the SD card.

I’ve been having quite a few problems getting the latest Arch Linux ARM image (currently ArchLinuxARM-2014.06-rpi.img) to expand to fill the entire SD card.  In my case, a 32GB class 10 micro SDHC card.  So my steps are documented here.

Instructions given here are valid for writing the Arch Linux ARM image to the card on OS X. They should be similar for other unix-based systems. Windows instructions are given on their site.  Instructions on resizing the card are carried out ‘live’ on the Arch Linux system and so apply to all.

First we need to download the latest image from the Arch Linux ARM site.  This comes as a zip file, so we need to extract the image.

wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.zip
unzip ArchLinuxARM-rpi-latest.zip

Next we write the image (in my case ArchLinuxARM-2014.06-rpi.img) to the card by first identifying the card:

diskutil list

Noting the name ID of your SD card – in my experiance often /dev/disk1, unmount it and proceed to write the image:

Replacing /dev/disk1 with the ID of your own card.

diskutil unmountDisk /dev/disk1
sudo dd bs=1m if=ArchLinuxARM-2014.06-rpi.img of=/dev/disk1

Boot the Pi as normally, and login with username and password of <code>root</code>.

If you run

df -h

to display the free space (in human-friendly format), you’ll see only approximately 2GB if your card is in use, hence the need to expand it.

I had found various instructions online to do this, however it seems a few fundamental changes in the structure of the latest version of Arch Linux ARM had meant some of them had left the system in an un-bootable state. The following worked for me.

fdisk "/dev/mmcblk0"
p
d
2
n
e
(return) # accept default partition no
(return) # accept default start
(return) # accept default end
n
l
(return) # accept default start
(return) # accept default end
p
w
sync
sync
sync
shutdown -r now

The system will then reboot. Once it has, login once more, and continue to expand the image to fill the card:

resize2fs /dev/mmcblk0p2
df -h

You should now notice that the full capacity of your card is now available to you.

I have collected and tweaked information from various sources to produce these instructions, and they are what have worked for me using the current version of Arch Linux ARM. I have to admit I’m slightly out of my depth, so if I have suggested anything silly, please let me know in the comments below.