Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Xen: Users

Mounting *.img file

 

 

Xen users RSS feed   Index | Next | Previous | View Threaded


scottmeyers at live

Apr 14, 2012, 11:15 AM

Post #1 of 5 (690 views)
Permalink
Mounting *.img file

I am trying to figure out the offest sector for vm01.img2 partition. I tried many possible ways, for example (1020 *512) , but in vain. I just can't hit the right offest sector to mount vm01.img2 partition. Any help is greatly appreciated.

BTW, I am using xen-3.0.3-135.el5_8.2. The vm01.img file was created using virt-install command. The command I am using to mount the partition in that img file is: mount -o loop,offset=130048 -t ext3 /vm/vm01.img /mnt/xenimg

#fdisk -l /vm/vm01.img
vice Boot Start End Blocks Id System
/vm/vm01.img1 * 1 64 514048+ 83 Linux
/vm/vm01.img2 65 1020 7679070 83 Linux
/vm/vm01.img3 1021 1657 5116702+ 83 Linux

Partition 3 has different physical/logical endings:
phys=(1023, 254, 63) logical=(1656, 254, 63)
/vm/vm01.img4 1658 3916 18145417+ 5 Extended

Partition 4 has different physical/logical beginnings (non-Linux?):
phys=(1023, 254, 63) logical=(1657, 0, 1)

Partition 4 has different physical/logical endings:
phys=(1023, 254, 63) logical=(3915, 254, 63)
/vm/vm01.img5 1658 1784 1020096 83 Linux
/vm/vm01.img6 1785 1848 514048+ 82 Linux swap / Solaris
/vm/vm01.img7 1849 3916 16611178+ 83 Linux


cpetrolino at gmail

Apr 14, 2012, 12:09 PM

Post #2 of 5 (676 views)
Permalink
Re: Mounting *.img file [In reply to]

Try the following if you haven't already -

file -s /vm/vm01.img

see if that gives you your startsector.

I'm doing this from my phone so forgive misspellings and no formatting




On Sat, Apr 14, 2012 at 2:15 PM, Scott Meyers <scottmeyers [at] live> wrote:
> I am trying to figure out the offest sector for vm01.img2 partition. I tried
> many possible ways, for example (1020 *512) , but in vain. I just can't hit
> the right offest sector to mount vm01.img2 partition. Any help is greatly
> appreciated.
>
> BTW, I am using xen-3.0.3-135.el5_8.2. The vm01.img file was created using
> virt-install command. The command I am using to mount the partition in that
> img file is: mount -o loop,offset=130048 -t ext3 /vm/vm01.img /mnt/xenimg
>
> #fdisk -l /vm/vm01.img
>          vice Boot      Start         End      Blocks   Id  System
> /vm/vm01.img1   *           1          64      514048+  83  Linux
> /vm/vm01.img2              65        1020     7679070   83  Linux
> /vm/vm01.img3            1021        1657     5116702+  83  Linux
>
> Partition 3 has different physical/logical endings:
>      phys=(1023, 254, 63) logical=(1656, 254, 63)
> /vm/vm01.img4        1658        3916    18145417+   5  Extended
>
> Partition 4 has different physical/logical beginnings (non-Linux?):
>      phys=(1023, 254, 63) logical=(1657, 0, 1)
>
> Partition 4 has different physical/logical endings:
>      phys=(1023, 254, 63) logical=(3915, 254, 63)
> /vm/vm01.img5         1658        1784     1020096   83  Linux
> /vm/vm01.img6         1785        1848      514048+  82  Linux swap /
> Solaris
> /vm/vm01.img7         1849        3916    16611178+  83  Linux
>
> _______________________________________________
> Xen-users mailing list
> Xen-users [at] lists
> http://lists.xen.org/xen-users

_______________________________________________
Xen-users mailing list
Xen-users [at] lists
http://lists.xen.org/xen-users


Ian.Campbell at citrix

Apr 16, 2012, 12:37 AM

Post #3 of 5 (675 views)
Permalink
Re: Mounting *.img file [In reply to]

On Sat, 2012-04-14 at 19:15 +0100, Scott Meyers wrote:
> I am trying to figure out the offest sector for vm01.img2 partition. I
> tried many possible ways, for example (1020 *512) , but in vain. I
> just can't hit the right offest sector to mount vm01.img2 partition.
> Any help is greatly appreciated.

There is a tool called "kpartx" which is very useful here -- it will
read the partition table and create DM nodes corresponding to the
partitions on it. You might need to "losetup" the img to get a /dev/loop
and then run kpartx on that (I don't recall if kpartx handles loop
mounting too)

kpartx ought to be available on most distros, on Debian it is its own
binary package but the source is "multipath-tools" so YMMV may vary on
other distros.

Xen also ships "lomount" which automates the calculation of offset to
mount, but strangely I've never really used it.

Ian.




_______________________________________________
Xen-users mailing list
Xen-users [at] lists
http://lists.xen.org/xen-users


fbcyborg at gmail

Apr 16, 2012, 12:58 AM

Post #4 of 5 (670 views)
Permalink
Re: Mounting *.img file [In reply to]

On 14 April 2012 20:15, Scott Meyers <scottmeyers [at] live> wrote:
> I am trying to figure out the offest sector for vm01.img2 partition. I tried
> many possible ways, for example (1020 *512) , but in vain.
Hi,

you should do 65*512 if you want to mount at the beginning of partition 2,
not 1020x512.
I've already answered you for this question.
Please read this:
http://xen.1045712.n5.nabble.com/Viewing-the-content-of-img-file-td4840212.html

Haven't you tried what I suggested in such old discussion?
Please try that method because this always works for me. I can't
figure out why it
shouldn't work for you.

Cheers,

--
Flavio

_______________________________________________
Xen-users mailing list
Xen-users [at] lists
http://lists.xen.org/xen-users


Matthew.Keeler at jhuapl

Apr 16, 2012, 6:37 AM

Post #5 of 5 (690 views)
Permalink
Re: Mounting *.img file [In reply to]

Instead of figuring out the offset and mounting that way, why not use kpartx to figure out where all of the partitions are.

You would run:
losetup -f to determine an available loop device
losetup /dev/loopX <path to image> to do the loop setup where X is the loop device number
kpartx -a /dev/loopX to read the partition table and create entries in /dev/mapper
mount /dev/mapper/loopXpY where Y is the partition number

If you really want to get the proper offset and are running in Python do

Import parted
pdev = parted.device.Device(<path to image>)
pdisk = parted.disk.Disk(pdev)
offset = pdisk.partitions[<partition num> - 1].geometry.start * pdisk.device.sectorSize # Need to multiply by the sectorSize as parted gives the offset in sectors not bytes.

If you are doing this from bash run:

parted <path to image> -s unit b print | grep "^\s*<partition number>" | awk '{print $2 }' | tr -d 'B'

This prints out the partition table with all the units in bytes, then selects the line with the proper partition number, selects the starting offset entry and removes the trailing B from the number. This will leave you with just the byte offset which you can then give to the mount command to mount the partition.

Matt Keeler

From: xen-users-bounces [at] lists [mailto:xen-users-bounces [at] lists] On Behalf Of Scott Meyers
Sent: Saturday, April 14, 2012 2:15 PM
To: Xen Users List
Subject: [Xen-users] Mounting *.img file

I am trying to figure out the offest sector for vm01.img2 partition. I tried many possible ways, for example (1020 *512) , but in vain. I just can't hit the right offest sector to mount vm01.img2 partition. Any help is greatly appreciated.

BTW, I am using xen-3.0.3-135.el5_8.2. The vm01.img file was created using virt-install command. The command I am using to mount the partition in that img file is: mount -o loop,offset=130048 -t ext3 /vm/vm01.img /mnt/xenimg

#fdisk -l /vm/vm01.img
vice Boot Start End Blocks Id System
/vm/vm01.img1 * 1 64 514048+ 83 Linux
/vm/vm01.img2 65 1020 7679070 83 Linux
/vm/vm01.img3 1021 1657 5116702+ 83 Linux

Partition 3 has different physical/logical endings:
phys=(1023, 254, 63) logical=(1656, 254, 63)
/vm/vm01.img4 1658 3916 18145417+ 5 Extended

Partition 4 has different physical/logical beginnings (non-Linux?):
phys=(1023, 254, 63) logical=(1657, 0, 1)

Partition 4 has different physical/logical endings:
phys=(1023, 254, 63) logical=(3915, 254, 63)
/vm/vm01.img5 1658 1784 1020096 83 Linux
/vm/vm01.img6 1785 1848 514048+ 82 Linux swap / Solaris
/vm/vm01.img7 1849 3916 16611178+ 83 Linux

Xen users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.