Posts: 1
Joined: Sat Apr 25, 2015 5:13 am
Location: Adelaide

Booting Raspberry Pi From USB Flash Drive

Sat Apr 25, 2015 5:54 am

Although I'm posting this to the Beginners forum, I think you need to be familiar with writing to Sd cards and amending files.

Booting Raspberry Pi From USB Flash Drive

For this purpose, you do not need a very large SDHC card. Even something as small as 256MB will work.
Instead a writing the image to the SD card as per usual, you will write the downloaded image to a USB flash drive using the normal tool Win32DiskImager. The USB flash drive can be any size.
diskimager.png (10.53 KiB) Viewed 26239 times
Here E:\ is the USB drive. Writing the image will delete everything on the USB drive.

I’m using a Minibian image ( https://minibianpi.wordpress.com ) that I had created with some extra applications.
You can use the standard Raspbian wheezy image from https://www.raspberrypi.org/downloads/ . Please download the proper Raspbian image and not the NOOBS image to use this recipe.

Once the image has been written to the USB drive, exit Win32DiskImager.

In Windows Explorer open the newly written to USB flash drive (E: in our case). You will only see the boot files as shown below. Copy all the files (except the highlighted item System Volume Information) to a temporary directory on your hard drive. Please make sure that you copy the overlays directory as well.

After the copying, you can delete all the files from the USB drive that you have copied.
Boot Files
boot.png (47.19 KiB) Viewed 26239 times
If you check the boot files you have copied, there is one called cmdline.txt. This file controls how the Raspberry Pi boots.
If you open this file in your editor, you will see this single line
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 elevator=deadline root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

You need to amend this line.
Change root=/dev/mmcblk0p2
To root=/dev/sda2

Please note that is /dev/sda2

At the end of this line add rootdelay=15

This line should now look like this

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 elevator=deadline root=/dev/sda2 rootfstype=ext4 rootwait rootdelay=15

Note: This is a single line

I prefer to use a rootdelay of 15, to make sure the USB drive is available to the Raspberry Pi at boot time.

Now you need to copy these boot files from your temporary directory to a new SD card. As stated previously, this SD card does not need to be very large. The total size of these boot files should be less than 20MB.

Once you have created both your USB drive and the SD card as above, insert them into your Raspberry Pi and boot.
I used the information from this to create the above recipe

http://www.redrobe.com/mike/boot-raspbe ... b-sd-card/

Once your Raspberry Pi has booted, login and check the Pi’s disk space usage

df –h

/dev/root is the USB drive root (/) partition
/dev/mmcblk0p1 is the SD card boot partition

Now that you have booted from the flash drive, you need to expand the root partition on USB flash

Expanding the Root Partition on USB Stick

Note: raspi-config will not resize a USB stick

From a terminal window or command-line enter:

sudo fdisk /dev/sda

At the fdisk prompt, type p to list the partition table

You should see two partitions. One the FAT partition the other is the Linux partition on sda2
fdisk command result
fdisk.png (11.78 KiB) Viewed 26239 times
Make a note of the start number for partition 2, you will need this later (just in case).

type d to delete a partition.

You will then be prompted for the number of the partition you want to delete. In the case above you want to delete the Linux partition.

type 2

To resize the main partition, start with creating a new partition.

type n to create a new partition.

type p to be the primary partition

type 2 when prompted for a partition number.

You will now be prompted for the first sector for the new partition. Enter the start number from the earlier step (the Linux partition). It is possible it will already be shown as the default.

Next you will be prompted for the last sector you can just hit enter to accept the default which will utilize the remaining disk space.

type w to save the changes.

Now reboot the system:

sudo reboot

Once the system has rebooted, from a terminal window or command-line enter this command to do the actual resizing. This is an important step.

sudo resize2fs /dev/sda2

Note: You have to specify the actual partition sda2. Resizing might take a while (depending on the USB drive size and speed).

Once it is completed, reboot the system again. This might not really be necessary, but a good habit to get into when you are making major system changes.

sudo reboot

Once the reboot is complete, you can now verify that the Pi is using the full capacity of the SD Card.
df -h

Filesystem Size Used Avail Use% Mounted on
rootfs 3.6G 820M 2.7G 24% /
/dev/root 3.6G 820M 2.7G 24% /
devtmpfs 238M 0 238M 0% /dev
tmpfs 49M 1.2M 48M 3% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 97M 0 97M 0% /run/shm
/dev/mmcblk0p1 244M 15M 230M 7% /boot
tmpfs 97M 0 97M 0% /tmp

/dev/root line shows a 4GB USB flash drive being used.
/dev/mmcblk0p1 line shows a 256MB SD card being used for boo


Howto: Move the filesystem to a USB Stick

Boot Raspberry Pi from a 16MB SD card
http://www.redrobe.com/mike/boot-raspbe ... b-sd-card/

How can I resize my / (root) partition
https://raspberrypi.stackexchange.com/q ... -partition
Frank Nicholas

Posts: 7
Joined: Mon Aug 28, 2017 7:22 am

Re: Booting Raspberry Pi From USB Flash Drive

Sat Jan 20, 2018 10:43 am

I was wondering if this could be done trough SSH as well? I mean after the deletion of the Linux partition, will it still reboot with the SSH enabled?

User avatar
Posts: 13961
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Booting Raspberry Pi From USB Flash Drive

Sat Jan 20, 2018 11:09 am

The options for booting an RPi from a device other than the microSD card have changed a lot in the 3 years since the post you are responding to was published.

For the present situation see the Raspberry Pi Foundation documentation here: https://www.raspberrypi.org/documentati ... /README.md

Return to “Beginners”