Mounting an image file in Linux

If you need to mount an image file as a disk partition you can follow the following steps. I have followed these to mount a junos space disk image indeed. Here are the steps:

losetup
#losetup /dev/loop0 space-11.4R1.5.img

Then try to mount:

mount
#mount -t ext2 -o ro,loop space-11.4R1.5.img /mnt/space-disk
mount: Stale NFS file handle

It fails right? To get where the sector starts on this image

file
#file space-11.4R1.5.img
space-11.4R1.5.img: x86 boot sector; partition 1: ID=0x83, active, starthead 1, startsector 62, 3890066 sectors, code offset 0x31

Sector is 62 from which we calculate offset as 62*512=31744 and partition id is 83. It is linux and   file system type is ext2, now mount!

command
#mkdir /mnt/space-disk
#mount -t ext2 -o ro,loop,offset=31744 space-11.4R1.5.img /mnt/space-disk
#ls /mnt/space-disk/
LiveOS ks.cfg lost+found space-11.4R1.5.iso syslinux

Here is the partition content!

DISCLAIMER: Views expressed in this blog are my own and do not necessarily reflect those of Juniper Networks

You have a feedback?