UPDATE (May 2017):
This article focus on using a Raspberry Pi 2 & USB.
If you however have a Raspberry Pi 3 and the latest version of Rasbian (Jessie April 2017 or later) then you can natively run from USB – See the documentation here on Raspberrypi.org (https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md)
I have been playing around with my Raspberry Pi 2 lately and read that if you want to run some write-intensive code on the Pi (MySQL, etc.) and you have an SD card, you’re probably heading for trouble. SD cards have improved over the years, but they still suffer from having a limited write-cycle (eventually they stop working).
USB stick/drives on the other hand are quite cheap and have a much better write-cycle.
So my next “project” was trying to figure out how to run Raspbian Jessie from a USB stick.
Currently there is no way to boot directly from a USB stick on the Raspberry Pi, but this is solved by using a small SD card to bootstrap the process and point the boot-up manager to boot from the USB stick.
The following article gave me most of the information I needed, but I adapted it to my own set-up which I am documenting in this post – Install & Run Raspbian from a USB Flash Drive
Step 1 – Download Raspbian
Download Raspbian from the RaspberryPi website – https://www.raspberrypi.org/downloads/raspbian/
I downloaded the Raspbian Jessie Lite version as I’m planning on running a non-GUI, head-less installation. This process will work for the full version as well.
Unzip the downloaded file to get the .img file ready to use.
Step 2 – Install Raspbian on your USB stick
I use ApplePi-Baker to make this process quick and easy.
Open ApplePi-Baker, supply your admin password (required as ApplePi-Baker needs root access behind the scenes to write the .img file, etc.)
First off, I “prep” the USB stick by formatting it
- Select the drive (under the Pi-crust option)
- Click on “Prep for Noobs” (basically ensuring the partitioning and formatting is done)
- Wait for the prep to finish
Now you want to write the image file to the USB stick
- Select the .img file (under the Pi-ingredients section)
- Click on the “Restore Backup” option – this will write the .img file to the USB stick and may take a while to complete (5-10 mins depending on speed of USB stick)
Your USB stick is now prepped BUT you still need to configure the MicroSD card to ensure the Raspberry Pi boots from the correct drive.
Step 3 – Configure the MicroSD card
Use ApplePi-Baker to prep the SD card as well
- Select the card in the Pi-Crust section
- Click on “Prep for NOOBS” to partition and format it
Once formatted, you should see this drive mounted on your desktop as “RASPBERRY”
Copy all the files from the USB stick to the SD Card.
Step 4 – Change the boot path on your MicroSD card
Once you’ve completed step 3, you now need to tell the Raspberry Pi to boot from the USB stick. You do this by changing the boot path setting in the cmdline.txt file in the root of the MicroSD card.
Open the file using TextEdit and change the following:
Save the changes and eject the USB stick and MicroSD card.
Step 5 – Boot up your Raspberry Pi
Plug your MicroSD card in the slot in the Raspberry Pi and the USB stick in one of the USB ports.
Add power and wait for the Raspberry Pi to boot up 🙂
Step 6 – Housekeeping (utilising all the space on the USB stick)
To utilise all the space on the USB stick, we need to expand the partition. Normally you would make use of the raspi-config utility to expand the file system, but this does not work on USB sticks.
Log in to the Raspberry Pi (standard username: pi, password: raspberry [change this in future :-)])
Start FDISK with the following command:
sudo fdisk /dev/sda
Press p to see all the partitions. You should have only 2.
We need to delete the 2nd partition and recreate it – BUT we need to note the start position for the sda2 partition. (write down the start position number – for me it was 131072)
Press d and then 2, then ENTER. [this will delete the partition]
Now we need to create the partition again.
Press n, then p, then 2 and then ENTER.
Provide the start position (first sector) for partition 2. (for me it was 131072)
For the end position, just hit ENTER to use the full partition.
Press w to commit the changes. You will see a message about the table being in use, etc. but don’t worry about it.
Reboot the system to start using the updated partition info.
Once rebooted, we need to resize the partition to use the full amount of space.
sudo resize2fs /dev/sda2
Once it’s done, reboot your Raspberry Pi again.
Confirm that the changes have taken effect by checking the space allocated using:
That’s it !
You are now running Raspbian Jessie from a USB stick (using the SD card to inform the Raspberry Pi to boot from the USB stick :-))
Have fun !