Pinterest Stumbleupon Whatsapp
Ads by Google

The Raspberry Pi (CA, UK) is a great, versatile piece of kit, capable of projects as diverse as running a media center to use as a broadcast radio. But it has one glaring flaw: the inability to boot from USB.

Well, until now, that is.

Raspberry Pi 3 Shot by MakeUseOf

If you’re using a Raspberry Pi 3 The Raspberry Pi 3: Faster, Better, with Wi-Fi and Bluetooth The Raspberry Pi 3: Faster, Better, with Wi-Fi and Bluetooth Today, the Raspberry Pi foundation announced the release of the Raspberry Pi 3. It's the most significant update to the popular line of low-cost computers yet. Read More , it is now possible to forego booting from microSD and instead boot the computer from a USB device. This might be a flash stick, an SSD with a USB adaptor, or even a full sized USB hard disk drive. This is a significant development, so let’s take a look at how you can setup your Raspberry Pi 3 to boot from USB.

Get Started: Install Raspbian and Add New Files

It’s best to start this project with a fresh copy of Raspbian, so download the latest version (we’re using Raspbian Jessie 5 Ways New Raspbian Jessie Makes Raspberry Pi Even Easier to Use 5 Ways New Raspbian Jessie Makes Raspberry Pi Even Easier to Use Following the release of Debian Jessie in July, the Raspberry Pi community has been blessed with a new release of the Raspbian variant, based on the "parent" distro. Read More ) and install it in the usual way How To Install An Operating System To Your Raspberry Pi How To Install An Operating System To Your Raspberry Pi Here's how to get a new OS installed and running on your Pi – and how to clone your perfect setup for quick disaster recovery. Read More . As soon as this is done, safely remove the card from your PC, insert it into the powered-down Raspberry Pi and boot, remote connecting over SSH Setting Up Your Raspberry Pi For Headless Use With SSH Setting Up Your Raspberry Pi For Headless Use With SSH The Raspberry Pi can accept SSH commands when connected to a local network (either by Ethernet or Wi-Fi), enabling you to easily set it up. The benefits of SSH go beyond upsetting the daily screening... Read More as soon as it loads up.

Sign in (unless you’ve changed your default credentials Securing Your Raspberry Pi: From Passwords to Firewalls Securing Your Raspberry Pi: From Passwords to Firewalls Anyone can use Google to find the default username and password of your Raspberry Pi. Don’t give intruders that chance! Read More ) then run the following commands, which will replace the default start.elf and bootcode.bin files with freshly downloaded alternatives:

Ads by Google
sudo apt-get update

sudo BRANCH=next rpi-update

This update delivers the two files into the /boot directory. With the files downloaded, proceed to enable the USB boot mode with:

echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt

This command adds the program_usb_boot_mode=1 instruction to the end of the config.txt file.

Linux Terminal Boot Raspberry Pi 3 With USB

You’ll need to reboot the Pi once this is done.

Next step is to check that the OTP — one-time programmable memory — has been changed. Check this with:

vcgencmd otp_dump | grep 17:

If the result is representative of the address 0x3020000a (such as 17:3020000a) then all is good so far. At this stage, should you wish to remove the program_usb_boot_mode=1 line from the config.txt file, you can. The Pi is now USB boot-enabled, and you might wish to use the same microSD card in another Raspberry Pi 3, with the same image, so removing the line is a good idea.

Linux Terminal Boot Raspberry Pi 3 With USB Nano Edit

This is easily done by editing config.txt in nano:

sudo nano /boot/config.txt

Delete or comment out the corresponding line (with a preceeding #).

Prepare Your USB Boot Device

Next, connect a formatted (or ready-to-be-deleted) USB stick into a spare port on your Raspberry Pi 3. With this inserted, we’ll proceed to copy the OS across.

Begin by identifying your USB stick, with the lsblk command.

Linux Terminal Boot Raspberry Pi 3 With USB LSBLK Command

In this example, the SD card is mmcblk0 while the USB stick is sda (it’s formatted partition is sda1). If you have other USB storage devices connected the USB stick might be sdb, sdc, etc. With the name of your USB stick established, unmount the disk and use the parted tool to create a 100 MB partition (FAT32) and a Linux partition:

sudo umount /dev/sda

sudo parted /dev/sda

At the (parted) prompt, enter:

mktable msdos

You might be informed that the disk is otherwise engaged. If so, select Ignore, then note the warning instructing you that the data on the disk will be destroyed. As explained earlier, this should be a disk that you’re happy to delete or format, so agree to this.

If you run into any problems here, you might need to switch to the desktop (either manually, or over VNC How to Run a Remote Desktop on Raspberry Pi with VNC How to Run a Remote Desktop on Raspberry Pi with VNC What if you need access to the Raspberry Pi desktop from your PC or laptop, without having to plug in a keyboard, mouse and monitor? This is where VNC comes in. Read More ) and confirm the disk is unmounted, before entering the mktable msdos command in a windowed command line.

Proceed in parted with the following:

mkpart primary fat32 0% 100M

mkpart primary ext4 100M 100%

print

This will output some information concerning disk and the new partitions. Proceed to exit parted with Ctrl + C, before creating the boot filesystem, and the root filesystem:

sudo mkfs.vfat -n BOOT -F 32 /dev/sda1
sudo mkfs.ext4 /dev/sda2

You then need to mount the target filesystems, before copying your current Raspbian OS to the USB device.

sudo mkdir /mnt/target
sudo mount /dev/sda2 /mnt/target/
sudo mkdir /mnt/target/boot
sudo mount /dev/sda1 /mnt/target/boot/
sudo apt-get update; sudo apt-get install rsync
sudo rsync -ax --progress / /boot /mnt/target

That last one is the final command that copies everything over, and so will take a while to complete. Time to make a coffee!

Linux Terminal Boot Raspberry Pi 3 With USB Copying

Next, you need to refresh the SSH host keys, to maintain the connection with the reconfigured Raspberry Pi after an imminent reboot:

cd /mnt/target
sudo mount --bind /dev dev
sudo mount --bind /sys sys
sudo mount --bind /proc proc
sudo chroot /mnt/target
rm /etc/ssh/ssh_host*
dpkg-reconfigure openssh-server
exit
sudo umount dev
sudo umount sys
sudo umount proc

Linux Terminal Boot Raspberry Pi 3 With USB SSH

Note that after sudo chroot (the fifth command above) you’re switching to root, so the user will change from pi@raspberrypi to root@raspberrypi until you enter exit on line 8.

Prepare for Rebooting From USB!

Just a few more things to sort out before your Raspberry Pi is ready to boot from USB. We need to edit cmdline.txt again from the command line with:

sudo sed -i "s,root=/dev/mmcblk0p2,root=/dev/sda2," /mnt/target/boot/cmdline.txt

Similarly, the following change needs to be made to fstab:

sudo sed -i "s,/dev/mmcblk0p,/dev/sda," /mnt/target/etc/fstab

You’re then ready to unmount the filesystems before shutting down the Pi:

cd ~
sudo umount /mnt/target/boot
sudo umount /mnt/target
sudo poweroff

Note that this uses the new poweroff command as an alternative to shutdown.

When the Pi has shutdown, disconnect the power supply before removing the SD card. Next, reconnect the power supply — your Raspberry Pi should now be booting from the USB device!

Have you tried this out? Intrigued by the possibilities of a USB boot rather than from SD card? Planning to give it a go? Tell us in the comments!

  1. Rolf
    October 26, 2016 at 7:04 am

    I just updated and upgraded the Raspberry PI 3 with USB Boot and the Update reinstalls the original Kernel. The Raspberry will not boot anymore from USB...
    Is there a workaround eventually completing your famous tutorial? Or just avoid any Upgrade!

  2. Rol
    October 25, 2016 at 1:09 pm

    PI 3 with a 120 GB Stick
    Simply great. Works like a charm.
    Many thanks for this, I guess, the only really working tutorial

    • Christian Cawley
      October 26, 2016 at 6:46 am

      Delighted it worked for you, Rol!

  3. William
    October 16, 2016 at 1:27 pm

    This worked like a charm! At first, I thought things were awry, because it stays on the RaspPi rainbow boot screen. But, after what seemed like forever to us antsy types, it booted without a hitch the first time I tried it! GREAT TUTORIAL!!!

    • Christian Cawley
      October 26, 2016 at 6:46 am

      Thanks for sticking with it, William!

  4. John Douglas
    October 6, 2016 at 11:56 pm

    Great article. I followed the instructions implicitly (I think :) ). When I rebooted the RP1 3 I go these messages:
    [3.437232] USB 1-1.4.4: Unable to get BOS descriptor.
    [4.439885] SD 0:0:0:0: [SDA] Asking for cache data failed
    [4.440070] SD 0:0:0:0: [SDA] Assuming drive cache: write trough

    Can any body help with this please?

    • Christian Cawley
      October 7, 2016 at 9:20 am

      This seems like a problem with the USB device. Have you tried a different flash device?

      I used this: https://www.amazon.com/gp/product/B00812F7O8

      • John Douglas
        October 7, 2016 at 9:54 am

        I am using a WD 500 Gb sata drive mounted in an external hdd usb case with it's own power supply. Maybe I'll have to replace the drive?

        Thanks for your reply, kind regards John

        • Christian Cawley
          October 7, 2016 at 11:25 am

          I suspect it's how the drive is being recognized.

          If you can get this to work with a standard USB flash drive, then you know the new feature works. After that, it's a case of finding a USB adaptor for your HDD that offers the right compatibility

  5. Jeff Johnson
    September 21, 2016 at 2:13 am

    Thanks so much much this worked brilliantly. Great work, I had a pi3 and a 1 tb pidrive working on raspbian jessie. Ran flawlessly I had issues installing a touch screen and will have to redo at some point. Can I do this on Openelec Kodi 15.2? I'm trying to make a large capacity stand alone portable music player I would like to boot into Openelec on a the piDrive and use a small lcd to control the who;e thing. I'm piecing the portable power supply after the software and hardware are done. Willing to try anything once all ideas welcome can always format and start over.

    • Christian Cawley
      October 7, 2016 at 9:17 am

      I don't believe it will work beyond Raspbian at this stage, but would expect support for it to be included in future distro updates.

  6. Pierre
    September 17, 2016 at 8:25 pm

    Puneet: Did you remove the SD-card as mentioned above?

  7. john
    September 17, 2016 at 2:36 pm

    works well. but pi 3 is very picky on the USB memory you use.
    does not work with all USB sticks.

  8. Puneet
    September 11, 2016 at 7:39 am

    Hi,

    I tried your step by step process, it's still booting from SD card and not from USB.
    I think Raspberry is programmed to boot from SD card and unless we change the BIOS of raspberry and program it to boot from SD card as well as USB, it's not going to work.

    Puneet

    • Christian Cawley
      September 18, 2016 at 7:10 pm

      That's the whole point of the tutorial, which is based on instructions from the official Pi website. It's not like we've made this up, it actually works, on a Pi 3.

      Please make sure you double check your steps, and remember to run vcgencmd otp_dump | grep 17: - if this gives the correct result, the necessary switch has been made.

      • Bert Shure
        October 11, 2016 at 9:09 am

        Very cool!

        How about mirroring two USB Flash drives?

Leave a Reply

Your email address will not be published. Required fields are marked *