Triple Boot Raspberry Pi on USB (Raspbian / RetroPie / OpenELEC) – Part 2 6


WordPress Logo In this blog post, I continue to delve into the mysteries of the triple-boot Raspberry Pi install. Remember our goal is to install three OSes; Raspian, RetroPie, and Openlec, move all root filesystem to a fast USB key and install a script that will magically reboot into an OS of our choice.

If you missed Part 1, I suggest to have look and meet me back here. Once done, we’ll have a geeked-out Raspberry Pi setup that’s the envy of all you friends!

Just a word of caution for the guide that follows. A command like dd copies data from one location to another, overwriting existing data as it goes. Needless to say, this can be dangerous and is most certainly irreversible. Don’t blindly copy the commands below without ensuring they’re applicable to your specific case – adapt them if necessary. Don’t use dd while sleep deprived. You have been warned.

Recap

If you recall, in Part 1 we completed the installation of the OSes with NOOBS onto our SD card. In fact, now’s a good time to inspect the SD card and examine what NOOBS exactly did. So pop in the SD card into your reader and fire up your partitioning tool. I’ll be using the free GParted for this.

GParted NOOBS Install (Triple boot; Raspbian, RetroPie and Openelec)

GParted NOOBS Install (Triple boot; Raspbian, RetroPie and Openelec)

As you can see, NOOBS created a bunch of partitions for us. The table below summarizes its work:

PartitionFilesytemLabelPurpose
/dev/sdb1FATRECOVERYNOOBS boot files & initramfs, OS recovery images
/dev/sdb5FATbootRaspbian boot partition
/dev/sdb6ext4rootRaspbian root partition
/dev/sdb7FATboot0RetroPie boot partition
/dev/sdb8ext4root0RetroPie root partition
/dev/sdb9FATOpenelec SYSTEM partition
/dev/sdb10ext4Openelec STORAGE partition
/dev/sdb3ext4SETTINGSNOOBS settings

Step 1 – Begin Relocating the EXT4 Partitions

What we need to do now is move the root (sdb6), root0 (sdb8) and storage (sdb10) partitions to a USB flash key. I’ll now proceed to create three ext4 primary partitions on my USB key. Ideally, the destination partitions should be larger that the source partitions or you might receive an unwelcome error message while copying. Before I begin, I ensure that both the SD card and USB key are plugged into the desktop and begin the cloning/checking/resizing process.

For this example, and this is an important point to remember, my SD card and USB key are recognized as /dev/sdb and /dev/sdc respectively while connected to my desktop. However, as far the as the Raspberry Pi is concerned (on boot up), this will get mapped to /dev/mmcblk0p(1-9) and /dev/sda. Keep this in mind while making the edits below.

cd ~/working

sudo dd if=/dev/sdb6 of=/dev/sdc1 bs=1M
sudo e2fsck -f /dev/sdc1
sudo resize2fs /dev/sdc1

sudo dd if=/dev/sdb8 of=/dev/sdc2 bs=1M
sudo e2fsck -f /dev/sdc2
sudo resize2fs /dev/sdc2

sudo dd if=/dev/sdb10 of=/dev/sdc3 bs=1M
sudo e2fsck -f /dev/sdc3
sudo resize2fs /dev/sdc3

Once done, this is how my USB appears:

GParted NOOBS Root Partitions Relocated (Triple boot; Raspbian, RetroPie and Openelec)

GParted NOOBS Root Partitions Relocated (Triple boot; Raspbian, RetroPie and Openelec)

Step 2 – Optimize Space on the SD Card (Optional)

If you notice, we’ve moved the largest partitions off our SD card onto the USB key. In fact, at some later point — assuming every OS runs correctly — we could delete these unnecessary partitions. However, I’ll choose to do something different. I realize that the partitions; RECOVERY, SETTINGS and the three BOOT partitions, take up less than 4GB. But I’m currently using a 16GB card. Indeed you say, wasted space! It just so happens that I have a 4GB SD card lying around.

Now at this point, you can follow me or not. This step is totally optional and if you decided to do the same keep on reading or else jump to Step 3.

You may be wondering, why not copy all partitions to the USB key? In reality, the Raspberry PI cannot boot from anything other than the SD Card which differs from a normal PC. Thus all boot partitions need to remain on the SD card and cannot be migrated to a USB key. Too bad…

For this to work, I’ll need to systematically copy the partitions to disk (on my desktop), create partitions on the new card and carefully restore them back. Let’s begin by clone them.

cd ~/working
sudo dd if=/dev/sdb1 of=./sdcard_recovery.img bs=1M
sudo dd if=/dev/sdb5 of=./sdcard_boot.img bs=1M
sudo dd if=/dev/sdb7 of=./sdcard_boot0.img bs=1M
sudo dd if=/dev/sdb9 of=./sdcard_system.img bs=1M
sudo dd if=/dev/sdb3 of=./sdcard_settings.img bs=1M

Now that we have all partitions from the SD card backed up, take a screen shot of the partition layout and have it handy. Pull the SD card out and replace it with a 4GB card. Create the first FAT32 primary partition, ensuring that the partition’s size is equal to or larger than the original – this will be partition sdb1. Next create an extended partition while leaving 32MB following it — this will be partition sdb2 and will house our boot partitions. Create an ext4 primary partition in the 32MB unallocated slot we just left available from the previous operation – this will be sdb3. Now within the extended partition, create three logical partitions that will serve to be our boot partitions. Refer to the screen shot you took earlier if you don’t remember their sizes. In my case, boot (60MB FAT32), boot0 (60MB FAT32) and system (160MB FAT16) partitions were created with the device names, sdb5, sdb6 and sdb7 respectively.

With that out of the way, let’s restore each partition in turn.

cd ~/working
sudo dd if=./sdcard_recovery.img of=/dev/sdb1 bs=1M
sudo fsck.vfat -a /dev/sdb1
sudo dd if=./sdcard_boot.img of=/dev/sdb5 bs=1M
sudo fsck.vfat -a /dev/sdb5
sudo dd if=./sdcard_boot0.img of=/dev/sdb6 bs=1M
sudo fsck.vfat -a /dev/sdb6
sudo dd if=./sdcard_system.img of=/dev/sdb7 bs=1M
sudo fsck.vfat -a /dev/sdb7
sudo dd if=./sdcard_settings.img of=/dev/sdb3 bs=1M
sudo e2fsck -f /dev/sdb3
sudo resize2fs /dev/sdb3

Step 3 – Important Edits (NOOBS)

At this point, we’ve relocated the partitions but have yet to update the references to these new partitions. Now comes the crucial stage where must make these changes, and there are quite a few.

Settings Partition

The first edit we need to make is in the SETTINGS partition, which in my case is /dev/sdb3. Let’s mount that partition and make the following change in the file installed_os.json.

sudo mkdir /tmp/settings
sudo mount /dev/sdb3 /tmp/settings
sudo nano /tmp/settings/installed_os.json

If you did not follow Step 2 (i.e.: did not move the boot partitions to a smaller SD card) then make these edits.

[
 {
 "description" : "A Debian wheezy port, optimised for the Raspberry Pi",
 "folder" : "/mnt/os/Raspbian",
 "icon" : "/mnt/os/Raspbian/Raspbian.png",
 "name" : "Raspbian",
 "partitions" : [
  "/dev/mmcblk0p5",
  "/dev/sda1"
 ],
 "release_date" : "2015-02-16"
 },
 {
 "description" : "Retropie 2.6 img install",
 "folder" : "/mnt/os/Retropie",
 "icon" : "/mnt/os/Retropie/Retropie.png",
 "name" : "Retropie",
 "partitions" : [
  "/dev/mmcblk0p7",
  "/dev/sda2"
 ],
 "release_date" : "2015-02-16"
 },
 {
 "description" : "OpenELEC is a fast and userfriendly Kodi Entertainment Center distribution.",
 "folder" : "/settings/os/OpenELEC_Pi2",
 "icon" : "/settings/os/OpenELEC_Pi2/icon.png",
 "name" : "OpenELEC_Pi2",
 "partitions" : [
  "/dev/mmcblk0p9",
  "/dev/sda3"
 ],
 "release_date" : "2015-02-09"
 }
]

If on the other hand, you followed Step 2, proceed with these changes.

[
 {
 "description" : "A Debian wheezy port, optimised for the Raspberry Pi",
 "folder" : "/mnt/os/Raspbian",
 "icon" : "/mnt/os/Raspbian/Raspbian.png",
 "name" : "Raspbian",
 "partitions" : [
  "/dev/mmcblk0p5",
  "/dev/sda1"
 ],
 "release_date" : "2015-02-16"
 },
 {
 "description" : "Retropie 2.6 img install",
 "folder" : "/mnt/os/Retropie",
 "icon" : "/mnt/os/Retropie/Retropie.png",
 "name" : "Retropie",
 "partitions" : [
  "/dev/mmcblk0p6",
  "/dev/sda2"
 ],
 "release_date" : "2015-02-16"
 },
 {
 "description" : "OpenELEC is a fast and userfriendly Kodi Entertainment Center distribution.",
 "folder" : "/settings/os/OpenELEC_Pi2",
 "icon" : "/settings/os/OpenELEC_Pi2/icon.png",
 "name" : "OpenELEC_Pi2",
 "partitions" : [
  "/dev/mmcblk0p7",
  "/dev/sda3"
 ],
 "release_date" : "2015-02-09"
 }
]

What we did was simply inform NOOBS where the new boot / root partitions are. The USB key referenced as /dev/sdc in Step 1, will be /dev/sda as far as NOOBS is concerned. Unmount the settings partition now.

sudo umount /tmp/settings

Raspbian Boot and Root Partition

All right, now on to the OSes. For each OS we will need to modify both the os_config.json and cmdline.txt files (located in the boot partition) and the /etc/fstab file (located in the root partition). Remember that the boot partition is on the SD card as /dev/mmcblk0p5 and root with be on /dev/sda1 (as for as the Raspberry Pi is concerned). Mount the boot partition.

sudo mkdir /tmp/boot
sudo mount /dev/sdb5 /tmp/boot
sudo nano /tmp/boot/os_config.json

Make the edit.

{
 "description" : "A Debian wheezy port, optimised for the Raspberry Pi",
 "flavour" : "Raspbian",
 "imagefolder" : "/mnt/os/Raspbian",
 "keyboard" : "us",
 "language" : "us",
 "partitions" : [
"/dev/mmcblk0p5",
"/dev/sda1"
 ],
 "release_date" : "2015-02-16",
 "videomode" : 0
}

Now modify the cmdline.txt file.

sudo nano /tmp/boot/cmdline.txt

Make the edit.

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

Now on to the root partition.

sudo umount /tmp/boot
sudo mkdir /tmp/root
sudo mount /dev/sdc1 /tmp/root
sudo nano /tmp/root/etc/fstab

This is the edit we will need to make.

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p5  /boot           vfat    defaults          0       2
#/dev/mmcblk0p6  /               ext4    defaults,noatime  0       1
/dev/sda1  /               ext4    defaults,noatime  0       1

As you see, I have simply commented the line with a hash (instead of deleting it), copied it and made the edit. Un-mount the partition and we are done for this OS.

sudo umount /tmp/root

RetroPie Boot and Root Partition

Let’s now repeat the process for the RetroPie OS. Keep it mind that the changes may differ if you’ve followed Step 2. The boot partition will be /dev/sdb6 if you followed Step 2 or /dev/sdb7 otherwise.

sudo mount /dev/sdb7 /tmp/boot
sudo nano /tmp/boot/os_config.json

Followed Step 2?

sudo mount /dev/sdb6 /tmp/boot
sudo nano /tmp/boot/os_config.json

Make the change.

{
 "description" : "Retropie 2.6 image install",
 "flavour" : "Retropie",
 "imagefolder" : "/mnt/os/Retropie",
 "keyboard" : "us",
 "language" : "us",
 "partitions" : [
"/dev/mmcblk0p7",
"/dev/sda2"
 ],
 "release_date" : "2015-02-16",
 "videomode" : 0
}

Followed Step 2?

{
 "description" : "Retropie 2.6 image install",
 "flavour" : "Retropie",
 "imagefolder" : "/mnt/os/Retropie",
 "keyboard" : "us",
 "language" : "us",
 "partitions" : [
"/dev/mmcblk0p6",
"/dev/sda2"
 ],
 "release_date" : "2015-02-16",
 "videomode" : 0
}

Let’s now modify the cmdline.txt file.

sudo nano /tmp/boot/cmdline.txt

Modify the root= portion.

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

Now on to the root partition.

sudo umount /tmp/boot
sudo mount /dev/sdc2 /tmp/root
sudo nano /tmp/root/etc/fstab

Edit the /etc/fstab as per below.

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p7  /boot           vfat    defaults          0       2
/dev/sda2  /               ext4    defaults,noatime  0       1

Followed Step 2?

proc            /proc           proc    defaults          0       0
/dev/mmcblk0p6  /boot           vfat    defaults          0       2
/dev/sda2  /               ext4    defaults,noatime  0       1

Done with this OS, un-mount and on to the last one!

sudo umount /tmp/root

OpenELEC Boot and Root Partition

We’re at the last OS now and we won’t have to make the root modification in this case.

sudo mount /dev/sdb9 /tmp/boot
sudo nano /tmp/boot/os_config.json

Followed Step 2?

sudo mount /dev/sdb7 /tmp/boot
sudo nano /tmp/boot/os_config.json
{
 "description" : "OpenELEC is a fast and userfriendly Kodi Entertainment Center distribution.",
 "flavour" : "OpenELEC_Pi2",
 "imagefolder" : "/settings/os/OpenELEC_Pi2",
 "keyboard" : "us",
 "language" : "us",
 "partitions" : [
"/dev/mmcblk0p9",
"/dev/sda3"
 ],
 "release_date" : "2015-02-09",
 "videomode" : 0
}

Followed Step 2?

{
 "description" : "OpenELEC is a fast and userfriendly Kodi Entertainment Center distribution.",
 "flavour" : "OpenELEC_Pi2",
 "imagefolder" : "/settings/os/OpenELEC_Pi2",
 "keyboard" : "us",
 "language" : "us",
 "partitions" : [
"/dev/mmcblk0p7",
"/dev/sda3"
 ],
 "release_date" : "2015-02-09",
 "videomode" : 0
}

Now here is where things differ slightly. OpenELEC will have UUID’s in place of devices in the cmdline.txt file. At this point ensure that the UUID’s are correct for your case. You can get the UUID’s by simpy running the following command.

sudo blkid

In the file below, the value after boot=UUID= should be the UUID for /dev/sdb9 or /dev/sdb7 if you followed Step 2. The value for disk=UUID= (or OpenELEC’s SYSTEM partition) will be the UUID for/dev/sdc (the USB’s third partition).

sudo nano /tmp/boot/cmdline.txt
boot=UUID=5C57-7A04 disk=UUID=3bc3d58e-d60b-41d3-9e29-99643a507430 quiet

Finally done! Wow, the was longer than I expected. So the moment of truth awaits! At this point, it might be a good idea to see if the system boots all three OSes as expected. If so, consider it a great accomplishment!

Part 3 of this blog series will demonstrate how I use a script to be able to reboot into any OS. Catch you there!


Leave a comment

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

6 thoughts on “Triple Boot Raspberry Pi on USB (Raspbian / RetroPie / OpenELEC) – Part 2

    • bobby Post author

      Hi,

      Sorry for the late reply.
      Generally, that’s not a good thing. You should be able to get a more detailed message to further troubleshoot.

  • Nachriht

    Hi, on step1 I got :
    dd: error reading ‘/dev/sdc7’ : Input output error
    anyway copyed from 13 Mb to 180Mb.. source partition 9.95 on sdhc 32Gb destination parition 9.98 GB / usable 9.68? on 32Gb sandisc.

  • Malte

    This whole tutorial ist just awesome!
    It’s exactly what I’ve been trying to finally get away from the ever corrupting sd cards. I followed you’r steps (with some minor modifications) and now got a neatly media center retro console at the same time.
    One remark though. What do you think of the statement regarding using device names for usb boot here? http://openelec.tv/forum/124-raspberry-pi/67688-raspberry-pi-usb-boot-storage-the-right-way
    I think it’s quite convincing and hence adjusted the boot settings to use labels instead – works for all the OSes above including Openelec.
    Curious for your opinion about that.
    Best regards
    Malte

    • bobby Post author

      Hi Malte,
      Thanks for your kind words, I’m glad your enjoyed the post! In regards to Labels, I think they are a great way to go and see no disadvantage save for the rare instance where you have duplicate labels. Good suggestion!
      Thanks for stopping by!