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:

[stextbox id="grey" caption="losetup"]#losetup /dev/loop0 space-11.4R1.5.img[/stextbox]

Then try to mount:

[stextbox id="grey" caption="mount"]#mount -t ext2 -o ro,loop space-11.4R1.5.img /mnt/space-disk
mount: Stale NFS file handle[/stextbox]

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

[stextbox id="grey" caption="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[/stextbox]

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!

[stextbox id="grey" caption="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[/stextbox]

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?