dvaitman
Posts: 15
Joined: Wed Jan 13, 2016 1:59 am
Location: Melbourne, AU

How to boot ANY pi distro from usb?

Wed Jul 26, 2017 2:13 am

Is this possible? I'm asking about booting fully from a usb and not having an SD card at all.
I know the latest raspbian image can be written directly to a usb, and the raspberry pi 3 will know and boot from the usb device. A bit of my investigation showed me that the changes I could identify where mainly on the cmdline.txt file on boot, and fstab on /etc/root
so, previously these files would have the following:

Code: Select all

cmdline.txt:		root=/dev/mmcblk0p2 
fstab:		/dev/mmcblk0p1	/boot	vfat	defaults	0	0
		/dev/mmcblk0p2	/ ext4 defaults 0 1
on the new image, raspbian changes this to be:

Code: Select all

cmdline.txt:		root=PARTUUID=XXX2222333-02 
fstab:		PARTUUID=XXX2222333-01	/boot	vfat	defaults	0	0
		PARTUUID=XXX2222333-02	    / ext4 defaults 0 1
I know earlier suggestions to run from an attached USB were done by changing the root partition to /dev/sdx2; but this method still requires an SD card to boot and points the ROOT to the usb. Also, I read that sdX could change depending on what and what port is used... hence I think why raspbian is now using PARTUUID

Now, I've tried to apply the same raspbian principle to other distros (Google AIY, Retropie) without any success.
I've changed cmdline.txt and fstab to use PARTUUID as per the raspbian distro.. no luck
My questions:

is there any other place I should be updating these references?
read somewhere around adding

Code: Select all

	initramfs initrd.sda 
to config.txt (I'll have to check if there are differences between these files on new and old distros); but "initrd.sda" suggests me that it's using /sdx# as a reference?

Is there something tied to the kernel (?) [complete noob here] that allows using PARTUUID in the cmdline.txt and fstab references? maybe these other distros haven't updated their kernel?

Anything else I could/should try?

I'm very keen in running from USBs. A lot easier to swap them, and cheaper to get.

PS: Bonus question
If I want to use the old method of keeping an SD that points to a root partition on a USB, am I ok to format a smaller SD card, and do a "filecopy" of the "boot" partition via say windows explorer? (asking this because most of the tutorials ask to burn the image to the SD, but if I only need the boot partition, I can use a much smaller SD card!)

User avatar
procount
Posts: 1854
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: How to boot ANY pi distro from usb?

Wed Jul 26, 2017 9:24 am

Most, but not all, distros can be booted from USB on the Pi3.
The cmdline.txt and etc/fstab are typically the only files that need modifying to reference the "boot" and "root" partitions so that they can be located and used.

The use of PARTUUID and /dev/sda references is a separate issue. PARTUUID is not required to boot from USB, but it makes life easier, so it is becoming more the norm for distros to support this. The problem is due to the assignment of device names for the various USB devices/partitions.

The SD card is ALWAYS /dev/mmcblk0, so it is easy to hardcode the partition references as /dev/mmcblk0p1, /dev/mmcblk0p2 etc.
If you have a single USB attached storage device, it will be /dev/sda, so you can reference the partitions as /dev/sda1, /dev/sda2 etc.
However, if you have more than one USB, the labelling of them as /dev/sda and dev/sdb will not be reliable. Sometimes they may swap over, and in that case the references to /dev/sdaX will be wrong and it won't boot (or it won't boot what you expect if they are both bootable!).

The use of PARTUUID is to make references to partitions independent of this device labeling and therefore deterministic. It is based on a DISK having a Unique identifier in the MBR, and referencing the partitions relative to that. So for example, the disk might have a UUID of 7A0C1234, so its partitions will be referenced as 7A0C1234-01, 7A0C1234-02 etc. Provided all DISKS are given unique IDs, it avoids the problem, but when CLONING a disk, it might be a good idea to give it a revised UUID and update references accordingly to avoid 2 disks with the same UUID being used simultaneously.

So you can see that changing the cmdline.txt and fstab to a random partuuid will not work. You must use the UUID of the disk as a basis. (You can find the disk UUID using fdisk).

As you seem quite new to this, I would suggest using NOOBS (or my improved PINN version) to install your OSes. The latest version (>v2.4) will
1) install OSes to the SD card (all RPi devices)
2) allow the boot partition to be on the SD card and the rootfs to be on a USB device (all RPi devices), or
3) (if you put NOOBS/PINN on the USB device) then it will install the OS boot and root partitions to the USB device so you no longer need the SD card (RPi3 only)
And they allow multi-boot of several OSes from the same device. PINN will allow installation of a larger range of OSes, including Retropie and Google AIY etc.

Once you have this working you can explore how the mechanism works and then move onto configuring OSes without NOOBS/PINN (although personally I put PINN on all my devices as a small recovery/emergency tool, and it will become even more useful in the future).
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

dvaitman
Posts: 15
Joined: Wed Jan 13, 2016 1:59 am
Location: Melbourne, AU

Re: How to boot ANY pi distro from usb?

Wed Jul 26, 2017 11:42 pm

Hi Procount,

thanks for your response. Great explanation of how it works.
procount wrote:
Wed Jul 26, 2017 9:24 am
As you seem quite new to this, I would suggest using NOOBS (or my improved PINN version) to install your OSes. The latest version (>v2.4) will
1) install OSes to the SD card (all RPi devices)
2) allow the boot partition to be on the SD card and the rootfs to be on a USB device (all RPi devices), or
3) (if you put NOOBS/PINN on the USB device) then it will install the OS boot and root partitions to the USB device so you no longer need the SD card (RPi3 only)
And they allow multi-boot of several OSes from the same device. PINN will allow installation of a larger range of OSes, including Retropie and Google AIY etc.

Once you have this working you can explore how the mechanism works and then move onto configuring OSes without NOOBS/PINN (although personally I put PINN on all my devices as a small recovery/emergency tool, and it will become even more useful in the future).
I've used NOOBs before, but don't really use it that much. Might try PINN for all these distros I want to play with, as long as it all boots from a USB, with no need for an SD card.

procount wrote:
Wed Jul 26, 2017 9:24 am
changing the cmdline.txt and fstab to a random partuuid will not work. You must use the UUID of the disk as a basis. (You can find the disk UUID using fdisk).
I understand this and I haven't been changing it to a random partuuid. I've used sudo blkid to get the PARTUUID of the usb drives I've been using.
maybe one thing I can try is using an old raspbian version and manually changing /dev/mmcblk0 to PARTUUID. see if that works.

So, any other ideas why it wouldn't work for me if I'm changing /dev/mmcblk0 to PARTUUID?

Return to “Advanced users”