There are a lot of single-board computers in the market; the most famous ones are Raspberry Pi series. There are more powerful alternatives like Odroid N2+ that I'm going to explain how to prepare two Operating Systems for it. I mainly focus on partitioning the storage unit using parted
command line. You can use GParted
which is a front-end for it.
Odroid series are developed by South Korean company named HardKernel. Odroid N2+ price is close to Raspberry Pi 4 but it's more powerful. You can watch 4K HDR movies smoothly. It's based on Amlogic S922X SoC (System on a chip) that contains Quad-core Cortex-A73 and Dual-core Cortex-A53 CPUs and Mali-G52 GPU. For more information about the specification you can refer to this page.
You can use it as a media center by installing Kodi or your personal NAS or your personal server. Since it doesn't require a fan for cooling it's very quiet.
You can directly order it through HardKernel website. If you don't live in South Korea, it's better to order it from one of the official distributors. I recommend you also purchase an eMMC storage instead of a slower storage like MicroSD. I should mention you must purchase case, power cable and other components separately.
You don't need to purchase eMMC reader. We can use N2 device to write OS image into it. You can follow the instructions on this link to install eMMC module. Please ignore other suggestions like buying eMMC reader.
As you can see Odroid N2+ is a recommended device for playing 4K HDR movies in Kodi's forum. We are going to install two operating systems on N2:
I also tried Android. The problem was the absence of Netflix on Google Play Store. It seems it is supported on a special type of Android. If you are interested in Netflix on Android, you can follow this tutorial. I don't think it supports 4K videos. Another option is to install Netflix addon on CoreELEC.
Warning: Please understand that the following commands can erase your data. You shouldn't copy them without understanding them. It's likely that you need to modify them. I assumed you're comfortable with Linux.
I was inspired by this post. My method here is a bit different and we have more control over partitioning.
First we need to put N2 on SPI mode (the image is copied from Odroid Wiki):
The boot sequence between MMC and SPI is different; for more information you can read this wiki page.
Since we don't have eMMC reader, we should follow this tutorial so we can see eMMC as a USB Mass Storage. It's very important when you are in Petitboot, you select "exit to shell", then run the following command to update it:
# pb-update
You may need to restart it. Please follow the tutorial but don't flash the OS image. After running ums /dev/mmcblk0
command in Petitboot, you should see it as a USB storage. Let's assume it's /dev/sda
. It's likely it's different for you. So please confirm it. I assumed you are running a Linux OS. If you don't, this is not the tutorial you're looking for!
First we are going to install CoreELEC. You can find the image from this link. We are going to Flash eMMC using dd command. As I mentioned before, running it can destroy your data. So first confirm that you are using the correct destination device. For more information about dd
command, you can read this wiki page.
$ sudo dd if=CoreELEC-Amlogic-ng.arm-19.3-Matrix-Odroid_N2.img of=/dev/sda bs=1M status=progress
After running this command, we should have two partitions. We can confirm it by:
$ sudo parted /dev/sda unit MiB print
Model: Linux File-Stor Gadget (scsi)
Disk /dev/sda: 29820MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 4.00MiB 516MiB 512MiB primary fat16 boot, lba
2 516MiB 548MiB 32.0MiB primary ext4
As you can see partition table is MBR (i.e. msdos). So we cannot have more than 4 primary partitions. We can have 3 primary partitions and one extended partition in which we can define many logical partitions. For more information about partition tables refer to this link.
Note that for installing Ubuntu we cannot follow the same approach as we did for CoreELEC. Because Ubuntu image like CoreELEC has the same structure:
+--+---------------+----------------+
|PT| Partition 1 | Partition 2 |
+--+---------------+----------------+
0 start end
Each disk should have one partition table and it occupies the first sectors. When copying Ubuntu image, we want to copy everything besides the first sectors that contain partition table. We want to have something like this:
+--+---------------+----------------+---------------+---------------+
|PT| Partition 1 | Partition 2 | Partition 3 | Partition 4 |
+--+---------------+----------------+---------------+---------------+
0 start end
We created PT
, Partition 1
and Partition 2
by copying CoreELEC image using dd
command. Now we want to have two more partitions for Ubuntu image. Since in future we may install other OSs, Instead of primary partitions, we are going to create a logical one. Before doing that, restart the device manually or by using the following command:
# reboot -f
CoreELEC try to resize Partition 2
to take the entire disk. We deal with it later.
As I mentioned before CoreELEC took the entire disk. We need to shrink partition 2. The entire size of my eMMC is 29820 MiB. Note that I'm using binary units. So 1KB = 1024B
. I prefer it because parted
will not modify the locations. For more information read the official manual. Note taht the default units for parted
are KB
, MB
and so on. In other words 1KB = 1000B
.
I want to allocate 26% of eMMC to partition 2. I'm using bc for calculation. If you are not familiar with it you can read about it here.
echo "0.26 * 29820 / 1024" | bc -l
7.57148437500000000000
So the size of second partition should be around 7.57GB.
File system size shouldn't exceed the partition. So if we want to expand partition, first we resize the partition and then the file system. When we are shrinking, first we resize the file system and then the partition
So we play safe and resize the file system to 7GB:
$ sudo resize2fs /dev/sda2 7G
resize2fs 1.45.6 (20-Mar-2020)
Resizing the filesystem on /dev/sda2 to 7340032 (1k) blocks.
The filesystem on /dev/sda2 is now 7340032 (1k) blocks long.
Now we are going to shrink the second partition so it takes 26% of eMMC:
sudo parted /dev/sda resizepart 2 26%
We asked parted to resize the second partition to 26% of eMMC. For performance reason, it's always a good idea the partitions are aligned. Usually parted warn us if we want to do an operation which is not aligned. We can confirm the alignment of second partition by:
sudo parted /dev/sda align-check optimal 2
2 aligned
Now we can expand the file system to the entire partition by not specifying the size:
resize2fs /dev/sda2
resize2fs 1.45.6 (20-Mar-2020)
Resizing the filesystem on /dev/sda2 to 7410892 (1k) blocks.
The filesystem on /dev/sda2 is now 7410892 (1k) blocks long.
Now we are good to install Ubuntu.
We are using a loop device to mount Ubuntu image file:
$ sudo udisksctl loop-setup -r -f ubuntu-20.04-4.9-mate-odroid-n2-20210830.img
Mapped file ubuntu-20.04-4.9-mate-odroid-n2-20210830.img as /dev/loop11.
As you can see for me it's mounted as /dev/loop11
. Let's look at it:
$ sudo parted /dev/loop11 unit MiB print
Model: Loopback device (loopback)
Disk /dev/loop11: 7136MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1.00MiB 129MiB 128MiB primary fat16 lba
2 129MiB 7136MiB 7007MiB primary ext4
So we need to have two partitions for Ubuntu: one with the size of 128MiB and the other 7007MiB. Since we need to deal with alignment, we are using sector as a unit. A disk sector is the minimum storage unit of hard drive. As a reminder I copied the following image from Wikipedia that shows a disk sector (C):
loop11
partitions with sector as our unit:
$ sudo parted /dev/loop11 unit s print
Model: Loopback device (loopback)
Disk /dev/loop11: 14614528s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 2048s 264191s 262144s primary fat16 lba
2 264192s 14614527s 14350336s primary ext4
As you can see here 1 sector = 512B
in my eMMC module. Let's convert the size of first partition of loop device from sector to MiB:
$ echo "(262144 * 512) / 2^20" | bc -l
128.00000000000000000000
as expected it's equivalent to 128MiB. So let's create our partitions in interactive mode. As I mentioned before first we create an extended partition in which we create two logical partitions for Ubuntu. Before that first take a look at our eMMC's partitions in sector:
sudo parted /dev/sda unit s print
Model: Linux File-Stor Gadget (scsi)
Disk /dev/sda: 61071360s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 8192s 1056767s 1048576s primary fat16 boot, lba
2 1056768s 15878553s 14821786s primary ext4
So let's try to create an extended partition on sector 15878554
(one sector after the partition 2):
$ sudo parted /dev/sda
(parted) unit s
(parted) mkpart extended 15878554s 100%
Warning: The resulting partition is not properly aligned for best performance: 15878554s % 2048s != 0s
Ignore/Cancel?
As you can see parted expected that every partition starts with a sector that is multiple of 2048s
(1MiB
). Partition alignment is important for SSD drives to avoid excessive read-modify-write cycles which leads to longer lifespan. Basically 1MiB alignment covers all common SSD page and block size scenarios because it's divisible by all commonly used sizes: 1MiB, 512KiB, 128KB, 4KiB and 512B. For more information read this section of SSD drivers and partition alignment.
Let's find a suitable one:
echo "15878554 % 2048" | bc
410
echo "15878554 - 410 + 2048" | bc
15880192
So we need to use sector 15880192
, instead of 15878554
. Now the partitions are look like this. Note that the extend partition starts from sector 15880192
to the last sector of the disk which is 61071359
.
Number Start End Size Type File system Flags
1 8192s 1056767s 1048576s primary fat16 boot, lba
2 1056768s 15878553s 14821786s primary ext4
3 15880192s 61071359s 45191168s extended lba
Now we need to create the first partition for Ubuntu. It should start from:
$ echo "15880192 + 2048" | bc
15882240
We have the starting sector and we know the size of partition should be 262144s
. We use the following formula to calculate the end sector:
end = start + size - 1
So we have:
$ echo "15882240 + 262144 - 1" | bc
16144383
The first partition for Ubuntu:
(parted) mkpart logical fat16 15882240s 16144383s
The partitions look like this:
Number Start End Size Type File system Flags
1 8192s 1056767s 1048576s primary fat16 boot, lba
2 1056768s 15878553s 14821786s primary ext4
3 15880192s 61071359s 45191168s extended lba
5 15882240s 16144383s 262144s logical lba
The second partition of Ubuntu should start from sector 16146432s
instead of 16144384
because it should be a multiple of 2048
:
(parted) mkpart logical ext4 16146432s 100%
Now we have all required partitions. We need to copy Ubuntu partitions
The first partition is a fat16
. We are using GParted to clone it:
gparted /dev/loop11 /dev/sda
Copy the first partition of loop11
into partition 5 of sda
. For the second partition you can use GParted or e2image
:
e2image -ra -p /dev/loop11p2 /dev/sda6
e2image
doesn't support FAT
file system so we used GParted to clone it. There are other tools for disk cloning. You can read about them here.
Now you can turn off N2 device and enjoy two amazing operating systems!