Raspbian is a Debian based Linux distribution, specifically for use with the Raspberry Pi. The Raspberry Pi requires that the system is initially booted of SD. Because of this, a default install of Raspbian requires an SD card of at least 2gb.
I received my Raspberry Pi the other day, and didn’t have a spare 2gb SD card that wasn’t already being used, but I had a few smaller ones around the place (128mb, 256mb, etc). I wanted to find a way to utilize one of these smaller SD cards just for the system boot files, and then run the main system off a USB memory stick.
It turns out that the Raspbian image contains a boot partition, and as long as you can copy this to a SD card (and modify the cmdline.txt file to point to the root partition on the USB memory stick), you will be able to initially boot of a small SD card, then load the rest of the system off a larger USB memory stick.
Requirements:
- A linux PC (Only required for this guide. The same process could be done using tools on other operating systems).
- SD card (minimum 64mb)
- USB memory stick (minimum 2gb)
Determining device names:
Find the device names for both your USB device, and your SD device. You can usually use the ‘dmesg’ command to find the device names for your storage devices.
Eg: This shows the dmesg output after plugging in a USB memory stick.
$ dmesg | tail [4489268.141393] scsi 18:0:0:0: Direct-Access SanDisk Cruzer Switch 1.20 PQ: 0 ANSI: 5 [4489268.143286] sd 18:0:0:0: Attached scsi generic sg10 type 0 [4489268.146251] sd 18:0:0:0: [sdj] 7821312 512-byte logical blocks: (4.00 GB/3.72 GiB) [4489268.150144] sd 18:0:0:0: [sdj] Write Protect is off [4489268.150156] sd 18:0:0:0: [sdj] Mode Sense: 43 00 00 00 [4489268.150163] sd 18:0:0:0: [sdj] Assuming drive cache: write through [4489268.158814] sd 18:0:0:0: [sdj] Assuming drive cache: write through [4489268.162381] sdj: sdj1 sdj2 [4489268.173591] sd 18:0:0:0: [sdj] Assuming drive cache: write through [4489268.176965] sd 18:0:0:0: [sdj] Attached SCSI removable disk
In my examples, /dev/sdf is the SD card, and /dev/sdj is the USB memory stick.
Obtaining Raspbian:
Download the latest Raspbian release from http://www.raspberrypi.org/downloads
At the time of writing, the latest release was 2012-07-15-wheezy-raspbian.zip
Installing Raspbian to a USB memory stick:
Extract the zip to a location on your PC.
unzip 2012-07-15-wheezy-raspbian.zip
This should extract a single file named “2012-07-15-wheezy-raspbian.img”.
Write this image to your USB memory stick device. Make sure you get the “of” (output file) part of the command line parameters correct, so you don’t overwrite your hard drive, or any other storage device.
sudo dd if=2012-07-15-wheezy-raspbian.img of=/dev/sdj
2012-07-15-wheezy-raspbian.img being the input file.
/dev/sdj being the output file/device (the USB memory stick device).
Preparing the SD card:
Make sure you obtain the correct device name for your SD card. In this example, my SD card is /dev/sdf.
Remove any partitions that may already exist on the SD card.
(you can do this via fdisk, or use ‘sudo dd if=/dev/zero of=/dev/sdf’)
Create a single FAT32 partition.
$ sudo fdisk /dev/sdf
You should be presented with the following prompt:
Command (m for help):
press ‘n’ to create a new partition
Command (m for help): n Command action e extended p primary partition (1-4)
Press ‘p’ to create a primary partition.
p Partition number (1-4):
Press ‘1’ to create the first partition.
Partition number (1-4): 1 First cylinder (1-1024, default 1):
Press enter to automatically select the default first cylinder.
Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1024, default 1024):
Press enter again to automatically select the last cylinder.
Using default value 1024 Command (m for help):
Press ‘t’ to change the partition id
Command (m for help): t Selected partition 1 Hex code (type L to list codes):
Enter in the hex code ‘c’. This will change this partition to be FAT32.
Hex code (type L to list codes): c Changed system type of partition 1 to c (W95 FAT32 (LBA))
Press ‘w’ to write changes to the device, and exit.
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. Syncing disks. $
Now that you have a FAT32 partition created, you need to put a filesystem on it.
sudo mkfs.msdos -v /dev/sdf1
eg:
$ sudo mkfs.msdos -v /dev/sdf1 mkfs.msdos 3.0.7 (24 Dec 2009) /dev/sdf1 has 8 heads and 61 sectors per track, logical sector size is 512, using 0xf8 media descriptor, with 499650 sectors; file system has 2 16-bit FATs and 8 sectors per cluster. FAT size is 244 sectors, and provides 62391 clusters. Root directory contains 512 slots. Volume ID is 43181ecb, no volume label. $
Installing the boot files onto the SD card:
Create a couple of folders under /tmp for use when mounting the USB memory stick, and the SD card.
$ sudo mkdir /tmp/mnt_usb $ sudo mkdir /tmp/mnt_sd
Mount the USB memory stick.
$ sudo mount /dev/sdj1 /tmp/mnt_usb
Mount the SD card.
$ sudo mount /dev/sdf1 /tmp/mnt_sd
Copy across the boot files from the USB memory stick to the SD card.
$ sudo cp /tmp/mnt_usb/* /tmp/mnt_sd/
Modify the cmdline.txt file to tell the system where to find the root partition.
$ sudo nano /tmp/mnt_sd/cmdline.txt
modify this line:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
to read:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda2 rootfstype=ext4 elevator=deadline rootwait
(This is just changing /dev/mmcblk0p2 (the 2nd partition on the SD card) to /dev/sda2 (the second partition on the USB memory stick). This tells the Raspberri Pi device where to find the root partition.
Save and exit the editor.
Finishing up:
Unmount the devices.
$ sudo umount /tmp/mnt_usb $ sudo umount /tmp/mnt_sd
Remove the temporary mount folders. (Make sure they unmounted OK first, otherwise it will delete the data on the device itself).
$ sudo rm -rf /tmp/mnt_usb $ sudo rm -rf /tmp/mnt_sd
You can now unplug your USB memory stick, and SD card, and insert them into your Raspberry Pi.
Power up your Raspberry Pi, and make sure it boots up into Raspbian correctly. If all goes well, it should boot up fine.