47

I know it's not possible to directly boot from an external USB stick / drive, but instead you have to boot from the SD card and then the external device can take over. What's the easiest and preferred way to set this up, therefore boot from SD card and then let an external device take over?

Steve Robillard
  • 34,687
  • 17
  • 103
  • 109
me.at.coding
  • 685
  • 1
  • 8
  • 11

4 Answers4

38

If you have an existing OS running on the Pi, then firstly it would be useful to know if the USB device is supported. You can do this by mounting it like normal:

mount /dev/sda1 /mnt 

If that fails then you wont be able to use the USB device as a root partition without enabling the kernel modules for it. And for that you may need to compile your own kernel.

If it suceeds then it should work fine with some tweaking of the boot parameters that the Pi uses:

On an existing image, open cmdline.txt, which can be found on the boot partition, and enter the following lines:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 
root=/dev/sda1 rootfstype=ext4 rootwait text

All you must then do is flash that image to the SD card and boot the Pi. If all is well, /dev/sda1 should be the location of the USB drive when the Pi boots, and thus it should attempt to use that location as root. The rootwait parameter is important as it will make the boot process hang until the USB drive is recognised. Without it the Pi may complain that the location doesn't exist.

I suggest that you copy the root partition from an existing Raspberry Pi image to your USB drive and use that to boot from.

Let me know if you need any further information.

Jivings
  • 22,538
  • 11
  • 90
  • 139
  • 2
    Also, can you use UUIDs on the command line? – Alex Chamberlain Jul 21 '12 at 15:27
  • Yes I provided the whole file and where are you talking about using UUIDs? – Jivings Jul 21 '12 at 18:01
  • 3
    Thank you very much Jivings, I "flashed" the official image to my USB stick, then copied the stuff from the FAT partiiton to an SD card and adjusted the cmdline.txt. In my case the root partition is then /dev/sda2, because /dev/sda1 is the (unused) boot partition on the usb stick. I didn't need the rootwait in my case, but good to know this parameter! – me.at.coding Jul 21 '12 at 18:14
  • @stefan.at.wpf (and Jivings) You can use UUIDs instead of /dev/sdx - at least in /etc/fstab/ - then it doesn't matter if the x changes. – Alex Chamberlain Jul 22 '12 at 16:28
  • @AlexChamberlain Can you find a source that says the firmware can understand UUID? Because I have no idea if it will work in cmdline.txt. – Jivings Jul 22 '12 at 18:22
  • It depends on the kernel... http://en.gentoo-wiki.com/wiki/Initramfs#UUID.2FLABEL_Root_Mounting – Alex Chamberlain Jul 22 '12 at 18:27
  • @AlexChamberlain In that case it should be fine. – Jivings Jul 22 '12 at 18:47
  • can i somehow check if an usb drive is avilable and then according that let it decide to boot from SD Card or USB? (with the Bootmanager/Bootloader on the SD Card ofc) – philx_x Feb 18 '15 at 07:10
  • @Jivings I am able to mount my USB stick within OS (/dev/sda1), I then replaced root='s value with /dev/sda1 inside of cmdline.txt from boot sdcard (rootwait already there), yet kernel panics while booting with message Unable to mount root fs on unknown-block(8,1) – alexus Dec 30 '15 at 04:30
  • @Jivings you said "mount /dev/sda1 /mnt" but where i should add it? –  Apr 14 '16 at 13:56
  • @watonis What do you mean by add it? – Jivings Apr 15 '16 at 12:09
  • What do you mean by "boot partition," the external USB drive or the microSD card? Where is cmdline.txt located, on the external USB drive or the microSD card? – Geremia Dec 28 '16 at 18:28
4

The easiest way to set this up would be to use BerryBoot. It supports installation to, or from, one or more images on a USB stick (or on the SD card itself) out of the box through a nice GUI interface.

To set it up all you have to do is copy the ~70MB of install files on to a FAT32 formatted SD card, insert it into your device and boot away. It even has a list of preconfigured images that it can automatically download and install for you over an ethernet or wi-fi connection.

You then select the OS you would like to be booted by default from your available images, and if you want to add new images or change the default at a later date you simply hit enter during the boot process to reconfigure!

Nathan Dunn
  • 428
  • 2
  • 4
  • 8
  • move the image to the SD card ? I thought we want to install it on a USB stick ? – Suhaib May 12 '13 at 21:57
  • As the OP stated it's not possible to boot directly off a USB stick on a Raspberry Pi - You need an SD card with a bootloader installed that can hand the process over to another device once powered up. – Nathan Dunn May 14 '13 at 00:19
2

ok, to clarify -

further to @Jivings answer -

There are several ways that you can refer to a disk in the fstab. Using /dev/sdXX might not always be safe, as the order that scsi disks appear may not be guaranteed.

What I do not know, is if the boot configuration understands anything but basic device labels. "root=/dev/sda1" is an abstraction however, so in theory root=LABEL=TEST might work. I need to investigate.

I apologize if I am not being very clear. I've got some skill gain to do in explaining linux to new folks, obviously.

Nox
  • 106
  • 1
  • 1
  • 1
    Jivings: could you explain some of the parameters in your comand line example for us nubies? Thanks. – Michael Moriarty Sep 29 '16 at 02:12
  • He never mentioned fstab. The target device/partition name is a kernel parameter. I believe other naming conventions like UUID are possible with modern kernels, especially if they have initrd/initramfs modules. – jiggunjer Jan 23 '17 at 04:53
0

Assuming this is about RPi 3b and not RPi 2 or even older models: ~9 years later the answer is that you can use an USB device just like a SD card. Just dd the image onto the USB medium or use the flashing tool from the Raspberry website.

robo
  • 111
  • 3
  • I am not sure if this is correct. Your answer is based on a raspberry model 3. Model 2 firmware is said to not support this feature. Can you give me some source if I am wrong? Because your suggestion is not working with raspberry 2 B – benni Feb 06 '22 at 21:18
  • @benni that's right, I was referring to model 3 – robo Feb 14 '22 at 04:38