-
Notifications
You must be signed in to change notification settings - Fork 125
How to Create a Multi Boot SD card out of 2 existing OSes using PINN
These instructions explain how to create a multi-boot SD card for the Raspberry Pi that will enable you to select which OS will be used on boot. The 2 OSes are ones that you have previously installed to 2 separate SD cards and customised to an extent that you don't want to lose those customisations.
These instructions can be used to multi-boot more than 2 OSes, or different OSes than the example ones given here. Just adapt the instructions as necessary.
- 2 existing uSD cards containing 2 OSes (e.g. Raspbian and Retropie)
- 1 blank uSD card large enough to hold both OSes as a multi-boot SD card
- 1 USB memory stick (or uSD card with USB card reader)
- a USB uSD card reader
- a PC running a version of desktop Linux (Ubuntu assumed)
The overall process that I will cover will have the following general outline. Each step will be documented along the way.
- Backup the existing OSes
- Make the backups suitable for installation by PINN
- Make a PINN bootable uSD card
- Use PINN to install the OS backups to the multi-boot card.
The SD cards containing the existing customised OSes need to be backed up in a particluar way in order for PINN to install them. PINN prefers a backup file per partition, which could be a compressed image file, or a compressed tar file.
An image file is a bit-by-bit backup of the whole of a partition, including any unused space, so it can be a lot bigger than is necessary. Compressing the image afterwards can remove a lot of this unused space to make the file smaller, but it nevertheless requires an SD card at least as big as the original partition size to restore the files to. To avoid this, a common practice is to first resize the partition and its file system to be as small as possible before taking the image. In this way, less of the unused space is recorded in the iage file and it can be restored to a smaller SD card. However, it also requires that after restoration, the file system should be expanded to fill the remaining space of the partition, otherwise it will not be possible to add much more data or install anymore programs to the partition. Because of these complications of first reducing and then expanding the file systems, this method will not be considered here.
An alternative approach is to create an archive of the files on each partition as a tar file and then compress it. Using this method, only the existing files will be backed up, and not any empty space, so it should be smaller than a corresponding image file. On restoration, the tar files can be decompressed to a preformatted partition of any size at least as large as the files themselves. No file system expansion would be necessary because the partition would have already been formatted to its full capacity.
First we will backup the Raspbian OS.
We will start on our PC and fire up Linux. We will be doing a lot of this procedure by the command line, so if you have booted into a desktop environment, launch your normal terminal program (Terminal, LXTerminal or similar). This should drop you into your home directory (/home/<username> or just '~' for short)
- Create a folder called
os/raspbian
in your home folder to store your backup in.
$ mkdir -p ~/os/raspbian - Insert your uSD card that has your customised Raspbian OS on it into the USB reader and insert it into a free USB slot of the PC. You need to note what device Linux has assigned it (e.g.
/dev/sdb
) and where it has been mounted (e.g./media/<username>/boot
or/root
etc).
Some Linux OSes may automount the partitions on this SD card, so in this case you can typemount
to identify the device and where it's partitions have been mounted and skip the next step. For this tutorial, we will assume the SD card is referenced as /dev/sdb with /dev/sdb1 mounted at/media/<username>/boot
and /dev/sdb2 mounted at/media/<username>/root
. If yours is mounted at a different location, please replace appropriately in the following steps. - If it has not been auto-mounted, you will need to manually mount the partitions on the device.
$ dmesg
Look for the recent logs at the end of the dmesg output to identify the name of the most recently added device. You then need to create a mountpoint for each partition on the device. We will assume the device has been assigned/dev/sdb
and has 2 partitions (/dev/sdb1
and/dev/sdb2
) named boot and root
$ sudo mkdir /media/<username>/boot
$ sudo mkdir /media/<username>/root
$ sudo mount /dev/sdb1 /media/<username>/boot
$ sudo mount /dev/sdb2 /media/<username>/root - Now we will take a copy of our SD card and store it in 2 archive files.
$ cd /media/<username>/boot
$ sudo bsdtar --numeric-owner --format gnutar -cpvf ~/os/raspbian/boot.tar . $ cd /media/<username>/root
$ sudo bsdtar --numeric-owner --format gnutar --one-file-system -cpf ~/os/raspbian/root.tar . $ tar cvpf ~/os/raspbian/root.tar . --exclude=./proc/* --exclude=./sys/* --exclude=./dev/pts/*
$ cd ~/os/raspbian
$ xz -9 -e boot.tar
$ xz -9 -e root.tar
You should now have 2 files in~/os/raspbian
calledboot.tar.xz
androot.tar.xz
- We need to make a note of how much space the OS takes up.
$ sudo du -BK -s /media/<username>boot | cut -d"K" -f1 >boot.size $ sudo du -BK -s /media/<username>root | cut -d"K" -f1 >root.size - Finally we will unmount the Raspbian OS SD card
$ umount /media/<username>boot
$ umount /media/<username>root
and then you may eject and remove the Raspbian OS SD card.
Now we will backup the other OS of Retropie, which is just a repeat of the operation to backup our Raspbian OS.
- Create a folder called
os/Retropie2
in your home folder to store your backup in.
$ mkdir -p ~/os/Retropie2 - Insert your uSD card that has your customised Retropie OS on it into the USB reader and insert it into a free USB slot of the PC. You need to note what device Linux has assigned it (e.g.
/dev/sdb
) and where it has been mounted (e.g./media/<username>/boot
or/root
etc). Some Linux OSes may automount the partitions on this SD card, so in this case you can typemount
to identify the device and where it's partitions have been mounted and skip the next step. For this tutorial, we will assume the SD card is referenced as /dev/sdb with /dev/sdb1 mounted at/media/<username>/boot
and /dev/sdb2 mounted at/media/<username>/root
. If yours is mounted at a different location, please replace appropriately in the following steps. - If it has not been auto-mounted, you will need to manually mount the partitions on the device.
$ dmesg
Look for the recent logs at the end of the dmesg output to identify the name of the most recently added device. You then need to create a mountpoint for each partition on the device. We will assume the device has been assigned/dev/sdb
and has 2 partitions (/dev/sdb1
and/dev/sdb2
) named boot and root
(we will assume the/media/<username>/boot
and/media/<username>/root
folders still exist from backing up Raspbian)
$ sudo mount /dev/sdb1 /media/<username>/boot
$ sudo mount /dev/sdb2 /media/<username>/root - Now we will take a copy of our SD card and store it in 2 archive files.
$ cd /media/<username>/boot
$ sudo bsdtar --numeric-owner --format gnutar -cpvf ~/os/Retropie2/boot.tar . $ cd /media/<username>/root
$ sudo bsdtar --numeric-owner --format gnutar --one-file-system -cpf ~/os/Retropie2/root.tar . $ cd ~/os/Retropie2
$ xz -9 -e boot.tar
$ xz -9 -e root.tar
You should now have 2 files in~/os/Retropie2
calledboot.tar.xz
androot.tar.xz
- We need to make a note of how much space the OS takes up.
$ sudo du -BK -s /media/<username>boot | cut -d"K" -f1 >boot.size $ sudo du -BK -s /media/<username>root | cut -d"K" -f1 >root.size - Finally we will unmount the retropie OS SD card
$ umount /media/<username>boot
$ umount /media/<username>root
and then you may eject and remove the retropie OS SD card.
Now we need to add some meta data files that describe these OSes to PINN so it knows how to install them. We shall download some existing meta files for these OSes and then adapt them if necessary.
First, Raspbian:
$ cd ~/os/raspbian
$ wget -N "http://downloads.raspberrypi.org/raspbian/os.json"
$ wget -N "http://downloads.raspberrypi.org/raspbian/Raspbian.png"
$ wget -N "http://downloads.raspberrypi.org/raspbian/partitions.json"
$ wget -N "http://downloads.raspberrypi.org/raspbian/marketing.tar"
$ wget -N "http://downloads.raspberrypi.org/raspbian/partition_setup.sh"
Then Retropie:
$ cd ~/os/Retropie2
$ wget -N "http://downloads.sourceforge.net/project/pinn/os/Retropie2/os.json"
$ wget -N "http://downloads.sourceforge.net/project/pinn/os/Retropie2/partitions.json"
$ wget -N "http://downloads.sourceforge.net/project/pinn/os/Retropie2/Retropie2.png"
$ wget -N "http://downloads.sourceforge.net/project/pinn/os/Retropie2/marketing.tar"
$ wget -N "http://downloads.sourceforge.net/project/pinn/os/Retropie2/partition_setup.sh"