This is the story of how ODROID-N2 user can install two different OS images to one eMMC rather than swapping the two eMMC memory cards installed two different OS, or having one OS on eMMC and another one on uSD.
I’ve published a story about Petitboot which can manage the multiple OS installed in the memory card on ODROID-N2. “Link”
The legacy way of using OS contributed and built by an open source community is that downloading the image file from a server and flashing it to a memory card, uSD or eMMC, in a USB stick attached to PC. Some SBC vendor provide a tool or Linux expert uses a command line tool “dd”, recently thankfully very convenient tool is developed “Etcher”. So SBC users become to flash the image more easily.
The small problem here is that usually their OS image is built in an assumption that an OS will be running in a single memory card no matter what’s the memory card size is. After flashing the memory card with an OS image, the rest of the storage will be occupied to the OS while installing by the procedure a.k.a “Partition resizing”. So in general, one memory card can have one OS and the whole memory card is fully occupied to it unless the user does some workaround.
In the SBC world, there are two popular memory card types, uSD and eMMC. Two of them are easily compared with two factors, “Price” vs “Performance”. The uSD is very popular and can be purchased in an electronic store while eMMC is an electronic part that is usually mounted to the electronic device like a mobile phone in the factory. In terms of the price, uSD is cheaper than eMMC but performance wise, eMMC is way faster than uSD but more expensive. Therefore many people prefer to use eMMC if they have a budget.
The aim of the instruction below is to install two different OS images into a single eMMC memory card which is faster than uSD and boot one of them to run in a faster environment.
We could consist of a couple of options to achieve this.
- Purchase larger eMMC module to install two OS images. Most of Linux based OS image requires an 8GB memory card, so by the simple calculation, 16GB memory card would be required. This is only for the OS installation and maintenance, you would have an option to purchase a memory card larger than 16GB like 32GB or 64GB as much as your budget permits.
- uSD card can be used to store data that is usually not required high-performance IO traffics and if you are able to use two OS on eMMC, each OS can access the uSD as well.
Preparing to build the Dual OS image
In order to build the dual OS image, you require two different OS images and each OS image usually downloaded from a server of the OS distributors. The example in this story will explain with the Ubuntu Mate 18.04.2 Desktop image and CoreELEC nightly image.
Ubuntu Desktop Mate 18.04.2:
CoreELEC Nightly image:
Also, I wrote a script in order to go through complicated instruction and it can be downloaded from the link.
Setting a script
Before we start, we have to modify the script in order to let the script which OS images should be composed and how is their layout, also where the image should be flashed.
Firstly, you have to download the OS images from the server. In the example in this story, I will explain with the Ubuntu 18.04 Mate Desktop image and CoreELEC image.
Secondly, the image files must be specified in the script. The symbol “image1” is for the first OS installing to the lower sectors and “image2” is the second one after the first image.
Thirdly, it is necessary to set how much space will be occupied by the first OS in percentage. If 80% is given as a rate, then the rest 20% will be occupied by the second OS. Any rate can be given, but it would be better to estimate how much of minimal space is required for each OS.
Finally, you must give a device name of your USB storage attached to PC. In order to prevent to destroy your disk drive by accident using the device node name, I recommend using another form of device node that uses “by-id”.
Building OS image with the script
We’ve set the necessary parameters in the script and it will compose the OS images to the memory card attached using USB stick. Since some OS image is very large like a few GBytes and the script will flash the whole image, it would take some time and time would vary on the performance of PC and USB bus. Everything is clearly set in the script, it will keep flashing the image and at the end, you will be able to see 4 partitions mounted from USB stick.
Partition layout of Ubuntu Mate image:
As shown in the screen shown below, Ubuntu Mate image has consisted of two partitions with different sizes 128MB and 6GB, their location is specified in the partition table as well 2048 and 264192 respectively. Since Ubuntu Mate is selected as a first OS, the image will be stored into the same location.
Partition layout of CoreELEC image:
This image also has two partitions with different size 512MB and 32MB. Since this image must be after Ubuntu Mate image, their partitions will be pushed to right after the Ubuntu image. The percentage of allowed space for Ubuntu image is 80% which is set previously in the script.
After composing of two OS images:
After running the script with given factors, image names and layout percentage for the first OS, the new OS image is created and flashed to the memory card directly. The reason why the new OS image is flashed to the memory card is that the 2nd OS will be located very after the 1st OS, it would be a huge amount in bytes and this consumes unnecessary disk space of your PC although it will be removed right after the image is flashed. For the explanation, I used a 128GB eMMC and this is relatively huge only to save the new dual-OS image.
By some calculation with the given value, the script does a calculation where the 2nd OS is to be installed and the script just copies the image to the right position without changing the size of each partition of the 2nd OS. The amount of the sectors and size of each partition are the same as the original image.
These 4 partitions are able to be mounted on PC without any issue since they were copied from the original OS image, two of them (BOOT/rootfs) are from Ubuntu Mate and the rest two (COREELEC/STORAGE) are from CoreELEC image.
Booting the new OS image on ODROID-N2
The booting the new OS image is very easy, it’s the same as attaching the memory card to an SBC. But for multibooting, you require to flip the boot select switch to “SPI” that gives a boot priority to SPI flash memory than eMMC such that SPI flash memory boots up the Petitiboot and let Petitboot display the two OS entries in the eMMC.
Here is the screen booted from the image compose with two OS images, it would not be easy to indicate what is different from the installed image on eMMC and uSD. It’s fair simple, since the first OS “NOLABEL” indicate that it’s device is “mmcblk0p1” which is the first partition of eMMC while the 2nd OS “CoreELEC” indicates “mmcblk0p3” which is the third partition of eMMC. The eMMC device is noted as “mmcblk0*” while uSD is “mmcblk1”.
Once you have reached this screen on Petitboot, you are not able to boot to any of them on eMMC and offer you the fast performance as much as eMMC support which is faster than uSD.
Before you really compose the images!!
There is a couple of things you notice to proceed with the instructions above in order to create the dual OS image, these are the technical limitation currently.
- Android image from Hardkernel cannot be composed with. This is because of the Android image store the image files in raw sectors rather than file system due to its original development behavior. The current dual-OS script is not supposed to compose the Android image.
- The booting would be failed if two OS images share the same UUID for their root file system. Many Linux OS uses the UUID of the file system to indicate which file system should be mounted as a root file system and this brings the failure to look up the wrong partition and mount to use its root file system. I’ve observed this from Ubuntu Mate 18.04.2 and Debian Stretch. Both images can be composed but would mount the wrong root file system.
- Some OS image would be not be booted if it uses a device node instead of UUID. Since while composing the images, the partitions of 2nd OS are moved to another and their partition number is also changed. So if there are is an entry that uses like “/dev/mmcblk0p2” or “/dev/mmcblk1p2” instead of “UUID=19238….” then it will be failed. This can be solved if the original OS image is rebuilt.
I would be grateful if someone tries out this and shares the experience of how it goes and I would welcome any suggestion or question regarding to build the dual-OS image.
Thank you for reading and have fun with ODROID.