Install Raspbian on and boot from a USB Drive
This tutorial is written assuming you are using a Linux machine or Mac OS. Windows does not use BASH.
There is no SATA port on the Raspberry Pi which is kind of annoying because who wants to write to and from an SD card all day? SD cards are annoying because they have a limited read/write cycle and when you are doing stuff like databases it wont be long before you start to get corruption. This tutorial will outline how to get Raspbian (the official Debian Linux for the Pi) installed on and booted off of a USB drive.
Step 1: Download the Raspbian Image
The Raspbian image is available for free from the official Raspberry Pi website. You will need this, nothing special here but regardless you can download it here.
Step 2: Install Raspbian To The Drive
You will need to mount your USB drive and launch your terminal. There is a command you will have to run in order to get the identifier of your disk. Enter:
A list of all the attached drives will appear. You will need to note the correct identifier here because you can do some serious damage later if you don’t know which one is the correct one. Often the drive will appear like /dev/disk1. If you do not know which one is the correct one, remove the drive and run the command again. The one that is missing will be the one you need to note. After you have identified the correct drive you will need to unmount the disk from the system:
diskutil unmountDisk /dev/disk1
Now comes the fun part, we will copy the files to the drive. If you have downloaded the files and left them in your downloads folder then chances are the directory is ~/downloads (~ represents the home directory). You will need to change directories to the downloads folder.
Next we will run the command to copy the files. It is incredibly important that you select the correct drive. You WILL do damage if you choose the wrong one. The numbers in the .img file may be slightly different if you downloaded it after I wrote this.
sudo dd bs=1m if=2013-07-26-wheezy-raspbian.img of=/dev/disk1
This takes anything from 5 to 20 mins depending on the speed of your USB Flash Drive. The computer is now moving all the data from your computer onto the drive.
Step 3: Configure the SD card
If you are using Ubuntu (or any other version of Linux) you can open up gparted and if you are using Mac OS you can open up Disk Utility (both format disks, how about that?). You will need to select the SD card and erase any partition currently there. Once that is done you will want to create a FAT 32 (MUST be FAT 32) partition. Once this is done you will be able to mount the drive. You will notice you have a mounted SD card and a mounted USB drive that you just copied your files to.
You will need to copy over the files from the USB drive to the SD card. This copies the all-important files and instructions to tell your Raspberry Pi to boot from the USB Flash Drive.
Step 4: Change the boot path
We are going to need to tell the Raspberry Pi that it needs to boot from the USB drive. Since it is generally looking to boot from the SD card, we will need to tell it where to look. Open up the file called cmdline.txt in nano or vim (or whatever) and amend the line:
Now this will tell your Raspberry Pi to boot from the USB Flash Drive instead of from the SD card. You are all set, you can now boot your Raspberry Pi off your USB drive.
Step 5: Expand the Raspbian partition
At this point you should boot into the Raspberry Pi
This is optional but I am not sure why you would not do this. This allows you to utilize the entire USB drive because why wouldn’t you? If you are happy without using this space you are already done. If not you can start by running this command:
sudo fdisk /dev/sda
Now there are several steps that you will need to follow:
- Press P to view partitions
- Note that the starting position is sda2
- Press D when prompted
- Press 2
- Press enter, this will delete the partition
Now you will need to create a new partition:
- Press n to create a new partition.
- Press p for primary
- Press 2 for the partition number
- Press enter.
You are going be asked for a first sector, set this as the start of partition 2. After you will be asked for an ending position, you can just press enter to use the default settings. After this is selected you will need to press w to commit any changes. You can ignore any information that pops up about the kernel. You will now need to reboot.
After the Raspberry Pi has rebooted, you can run this command to resize the partition.
sudo resize2fs /dev/sda2
This will take some time, when it is done reboot again. Once the machine has rebooted you are all done. You have a Raspberry Pi that boots off of and uses the entire space of a USB drive.
Help support CMDann.ca
If you enjoyed this post you might consider supporting CMDann.ca by leaving a tip in the form of Bitcoin. Tips are not required but are greatly appreciated and help with hosting and supplies to continue providing tutorials, apps, news and more. Thank you.