The source code for this blog is available on GitHub.

Blog.

Odroid M1S bootable microsd on ubuntu command line

Cover Image for Odroid M1S bootable microsd on ubuntu command line
Od Simple
Od Simple

I'm trying to create Odroid M1S bootable image on a microsd card.

  • Insert microsd card to my Odroid M1S microsd slot.

  • Download an OS image from odroid.com

mkdir install
cd install
wget https://dn.odroid.com/RK3566/ODROID-M1S/Ubuntu/ubuntu-20.04-npu-odroidm1s-20231226.img.xz

--2024-12-24 16:49:53--  https://dn.odroid.com/RK3566/ODROID-M1S/Ubuntu/ubuntu-20.04-npu-odroidm1s-20231226.img.xz
Resolving dn.odroid.com (dn.odroid.com)... 211.233.81.212
Connecting to dn.odroid.com (dn.odroid.com)|211.233.81.212|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3401937460 (3.2G) [application/x-xz]
Saving to: ‘ubuntu-20.04-npu-odroidm1s-20231226.img.xz’

ubuntu-20.04-npu-odroidm1s-20231226 100%[=================================================================>]   3.17G  11.4MB/s    in 4m 47s

2024-12-24 16:54:40 (11.3 MB/s) - ‘ubuntu-20.04-npu-odroidm1s-20231226.img.xz’ saved [3401937460/3401937460]

Image download completed.

  • Identify microsd.
lsblk

NAME         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
mmcblk0      179:0    0  58.3G  0 disk
├─mmcblk0p1  179:1    0   256M  0 part /boot
└─mmcblk0p2  179:2    0    58G  0 part /
mmcblk0boot0 179:32   0     4M  1 disk
mmcblk0boot1 179:64   0     4M  1 disk
mmcblk1      179:96   0 119.1G  0 disk
└─mmcblk1p1  179:97   0 119.1G  0 part

The identified microsd is 'mmcblk1'.

  • Unmount microsd card, if mounted. Mine is not mounted.
sudo umount /dev/emmcblk1*

[sudo] password for odroid:
umount: /dev/emmcblk1*: no mount point specified.
  • Unpack downloaded image.
xz -d ubuntu-20.04-npu-odroidm1s-20231226.img.xz
  • **Write the Image ** which I got before.
sudo dd if=ubuntu-20.04-npu-odroidm1s-20231226.img of=/dev/emmcblk1 bs=4M status=progress

[sudo] password for odroid:
3917479936 bytes (3.9 GB, 3.6 GiB) copied, 26 s, 151 MB/s
dd: error writing '/dev/emmcblk1': No space left on device
956+0 records in
955+0 records out
4005953536 bytes (4.0 GB, 3.7 GiB) copied, 26.6152 s, 151 MB/s

copy completed before half a minute.

  • reboot and check
sudo reboot now

Connection to 172.30.111.198 closed by remote host.
Connection to 172.30.111.198 closed.

ubuntu did not boot from microsd but from old one.

I have to check now. I didn't synced. Even missed error message.

l$ sudo dd if=ubuntu-20.04-npu-odroidm1s-20231226.img of=/dev/emmcblk1 bs=4M status=progress
[sudo] password for odroid:
3917479936 bytes (3.9 GB, 3.6 GiB) copied, 26 s, 151 MB/s
dd: error writing '/dev/emmcblk1': No space left on device
956+0 records in
955+0 records out
4005953536 bytes (4.0 GB, 3.7 GiB) copied, 26.6152 s, 151 MB/s
  • Copy and Check again
sudo dd if=ubuntu-20.04-npu-odroidm1s-20231226.img of=/dev/mmcblk1 bs=4M status=progress

# After writing, run the sync command:
sudo sync

# Verify the partition table again using:
sudo fdisk -l /dev/mmcblk1

Disk /dev/mmcblk1: 119.9 GiB, 127865454592 bytes, 249737216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7e5e4ed6

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk1p1        6144   530431   524288  256M 83 Linux
/dev/mmcblk1p2      530432 19818865 19288434  9.2G 83 Linux

It looks good. Reboot again.

ssh odroid@172.30.111.198

Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.10.0-odroid-arm64 aarch64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
 _   _               _ _                        _
| | | | __ _ _ __ __| | | _____ _ __ _ __   ___| |
| |_| |/ _` | '__/ _` | |/ / _ \ '__| '_ \ / _ \ |
|  _  | (_| | | | (_| |   <  __/ |  | | | |  __/ |
|_| |_|\__,_|_|  \__,_|_|\_\___|_|  |_| |_|\___|_|

  ___  ____  ____   ___ ___ ____        __  __ _ ____
 / _ \|  _ \|  _ \ / _ \_ _|  _ \      |  \/  / / ___|
| | | | | | | |_) | | | | || | | |_____| |\/| | \___ \
| |_| | |_| |  _ <| |_| | || |_| |_____| |  | | |___) |
 \___/|____/|_| \_\\___/___|____/      |_|  |_|_|____/


Welcome to Ubuntu 20.04.6 LTS
Tuesday, 24 December 2024, 05:50:22 PM
Up time:     0 days, 00:06:17
Free memory: 7020720 / 7860920 kB

Success


Let's check onboard disk.

sudo mkdir /mnt/onboard-boot
sudo mkdir /mnt/onboard
sudo mount -t auto /dev/mmcblk0p1 /mnt/onboard-boot
sudo mount -t auto /dev/mmcblk0p2 /mnt/onboard

ls /mnt/onboard
ls /mnt/onboard-boot

All goes well. It looks like microsd is faster than onboard disk.


To mount an old disk located at /dev/mmcblk0, follow these steps:

  1. Create a mount point directory:
sudo mkdir /mnt/onboard-boot
sudo mkdir /mnt/onboard

  1. Determine the filesystem type of the partition you want to mount. You can use the following command:
sudo fdisk -l /dev/mmcblk0
  1. Mount the disk using the mount command. If the filesystem is ext4 (which is common for Linux systems), use:
sudo mount -t ext4 /dev/mmcblk0p1 /mnt/onboard-boot
sudo mount -t ext4 /dev/mmcblk0p2 /mnt/onboard

Replace "ext4" with the appropriate filesystem type if different, and "mmcblk0p1" with the specific partition you want to mount[1][3].

  1. If you're unsure about the filesystem type, you can use the "auto" option to let the system detect it:
sudo mount -t auto /dev/mmcblk0p1 /mnt/onboard-boot
sudo mount -t auto /dev/mmcblk0p2 /mnt/onboard
  1. Once mounted, you can access the contents of the old disk in the /mnt/olddisk directory[1].

  2. When you're done, unmount the disk using:

sudo umount /mnt/onboard
sudo umount /mnt/onboard-boot

Odroid M1S: Creating a Bootable Image and Selecting the Boot Disk

This guide walks you through creating a bootable image for your Odroid M1, verifying it, selecting the boot device, and testing the setup.


1. Writing a Bootable Image

To boot an OS on the Odroid M1, you must write the OS image (.img) to a storage device, such as emmcblk0 (eMMC) or emmcblk1 (microSD). Here are the methods:


A. Using dd (Linux/macOS)

  1. Identify the Target Device:

    Use lsblk to locate the device name (e.g., /dev/emmcblk1 for microSD or /dev/emmcblk0 for eMMC).

  2. Unmount the Device:

    sudo umount /dev/emmcblk1*
    
  3. Write the Image:

    sudo dd if=/path/to/image.img of=/dev/emmcblk1 bs=4M status=progress
    
  4. Flush the Write Cache:

    sync
    

Pros:

  • Fast and reliable.

    Cons:

  • Requires careful selection of the target device to avoid overwriting data.


B. Using Rufus (Windows)

  1. Download Rufus:

    Visit rufus.ie.

  2. Insert the Storage Device:

    Plug in your microSD card or eMMC adapter.

  3. Write the Image:

    • Open Rufus, select the .img file, and the target device.

    • Click START to write the image.

Pros:

  • User-friendly with advanced options for partition schemes.

    Cons:

  • Windows-only.


C. Using Etcher (Cross-Platform)

  1. Download Etcher:

    Visit balena.io/etcher.

  2. Write the Image:

    • Select the .img file and the target storage.

    • Click Flash to write the image. Etcher will validate the write automatically.

Pros:

  • Beginner-friendly and cross-platform.

    Cons:

  • Slower than dd or Rufus.


2. Verifying the Image

After writing the image, verify its integrity to avoid boot issues:

  1. Calculate the Checksum of the Original Image:

    sha256sum /path/to/image.img
    
  2. Verify the Written Device:

    sha256sum /dev/emmcblk1
    
  3. Compare the Results:

    The checksums should match.


3. Selecting the Boot Disk

Once the bootable image is prepared, configure the Odroid M1 to boot from the desired storage device.


A. Hardware Boot Selection (Boot Switch)

  1. Locate the Boot Switch:

    On the Odroid M1 board, find the switch labeled eMMC and microSD.

  2. Set the Switch:

    • eMMC: Select this to boot from emmcblk0.

    • microSD: Select this to boot from emmcblk1.

  3. Reboot the Device:

    The Odroid will boot from the chosen storage.

Pros:

  • Simple and reliable.

    Cons:

  • Requires physical access to the device.


B. Software Boot Selection (U-Boot)

For headless or remote configurations:

  1. Access U-Boot Console:

    Connect via UART or serial console and interrupt the boot process by pressing a key (e.g., Enter).

  2. Set the Boot Device:

    • To boot from eMMC (emmcblk0):

      setenv bootdev emmc
      saveenv
      boot
      
    • To boot from microSD (emmcblk1):

      setenv bootdev sd
      saveenv
      boot
      
  3. Save and Reboot:

    Save changes with saveenv and restart the device.

Pros:

  • Ideal for remote setups.

    Cons:

  • Requires familiarity with U-Boot commands.


C. Modifying Bootloader Files

If the system uses a bootloader like GRUB:

  1. Mount the Boot Partition:

    sudo mount /dev/emmcblk0p1 /mnt
    
  2. Edit the Boot Configuration File:

    Update the root= parameter in files such as /mnt/boot/config.txt or /mnt/boot/grub.cfg to point to the desired device.

  3. Save and Reboot:

    After saving changes, reboot the device.


4. Testing and Troubleshooting

A. Test Boot Order:

  • Remove either the eMMC module or microSD card, reboot, and verify which device is used.

B. Reset Defaults:

If issues occur, revert to the hardware boot switch or reset U-Boot to default settings.

C. Logs:

Check boot logs using a serial console to debug errors.


5. Key Notes and Best Practices

  • Backup Data: Always back up important data before making changes.

  • Check Devices Carefully: Use lsblk to ensure you target the correct storage.

  • Stay Safe with dd: Double-check commands to avoid overwriting critical drives.

  • Validate Writes: Verifying the image ensures a successful boot.