Pinterest Stumbleupon Whatsapp
Advertisement

The Raspberry Pi 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:

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!

Leave a Reply

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

  1. Francis Gan
    July 19, 2017 at 1:17 pm

    Thanks a lot for your sharing

    Very good

  2. Leonid
    June 25, 2017 at 3:26 pm

    If boot from USB error "Unable to mount root fs on unknown-block(8,2)"
    in /boot/cmdline.txt

    must correct "rootfstype" to
    dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/sda2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

    • Christian Cawley
      June 27, 2017 at 1:19 pm

      That sounds like a fault either with writing the data to USB< or with the device itself. Best option is to retry from the beginning.

  3. Carles
    June 17, 2017 at 3:09 pm

    Hi, thanks for the guide!
    Is this still valid if I want to multiboot from my usb external hard drive?
    I would like to have the option to choose Rasbian lite + openelec
    Thanks in advance for any help

  4. xbianOEosmc-allstupid
    June 3, 2017 at 5:23 am

    wow i wish i found this guide 4 days ago. Thank you so much you god of all pi-related things

    I bow my head in respect to your uber L337 skillz

    for real, thank u.

    • Christian Cawley
      June 4, 2017 at 7:45 am

      Happy to help!

  5. Other Paul
    April 18, 2017 at 3:28 pm

    Pretty good, but I snagged myself on a gotcha. After adding that program_usb_boot_mode=1 line to the end of config.txt. The problem may be that your following instruction is "You’ll need to reboot the Pi once this is done.". Of course I had no plans to reboot at that stage but decided I'd better comment that line out for the moment and remember to uncomment it later.

    Naturally I forgot, and the rsync duly copied over the commented out version, the non usb_mode config.txt, over onto the ssd. So when I removed the ssd card after the poweroff and reapplied power, the usb boot didn't happen. Why would it?! I'd commented that last line out!

    So, put the card back in, decomment the line in /boot/config.txt, utterly forget that this is no longer the right config file, poweroff, card-out, re-power. Nothing. D'oh!

    Light dawns. Card back in, re-power, mount the sda1 and sda2 this time, edit the _right_ config.txt file (in /mnt/target/boot), unmount them [actually I forgot that but it didn't seem to matter - presumably the ordinary sync had kicked off in time], poweroff, card-out, re-power.

    Success, finally. [Sheesh!].

    Also, slight bother with parted, above and beyond the messages you warned about, given that it had previously been used with gdisk after a triple partitioning layout in an old laptop. Exiting parted and explicitly umounting everything showing up as /dev/sda* seemed to fix it though.

    Good show!

  6. Nghia
    March 13, 2017 at 2:29 am

    Hi,
    I did follow the instruction and no error occur, but last after "sudo poweroff" command and
    1. removed power ,
    2. SDcard
    3. power ON
    then Raspberry Pi does not boot from USB, red LED stay ON.
    What did I do wrong?

    Nghia

    • Christian Cawley
      April 8, 2017 at 7:11 am

      Difficult to say, I'm afraid. All I can suggest is that you restart the process. Reinsert the microSD card, reboot, and see how you get on from there.

  7. Hatex
    February 21, 2017 at 1:21 pm

    Perfect :-) thx

  8. Fernando
    February 15, 2017 at 12:23 am

    Yes all step done.. I did all updates and upgrades .. I think I did it all..

  9. Paul V Matei
    February 13, 2017 at 8:29 pm

    Hello,

    I have Raspberry Pi 3 and after I type : sudo apt-get update
    and after typing at second line : sudo BRANCH=next rpi-update
    I have my San Disk, Class 10, SDHC 32 GB not booting at all Raspberry Pi 3.
    I use an USB is 32 GB , PNY.
    I did try second San Disk, 32GB, Class 10, SDHC with the same negative result.
    My Pi 3 DOES NOT WORK ANY LONGER. I had to erase the SDHC card using
    SDFormatter, and reload RPi.img using Win32DiskImager.
    I did check SD Card for compatibility and it is listed as good to use.
    This is second email addressed to Mr. Christian Cawley without any response.
    Please help me to solve the frozen screen after typing the first two coomands
    and reboot- with no activity on Pi 3.
    Thank you

    • Christian Cawley
      February 14, 2017 at 1:02 pm

      Hi Paul

      I've received no email from you, but if you're experiencing problems, I suggest you address the official Raspberry Pi website forums.

      Please note that these instructions are a worked-through guide, focused at basic users, and yours appears to be the only one that did not work. However, as sudo BRANCH=next rpi-update is unlikely to damage your Pi, I would suggest investigating just what is wrong with your Pi. Do the LEDs work? See here for help:

      http://elinux.org/R-Pi_Troubleshooting

  10. Fernando
    February 11, 2017 at 7:12 pm

    Hi, my OTP is 0x1020000a and i dont know how to fix it and change it to 0x3020000a

    Thanks

    • Christian Cawley
      February 14, 2017 at 1:03 pm

      What model Pi are you using?

      • Fernando
        February 14, 2017 at 5:21 pm

        Pi3 B

        • Christian Cawley
          February 14, 2017 at 8:59 pm

          And you've done the steps leading up to checking the OTP?

        • Lefteros @SomniusX
          March 11, 2017 at 5:18 pm

          Well i've had the same address printed out for OTP as @Fernando

          I'm using one Intel SS series ssd 128gb connected to sata3 to usb interface, went thru the whole process but not the pi (rpi3) pings back on the network but doesn't let me log in, not by flashing clean system on the sd, not by connected the ssd disk at even the same usb port..

          So.. i'm a bit frustrated that the my pi had something done to it by me wrongfully using this guide..

          Any ideas?

        • Christian Cawley
          March 11, 2017 at 10:12 pm

          All I can suggest, Lefteros, is checking the lights (http://elinux.org/R-Pi_Troubleshooting) to establish what your Pi is telling you at boot, and consulting the discussion on the official Pi forum https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=155167

          As you can see from the comments, the vast majority of readers have had success with this, but if you've omitted any steps (updates, for instance) then that can cause problems.

  11. Kalle
    February 2, 2017 at 12:49 pm

    Next step should be to but two USB sticks in raid 1. its for secure if one dies then data dont be lost and system work without crashing.

    • Christian Cawley
      February 2, 2017 at 1:58 pm

      Genius idea, Kalle. Let's wait and see what happens!

  12. Oliver
    January 18, 2017 at 9:13 pm

    How ever has done this - Many Thanks - It works great - The first script which worked perfectly. Booting from a 32 GB USB Stick
    Cheers
    Oliver

    • Christian Cawley
      January 22, 2017 at 8:45 am

      Excellent, have fun with it!

  13. Senor CMasMas
    January 13, 2017 at 10:20 pm

    Great instructions!
    First USB boot worked like a charm!

    I am running this on a SanDisk Extreme 3.0! Even though I am only getting 2.0 speeds, the performance is astounding.

    • Christian Cawley
      January 22, 2017 at 8:44 am

      Great to hear!

  14. Ram Sambamurthy
    January 13, 2017 at 9:58 am

    Hi. By setting the OTP to boot from USB, does this mean that booting from the MicroSD will not be an option after that?

    • Christian Cawley
      January 13, 2017 at 11:00 am

      You would think so from the term OTP, BUT I've successfully booted from microSD since.

      • Ram Sambamurthy
        January 14, 2017 at 1:32 am

        christian, thanks for confirming.
        yes you're right, it's easy to assume that it won't be able to, especially from the point of view of why would the Pi guys not enable it by default. the One Time Programming thingy about some capacitor that has to be blown to enable USB boot made me think that it may be an irreversible process that changes the boot process to only USB bootup.
        this article did mention in the boot sequence involving the SD first and then USB, but was not conclusive for me.
        https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/bootflow.md
        once again, thanks for confirming.

  15. Roy Sieliakus
    January 6, 2017 at 10:15 pm

    Did exactly like you wrote, never got an error, so i thought, no problems piece of cake..
    But it does not boot from usb, and also not from sd card anymore.. :(
    Using a sandisk cruzer 16Gb. added the file 'timeout' to the usb, but nothing..

    How do i get my raspberry up and running again??

    • Roy Sieliakus
      January 7, 2017 at 12:05 am

      Got it,
      apparently it needs a wired lan connection, in stead of just wifi.
      I do not know why, but that is the only thing that has changed.
      For now i have it running on the USB.
      Thank you for the tut..

    • Roy Sieliakus
      January 7, 2017 at 12:08 am

      Got it,
      Apparently it needs a wired lan connection because with wired lan it boots up from usb.
      Why?? i have no idea because wifi is stil working.

      Anyway thanks for the tut!!

  16. geof
    January 4, 2017 at 7:25 pm

    Christian,

    Really nice article.

    I have followed the instructions exactly as stated. Everything is fine until I exit from the chroot command and enter

    sudo umount dev

    and get the following response:

    Umount: /mnt/target/dev: target is busy

    How do I solve this?

    Any help would be appreciated.

  17. Jan Paulussen
    January 1, 2017 at 3:14 pm

    The command to mount the new partitions from the USB start with:
    "sudo mkdir /mnt/target"
    But it should be:
    sudo mkdir -p /mnt/target (the parameter -p is the difference!)
    This is because the parent directory /mnt does not exist at that time yet, and I got an error because of that saying it cannot create the subdirectory.
    By adding the parameter it did work. It then is not necessairy to add it the second time, bacause there the /mnt directory does already exist.
    I hope this helps...
    PS: Thanks for the great instructions!

  18. Pete
    December 29, 2016 at 12:35 pm

    The procedure worked fine for me except the two "sed" steps at the end.

    /mnt/target/boot/cmndline.txt - Instead of "mmcblk0p2", mine was "mmcblk0p7"

    /mnt/target/etc/config - /boot and / had different "mmcblk0p6" & "mmcblk0p7" which I changed to /dev/sda1 & 2

    Hope this helps someone else.

  19. Nidde Nedelius
    December 28, 2016 at 8:01 pm

    I managed to get it working once.
    Excited I started setting up my webserver and such, using this script:
    https://gist.github.com/Lewiscowles1986/ce14296e3f5222082dbaa088ca1954f7
    But afterwards, the Pi won't boot from USB. I can put the SD-card back in and boot from that fine.
    So I tried to run the install-script before setting up the USB-boot, so that everything would already be installed and I wouldn't have to do any apt-get upgrade or similar after duplicating the system, but to no success.
    I even tried switching the firmware back to master, then back to next again, to see if that would overwrite something that got messed up by the script, but still no luck.

    Any advice?

  20. Paul Smith
    December 19, 2016 at 2:37 am

    I have been getting stuck at this point every time.

    pi@Pi-3:/mnt/target $ sudo chroot /mnt/target
    chroot: failed to run command ‘/bin/bash’: No such file or directory
    pi@Pi-3:/mnt/target $

    I have tried many times. Used 2 new USB drives. And same problem every time.
    Everything runs smoothly up until this point.
    Raspian Jessie (Pixel) latest updates. New install on sd card with Alexa installed.Nothing else.

  21. 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!

    • kikret
      December 9, 2016 at 12:36 pm

      very good questions, i will also want to know

  22. 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!

  23. 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!

  24. 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

  25. 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.

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

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

  27. 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.

  28. 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?