Monday, November 14, 2016

Mounting ARM Linux (OLinuXino/Raspberry Pi) SD card .img files on Desktop PC to access its rootfs

Linux distributions for embedded ARM board like Raspberry Pi or iMX233-OLinuXino-MAXI are available as prebuilt SD card images supplied as raw .img files.
For example, .img files for ArchLinux are available for Raspberry Pi and OLinuXino.
These files can be written to SD cards using the program dd on Linux or Win32 Disk Imager on Windows.

These files contain the image of the SD card as a whole including multiple partitions - bootloader/bootlets, rootfs, swap etc.

At some point of time we might find ourselves wanting to access the files from the rootfs contained within one of the partition of these image files. Accessing the kernel headers folder for cross-compiling kernel modules for these boards can be one such situation. And one does not necessarily need to write the image to an SD card and mount it back on ones desktop to achieve this.

Major Hayden has straightforward instructions here on how to mount .img files which contain multiple partitions.

So when I found myself wanting to extract the rootfs from ArchLinux distribution for OLinuXino (ArchLinuxARM-2014.02-olinuxino-rootfs.img) onto my Ubuntu 12.04 32 bit Desktop, here are the steps I followed:


Analyse the image file using the fdisk and file commands:
There are two partitions, the first one is for the bootloader and the second one is the rootfs. We want to mount the second one

The start sector for the second partition which houses the rootfs is 67584. We need to mount that. Since block size is 512, we need to mount starting from 67584*512 byte 34603008

Make a folder for mounting the rootfs. I named mine "rootfs"

And issue the command to mount:
sudo mount -o ro,loop,offset=34603008 ArchLinuxARM-2014.02-olinuxino-rootfs.img rootfs

The rootfs from the .img file is successfully mounted
You can even use nautilus to browse the mounted folder!!


0 comments:

Post a Comment