Sunday, March 23, 2014

Simple method of mounting SD card image partitions for testing

Frequently you will have an SD card with linux or other partitions and you will require a method to access them.

In the case of the shell script here, I had to dd images of sd cards and I wanted to start out with just diffing everything on the two cards at a file level

First you need to fdisk the image and get the offset of the partitions you need to get to.

then perform a mount -loop,option with an offset to the start of the partition.

If you are lucky, you won't need to specify an FS type as the mount software will figure that out.

root@jws2:/home/jws/work/pitbull2# cat

#root@jws2:/home/jws/work/pitbull2# fdisk ipfire-72-pitbull.img
#Command (m for help): p
#Disk ipfire-72-pitbull.img: 15.7 GB, 15719727104 bytes
#64 heads, 32 sectors/track, 14991 cylinders, total 30702592 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: 0x00000000
#                Device Boot      Start         End      Blocks   Id  System
#ipfire-72-pitbull.img1   *          32      131071       65520    c  W95 FAT32 (LBA)
#ipfire-72-pitbull.img3          131072    30701567    15285248   83  Linux

mount -o loop,offset=$((131072 * 512)) ipfire-72-pitbull.img /mnt/reference/
mount -o loop,offset=$((131072 * 512)) mmcblk0.backup.compress /mnt/test/

diff -u -r /mnt/reference /mnt/test > diffout.txt

This illustrates not only the mount method but also the diff method.

The two images are both 16gb SD card image files.  You would also have to create the files in /mnt, or some other location upon which to mount the images.

Reference on loop mounting:

No comments:

Post a Comment