Sunday, April 13, 2014

How To: Mount a broken ODroid (U2) boot images from Windows


How To: Mount a broken ODroid (U2) boot image from Windows

 

Sat In A Box For A While...


http://com.odroid.com/sigong/_Files/2012/201211/images/201211251432377371.jpg

Almost a year and a half ago, I purchased an ODROID U2 from Hardkernel from HardKernel.com.  Since then, the U2 sat in a box and was replaced by the ODROID U3 product line. Earlier this year I finally had time to get it out.

Overview

In brief, the ODroid U2 is a ARM processor board which can boot from an SD card or an EMMC card.  It supports Android and Linux operation systems (and probably more) with some extra drivers.  Think of it as a Smart Phone motherboard with full size USB and network connections.

Side note: I did look at Rasberry PI first, then bought the ODroid.

After moving between countries with the growing family, I finally had time to get the device out and explore.  After "fixing" the boot partition layout of the EMMC card (which I had initially destroyed by writing an SD images to the EMMC card), I was finally able to reach my short term goal: booting Linux on this tiny device.  I started customizing the settings to suit myself and testing out available software in preparation for a larger project.
Not long after this, I destroyed the boot-able image on the EMMC.

Step 1: Assessment

While glossing over the specifics, I had removed all the boot files, kernels and related details which make the EMMC bootable.
Yes, in fact it doesn't boot any more, displaying only the D.S.B.L. (Dreaded Solid Blue Light); when the ODroid U2 is powered-up, there is a blinking blue light to indicate that the system is booted and operational where as a solid blue light is for other, "non-positive" cases.

Step 2: Planning

Since I used an .img file to write the EMMC image to start with, I could have easily re-burn the same starting .img file to the EMMC again.  But, this would mean losing the current, customized setup ( and more importantly my notes for that setup ) and starting again.  So, my goal was 1) to recover my notes and 2) repair the system.

What I found was the .img file is really a kind of direct 'disk' image of OS, including (and importantly) the boot and other OS partitions.

I am currently using Windows 7 at home.  While Windows doesn't understand these other partition types, Linux readily does.  The plan is to mount the partitions, repair and copy off data and retest.

Step 3: Make an .IMG

I needed to make a new .img file of the corrupted EMMC Linux "disk" from the EMMC.  This allowed me to experimenter while not damaging the original image, providing a "fall back option" if needed.

I placed the EMMC card in to the eMMC Module Reader and plug into Windows host.  Windows saw it and prompted me for some not-so-useful options, such as reformatting.  Cancel all the windows options and let it mount unmodified.

Using Win32 Disk Imager, I configured it to read from the eMMC Module Reader (with the EMMC attached) and selected a target directory and name for the .img file.

In my case, I read from H:\ and wrote to c:\temp\odroid-rescue.img. Your drive and targets will probably be different. I will use this for the reminder of these instructions; adjust your settings as needed.

IMPORTANT: as the tool will remind you, make sure you are very clear where you are reading from and where you intend to write to.  This tool can easily erase a media.

Once configured, click on the Read button.  This will read from H:\ and write to c:\temp\odroid-rescue.img

With a larger EMMC, this can take a while as it is making a bit-for-bit copy of the media.

Step 4: Mounting Folders

I have an up-to-date version of Virtual Box on Windows with Fedora 14 which I have used for years now.  I used it because it was already set and available but any modern Linux distro installed in a virtual machine should work.

Using VirtualBox, I setup this Linux VM to share a directory with my Windows host.  In this directory I copied my odroid-rescue.img image.

Note: instructions for using VirtualBox and shared folders are not in the scope of this article.  An alternative is to copy the .img inside the Linux VM but be aware of the size of your .img file before taking this approach.

I started and logged into the Linux VM.  In the Linux VM, I verified both the shared directory was accessible and the .img file was available.  I changed/su-ed to the root account to avoid excessive sudos.

Step 5: Measuring The Partitions

So, now I am in Linux VM as root and I can see the .img file.  Inside this particular .img file, I know there could be one or more partitions.  As such, I will need to survey the contents on the .img file before mounting parts of it.

cd /path/to/odroid-rescue.img
fdisk -lu odroid-rescue.img


Note: this .img file contains an xubuntu 3.10 image. Other Linux distribution's partitions any vary significantly.

Here are the results with key aspects bolded in red:

Disk odroid-u2-emmc-64G-xbuntu13.1.img: 62.5 GB, 62537072640 bytes
255 heads, 63 sectors/track, 7603 cylinders, total 122142720 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
Disk identifier: 0x000c4046

                            Device Boot      Start         End      Blocks   Id  System
odroid-u2-emmc-64G-xbuntu13.1.img1            4096      266239      131072    b  W95 FAT32
odroid-u2-emmc-64G-xbuntu13.1.img2          266240   122142719    60938240   83  Linux

So, in my case I have:
  • Bytes per sector are 512 (first bold number)
  • two partitions:
    • one FAT32 partition which starts on 4096 (second bold number)
      • boot files are here!
    • one Linux partition which starts on 266240 (third bold number)

Step 6: Mounting Partitions

In the Linux VM, cd /mnt and create directories: /mnt/boot and /mnt/odroid.

To mount the boot partition I used:
mount -t auto -o loop,offset=$((512*4096)) odroid-rescue.img  /mnt/odroid-boot/
Note: the 4086 comes from the "start" column of the fdisk command and the 512 from the sector size.

To mount the other partition I used:

mount -t auto -o loop,offset=$((512*266240)) odroid-rescue.img  /mnt/odroid/
Note: the 266240 comes from the "start" column of the fdisk command and the 512 from the sector size.


         
Note: see references for whom to created for this section.

Step 7: Explore, Repair And Copy (as needed)

Here you have access to the partitions of the .img file for exploration and/or repairs as you wish.

In my case, I needed to put the correct files back in the /mnt/odroid-boot and backup files from /mnt/odroid. 

IMPORTANT: All changes your make to the mounted .img file are "live and persistent" like any other disk operation so do be careful!

Step 8: Release The Image and Un-Mount Partitions

After you finish you changes, close all editors and any other open files into the mounted image partitions.  Then:
umount /mnt/odroid
umount /mnt/odroid-boot

Makes certain there are no issues with the umount commands.  As an alternative catch all" move, shutdown the Linux VM to ensure you are completely disconnected from the .img file.

Step 9: Re-burn the ,img to the EMMC card

Back in the Windows host and using Win32 Disk Imager again, this time you will setup to read from the odroid-rescue.img and write to H:\ after connecting the EMMC to your eMMC Module Reader and load it into Windows.

IMPORTANT: as the tool will remind you, make sure you are very clear where you are reading from and where you intend to write to.  This tool can easily erase an media.

Once configured, click on the Write button.  This will write c:\temp\odroid-rescue.img to H:/

Step 10: Boot EMMC card

You are now ready to "check our work" by replacing the EMMC card in the powered off ODroid device, powering it up.  A blinking blue light means success while a stead blue light means try again.

Summary

We have described:
  1. discovering partition information about an .img file
  2. the basics of mounting an .img file
  3. described the use of the Win32 Disk Imager
  4. described how to perform a rescue operation of a Linux .img file from a Windows OS using VirtualBox

Resources

Here is where I got my information from:
  1.  [SOLVED] how to mount .img file
  2.  Win32 Disk Imager
  3.  VirtualBox

No comments: