[CentOS] question on mounting a partition that is in a disk image

William L. Maltby BillsCentOS at triad.rr.com
Wed Aug 23 15:48:27 UTC 2006


On Wed, 2006-08-23 at 10:02 -0400, Jerry Geis wrote: 
> How do I mount a partition that is in an image file?
> 
> I have a file called centos.img that has 3 partitions in the file.
> I need to copy data to the third partition on that image file.
> 
> I have seen things about a loop back device (which is fine)
> but then it talked about an offset parameter and I dont know what
> that is or more importantly what number to use. I hope I'm on the
> right track.
> 
> How do I mount it?

Just assign the whole thing to a loop device. Then do an 

    "sfdisk -l /dev/loop0" # or whichever loop you used

If it is truly an image file, at that point it *appears* identical to a
real device. I've added little sample I ran, since I know this can be
scary.

Offset is just if you need to start elsewhere from the beginning. If
you're using LVM, you'll have more work to do.

====================================================================
# Pardon my verbosity as I set up a test scenario.
# lvextend --extents +40 VolGroupTemp/LogVol00
  Extending logical volume LogVol00 to 1.62 GB
  Logical volume LogVol00 successfully resized

mke2fs -b 4096 -m 0 -N 128 /dev/VolGroupTemp/LogVol00
<snip extremely fascinating refs to momentous cosmological events>

Maximum filesystem blocks=436207616
...
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912

Writing inode tables: done
Writing superblocks and filesystem accounting information: done
...

# mount -t ext2 /dev/VolGroupTemp/LogVol00 /VolGroupTemp/LogVol00/
# dd if=/dev/hda of=/VolGroupTemp/LogVol00/hda_image bs=8225280
<snip>
# losetup /dev/loop0 /VolGroupTemp/LogVol00/hda_image

[root at server01 ~]# sfdisk -l -uS /dev/loop0
Disk /dev/loop0: cannot get geometry

Disk /dev/loop0: 0 cylinders, 0 heads, 0 sectors/track
Warning: The partition table looks like it was made
  for C/H/S=*/255/63 (instead of 0/0/0).
For this listing I'll assume that geometry.
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/loop0p1   *        63    208844     208782  83  Linux
/dev/loop0p2        208845   2506139    2297295  8e  Linux LVM
/dev/loop0p3             0         -          0   0  Empty
/dev/loop0p4             0         -          0   0  Empty

# dc
63
512*pq
32256

# losetup -o 32256 /dev/loop1 hda_image
# e2fsck /dev/loop1
e2fsck 1.35 (28-Feb-2004)
/boot: clean, 43/26104 files, 19763/104388 blocks

# mkdir /mnt/temp
# du -s /mnt/temp/*  # Snipped below for brevity
51      /mnt/temp/config-2.6.9-34.0.1.EL
211     /mnt/temp/grub
986     /mnt/temp/initrd-2.6.9-34.0.1.EL.img
...
1442    /mnt/temp/vmlinuz-2.6.9-34.0.2.EL
1442    /mnt/temp/vmlinuz-2.6.9-34.EL

# dc
32256
208782
512*+pq
106928640
# losetup -o 106928640 /dev/loop2 hda_image
# pvdisplay /dev/loop2
  Found duplicate PV 602X4Js851U78eRzvYP3Fhyf4F8A1v68: using /dev/hda2
not /dev/loop2
  Found duplicate PV 602X4Js851U78eRzvYP3Fhyf4F8A1v68: using /dev/loop2
not /dev/hda2
  --- Physical volume ---
  PV Name               /dev/loop2
  VG Name               VolGroup00
  PV Size               1.09 GB / not usable 0
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              35
  Free PE               0
  Allocated PE          35
  PV UUID               602X4J-s851-U78e-RzvY-P3Fh-yf4F-8A1v68
=================================================================

> 
> THanks,
> 
> Jerry
> <snip sig stuff>

HTH
-- 
Bill
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.centos.org/pipermail/centos/attachments/20060823/aaffe4e4/attachment.sig>


More information about the CentOS mailing list