In the article How to copy an image to an sd-card you can read how to copy the disk image file (e.g. what you have downloaded, e.g. raspbian-RT-opendatalogger-201511.img) to an SD-card in a card reader attached to your computer.

Now, I would like to show, how the content of the .img file can be browsed without copying it to an SD-card.

You might ask, why do I need this? Maybe if you are also maintaining an image file, and would like to keep some software up-to-date within it, you will end up after the second time to put the SD-card in a raspberry, boot, update the software (even if its only a git pull command) dd back to create a new image, because it takes a lot of time.

We will mount the image, so it will be part of the root file system, enabling editing with ordinary tools (such as git). In case of a Raspbian installation, you have within the image file 2 partitions.

  1. A boot partition (which is small as a few ten MB)
  2. A root partition (ext4) storing all your files, usually several GB large.

Since I am only interested in the 2. partition, I have to find out the offset of that partition and mount it with this offset option of mount.

The fdisk command is capable to provide this information.

fdsik -l raspbian-RT-opendatalogger-201511.img

fdisk

mount needs the offset in bytes. As you can see in the screen-shot above, the block size=512 bytes times the offset of 122880 blocks = 512*122880=62914560. From here on one command with the right arguments mounts the image:

sudo mount -o loop,offset=62914560 raspbian-RT-opendatalogger-201511.img /mnt/

As you can see, I can read, browse, modify the image by accessing /mnt/

fdisk

(ll is an alias for ls -l)

When finished, just sudo umount /mnt

mount image file as device

Here you find the instructions how to mount the image file alternatively as a device which you can resize or partition.



Comments

comments powered by Disqus