Friday, 25 May 2012

Raspberry Pi - Formatting an SD card for OpenELEC

Turns out the SD card I was using for my OpenELEC image is slightly larger then everyone elses - meaning the image won't write back correctly using Win32 imager / dd.
There is a good start to finish guide here, but for clarity and simplicity - I'll outline them here too.

First identify where your Linux OS has attached your SD card (mine was the same as this guide, /dev/sdb). Typing dmesg and examining the output will most often be the easiest way to find this. For these instructions, we'll assume yours is also attached to /dev/sdb

We need to ensure the device is not mounted anywhere first (Ubuntu, for example, will automatically try to mount removable media in /media/[device-name]

sudo umount /dev/sdb

Next, remove all existing partitions (and also, data - make sure this card is not important, backed up etc.)

sudo parted -s /dev/sdb mklabel msdos

Data removed, we'll need to create two partitions. The first being FAT32 which will become the system / boot partition for OpenELEC. The second, an EXT file system for OpenELEC using all remaining space on the card.

sudo parted -s /dev/sdb unit cyl mkpart primary fat32 -- 0 16
sudo parted -s /dev/sdb set 1 boot on
sudo parted -s /dev/sdb unit cyl mkpart primary ext2 -- 16 -2

This should give you your two required partitions. Next, you will need to format these new partitions.

sudo mkfs.vfat -n System /dev/sdb1
sudo mkfs.ext4 -L Storage /dev/sdb2

At this point, it's best to pop the card out and reinsert it to have the OS recognise the new partitions and if you're lucky - mount them for you. Otherwise, you'll need to create some mount points and reload the cards partitions manually.

sudo partprobe
sudo mkdir /mnt/System
sudo mkdir /mnt/Storage

sudo mount /dev/sdb1 /mnt/System

Now, it's as simple as copying the files from my zipfile into the right places. Extract everything to an easy to access directory, we'll use /tmp. Copy the files across (note - some of them need to be renamed which is taken care of in the code below). Then make sure you're not in a mounted directory and unmount the SD card. Fingers crossed, it should be ready for use!

sudo cp /tmp/OpenELEC-RPi.arm-devel-20120514154309-r10954.kernel /mnt/System/kernel.img
sudo cp /tmp/OpenELEC-RPi.arm-devel-20120514154309-r10954.system /mnt/System/SYSTEM

sudo cp /tmp/bootcode.bin /mnt/System/
sudo cp /tmp/loader.bin /mnt/System/
sudo cp /tmp/arm128_start.elf /mnt/System/start.elf
cd /
sudo umount /dev/sdb


  1. I did but it doesn't work :(

    1. Ok, might need a bit of a hint as to what didn't work... did you get any errors when running the commands? how long did you wait for the first boot? can you post an output of 'fdisk -l /dev/sd(x)' where x is your SD card?