November 11, 2019, 10:39:42 pm

News:

Have you visited the Allwinner Chipset wiki? - http://linux-sunxi.org/


Checking out Disk Images the easy way.

Started by lawrence, January 25, 2013, 09:51:12 pm

Previous topic - Next topic

lawrence

January 25, 2013, 09:51:12 pm Last Edit: January 25, 2013, 10:06:55 pm by lawrence
As some in the community prefer to make whole disk images, rather than separated files, it can be a bit irritating if you just want to check out someones kernel quickly.

What to do?

Well, as a disk image, is merely... a disk image, you can still run standard tools on it.

Lets take an example.  I've found an intriguingly named linaro-alip-armhf-t4.img  file, that I want to look at.

On OS X, I can use fdisk and the name of the file to see what the partitions are.
On linux fdisk -ul should do the same thing.
On windows you should load up a VM of Linux and do the above.

Lets do that:

fdisk /Users/lawrence/Downloads/linaro-alip-armhf-t4/linaro-alip-armhf-t4.img
Disk: /Users/lawrence/Downloads/linaro-alip-armhf-t4/linaro-alip-armhf-t4.img geometry: 939/128/63 [7579648 sectors]
Signature: 0xAA55
         Starting       Ending
#: id  cyl  hd sec -  cyl  hd sec [     start -       size]
------------------------------------------------------------------------
1: 83    0  33   3 -    4  65  34 [      2048 -      32768] Linux files*
2: 83   17   0   1 -  544  63  32 [     34816 -    7372800] Linux files*
3: 00    0   0   0 -    0   0   0 [         0 -          0] unused     
4: 00    0   0   0 -    0   0   0 [         0 -          0] unused   
 


So, looking at this image, I see that there are 2 partitions.

@2048  (at 1M) for 32M theres 1 partition (boot partition)
@34816 (1.7408M) for 7.3G theres another partition (rootfs)

I also know that this is a standardized setup, so
@8k and @32k I will see the ipl/spl.  I don't need those though, as I prefer to use the nightlies from the linux-sunxi site.

So, we know there is an image at 2048.  While we could use dd to extract that partition, lets go one better.
Lets mount it straight.


Our partition table size is 512, as this is an SD image, so we'll need to multiply our start partition by that to get the actual location (its at 1M on the SD card for the first partition)

2048 x 512 = 1048576  (which is 1M in bytes)

We'll need a *nix system to mount it, as OS X doesn't like doing offset mounts, and windows is not a real OS.
So, off to *nix land.

mkdir /mnt/test
mount -o loop,offset=1048576 -t auto linaro-alip-armhf-t4.img /mnt/test

And voila, we can see whats inside that partition at /mnt/test.

Repeat for the second offset, and we can also mount the rootfs..


Because seeing is believing, I have attached screen shots of the mounted filesystems.

Enjoy!


lawrence

Thought I'd add another example, as I just did this again for some testing:

I downloaded a rasberry pi distribution and i wanted to take a look at some files inside.

Instead of blatting it out to an SD, I did the same as I did previously.
Heres my example:

Sample file is:  chameleon.v031.img.bz2

Unpacked it to chameleon.v031.img

-rw-r--r--  1 root   samba 3850000000 Apr 10 12:39 chameleon.v031.img
-rw-r--r--  1 samba  samba  742777226 Apr  7 10:22 chameleon.v031.img.bz2


Gave it a quick run through with fdisk to see if it see's any valid partitions:

fdisk -l chameleon.v031.img

Disk chameleon.v031.img: 3849 MB, 3849999872 bytes
4 heads, 32 sectors/track, 58746 cylinders, total 7519531 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: 0x000f01ca

             Device Boot      Start         End      Blocks   Id  System
chameleon.v031.img1            8192      122879       57344    6  FAT16
chameleon.v031.img2          122880     6877183     3377152   83  Linux
chameleon.v031.img3         6877184     7905279      514048    b  W95 FAT32


So, I can see that there are 3 valid partitions on the drive.

First one is fat16, 2nd linux ( and the largest one), and the 3rd is fat32.
I wanted to look at the stuff in the 2nd partition - chameleon.v031.img2         

The start sector for that is  122880, and sector size is 512 bytes according to fdisk
- "Sector size (logical/physical): 512 bytes"

So, going with some basic math  - 122880 x 512 = 62914560

Thats where that partition starts on the image, so lets mount it baby!

mkdir /mnt/tmp
mount -o loop,offset=62914560  -t auto chameleon.v031.img /mnt/tmp



The secret sauce is in the mount command.  We pass the offset to the partition, and mount does all the hard work.

A quick check shows that it mounted ok -

ls -al /mnt/tmp
total 116
drwxr-xr-x 26 root root  4096 Mar 28 17:01 .
drwxr-xr-x  7 root root  4096 Apr 10 12:37 ..
drwxr-xr-x  2 root root  4096 Feb 19 00:53 bin
drwxr-xr-x  2 root root  4096 Oct 29 06:12 boot
drwxr-xr-x  2 root root  4096 Jan  1  1970 boot.bak
drwxr-xr-x  3 root root  4096 Oct 29 05:59 dev
drwxr-xr-x 99 root root  4096 Mar 28 02:55 etc
drwxr-xr-x  3 root root  4096 Jan 16 01:34 home
drwxr-xr-x 14 root root  4096 Feb 10 04:05 lib
drwx------  2 root root 16384 Oct 29 05:50 lost+found
drwxr-xr-x  3 root root  4096 Feb 19 00:53 man
drwxr-xr-x  2 root root  4096 Oct 29 05:54 media
drwxr-xr-x  2 root root  4096 Sep  3  2012 mnt
drwxrwxrwx 32 root root  4096 Mar 28 02:13 opt
drwxr-xr-x  2 root root  4096 Sep  3  2012 proc
drwxr-xr-x  2 root root  4096 Feb 10 20:02 roms
drwx------  7 root root  4096 Mar 28 17:01 root
drwxr-xr-x  8 root root  4096 Jan  1  1970 run
drwxr-xr-x  2 root root  4096 Feb 24 03:59 sbin
drwxr-xr-x  2 root root  4096 Jun 20  2012 selinux
drwxrwxrwx  5 root root  4096 Feb 19 00:53 share
drwxr-xr-x  2 root root  4096 Oct 29 05:53 srv
drwxr-xr-x  2 root root  4096 Sep 13  2012 sys
drwxrwxrwt  3 root root  4096 Mar 28 16:17 tmp
drwxr-xr-x 10 root root  4096 Oct 29 05:54 usr
drwxr-xr-x 11 root root  4096 Oct 29 06:59 var



I use this sort of solution all the time when checking out disk images.  Hopefully this will be useful for you also.

Lawrence.