Click to See Complete Forum and Search --> : mounting partitions from a full disk image
neuron
10-26-2008, 08:11 AM
Hello, i hope this is the correct section to post this question,
I have an image of a disk (/dev/sda for example) as a file, called image.iso, i want to mount the 2nd primary partition (was sda2) from the image, how do i do that ?
I know how to mount disk images using loop device, but i need to mount a partition within that image!
Thanks
saikee
10-26-2008, 10:15 AM
I believe an iso file is just a data file arranged to iso9660 standard generally used by CD or DVD. Thus to read it you need to mount it on a loop back device which is a standard facility within the mount command.
The step 2 of this thread (http://www.justlinux.com/forum/showthread.php?t=150078) gives a script as for mounting any iso file on a subdirectory /cdrom
mkdir /mnt/cdrom
mount -t iso9660 -o ro,loop=/dev/loop0 $1 /mnt/cdrom
It should work if you specify your target in place of $1 and using any other subdirectory other than /mnt/cdrom.
Needless to say the partition you mount the iso file must be big enough for the image. You should find all the original subdirectories inside the mount point.
bwkaz
10-26-2008, 10:33 PM
Um, saikee? I don't think it's an ISO image. I think he just named it image.iso (even though it wasn't a copy of a CD or DVD -- yes, this sounds like a really bad idea to me too); it sounds like it actually has a partition table on it. ISO images can't have partition tables. ;)
neuron -- I seem to remember something about some newer kernels having support for partitions on loopback devices. But I can't find that anymore, so I don't know when it happened (or if I'm just imagining it -- either is possible). I believe I've heard that kpartx can do something with device-mapper to give the loopback device partitions, though; you may want to check into it.
Samsonite
10-31-2008, 01:15 AM
If it is just an image file, find the offset of the first sector of the partition and multiply by 512 to get an offset value. Then mount the partition using that offset figure. Below is an example of mounting the first partition which starts at offset 63 (63 sectors) found by the second command run from the same directory as the image file:
1: mkdir /mnt/image
2: sfdisk -l -uS image.iso
3: mount -oloop,offset=32256 image.iso /mnt/image
You would then be able to access the patition in /mnt/image.
In some cases, you may need to specify the file system type in the mount command, example for NTFS filesystem:
mount -t ntfs -oloop,offset=32256 image.iso /mnt/image