Fedora Linux Support Community & Resources Center
  #1  
Old 19th January 2009, 08:50 PM
nt4cats Offline
Registered User
 
Join Date: Aug 2005
Location: Philadelphia, PA
Posts: 99
mount a disk image (made with dd) + LVM

I like to do fresh installs when I 'upgrade' from one Fedora release to the next. That way any hacks or workarounds that I made in the prior release don't get in my way. I'm also enough of a geek that I pretty much upgrade on release day every release (since Fedora Core 3).

Prior to doing a fresh install I take a drive image -- so if the new install doesn't go well I have an easy roll-back path. When F10 came out, I booted to a Live CD image, attached a big external hard drive and did some variation of 'dd if=/dev/sda of=/mnt/usb-disk/f9-disk.img bs=8M'.

In the past I also did a file-level copy (using rsync) for easy access. This time I didn't have enough disk space on the external drive for both the drive image AND a file-level copy, so I decided I'd just do the image -- figuring I could just mount it if I needed to get files.

This gives me a nice 200G image file of every bit that was on my hard drive before I wiped it.

I want to grab a few files off of the old drive image, but I can't figure out how to mount this image. If this were an external USB device with LVM on it, I know how to 'discover' the PV/LV stuff and mount it. I know how to use the mount command to mount a file system -- but this isn't a file system.

I guess I need a way to make this .img file appear to be a block device so that the pvchange and lvscan commands can see it.

Additional info: I always use the "create default layout" option for my disks (small boot part'n, LVM for data and swap) when doing an install -- EXCEPT that I go in and edit the volume names to include the Fedora Release number. That way there will not be a conflict with my current volume names if I try and access the disk image.

I think I was a bit too clever for my own good here ...
Reply With Quote
  #2  
Old 19th January 2009, 08:54 PM
nt4cats Offline
Registered User
 
Join Date: Aug 2005
Location: Philadelphia, PA
Posts: 99
... or maybe this is a better way to put my question:

If this was an external USB disk, I'd attach it, and the magic gnomes and fairies in my computer would work together to make this USB disk available as /dev/sdc.

How do I tell the magic gnomes and fairies to present the data at /mnt/usb-disk/f9-disk.img as /dev/sd[X]?
Reply With Quote
  #3  
Old 19th January 2009, 10:02 PM
sideways Offline
Retired User
 
Join Date: Oct 2004
Location: London, UK
Posts: 4,999
I haven't got the image file to test this atm, but I recall that you need to run kpartx on the image file before you run vgscan

Code:
kpartx -av /mnt/usb-disk/f9-disk.img
vgscan
Reply With Quote
  #4  
Old 19th January 2009, 11:05 PM
nightmarcus Offline
Registered User
 
Join Date: Mar 2006
Location: WA
Age: 27
Posts: 83
Try mounting the file like you would mount a normal file system. I made a .img of my Windows hard drive for backups at one point and I just mounted it with the normal mount -t ntfs blah blah blah and it worked for me. Just in the place of where you would put the source device you're trying to mount, put the path to the img file. Example that I used in my situation was I believe this:
Code:
modprobe loop
mount -o loop -t ntfs ./<filename>.img /mnt/<some folder>
Reply With Quote
  #5  
Old 19th January 2009, 11:15 PM
nt4cats Offline
Registered User
 
Join Date: Aug 2005
Location: Philadelphia, PA
Posts: 99
Nightmarcus:

If this was a dd of a partition with a filesystem on it, then your command would work perfectly.

There are two problems:

1) This is a dd of a disk (lower-level than the partition) -- it is a dd of /dev/sda, NOT a dd of /dev/sda1
2) The partition with the data on it is managed with LVM, so even if I had direct access to the partition (which I will shortly) I have to make the LVM infrastructure aware of the physical and logical volumes stored in the image -- and THEN I can get to the ext3 filesystem using mount.
Reply With Quote
  #6  
Old 20th January 2009, 12:18 AM
nt4cats Offline
Registered User
 
Join Date: Aug 2005
Location: Philadelphia, PA
Posts: 99
Smile

Okay, I have it. Thanks to sideways who gave me the last "missing link" in the chain.

Here is what my machine looks like normally:
Code:
[root@cylon ~]# df -mlh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroupAlpha-LogVolCylonRoot
                      178G   91G   79G  54% /
/dev/sda1             190M   30M  151M  17% /boot
tmpfs                 2.0G   76K  2.0G   1% /dev/shm
[root@cylon ~]# ls -l /dev/mapper/
total 0
crw-rw---- 1 root root  10, 63 2009-01-19 18:43 control
brw-rw---- 1 root disk 253,  0 2009-01-19 18:43 VolGroupAlpha-LogVolCylonRoot
brw-rw---- 1 root disk 253,  1 2009-01-19 18:43 VolGroupAlpha-LogVolCylonSwap
Okay, so plug in my external USB drive ...
Code:
[root@cylon ~]# df -mlh
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroupAlpha-LogVolCylonRoot
                      178G   91G   79G  54% /
/dev/sda1             190M   30M  151M  17% /boot
tmpfs                 2.0G   76K  2.0G   1% /dev/shm
/dev/sdb1             459G  360G   76G  83% /media/disk
... and here is the disk image I created with dd:
Code:
[root@cylon ~]#  ls -l /media/disk/fc9-cylon/fc9-disk.dd 
-rw-r--r-- 1 root root 200049647616 2008-11-25 23:03 /media/disk/fc9-cylon/fc9-disk.dd
First: create a loop device. This maps the bits in the file to a block device under /dev/.
Code:
[root@cylon ~]# losetup -f /media/disk/fc9-cylon/fc9-disk.dd
[root@cylon ~]# losetup -a
/dev/loop0: [0811]:1007622 (/media/disk/fc9-cylon/fc9-disk.dd)
Second (thanks Sideways!): read the partition table from the new block device and create device mappings for the partitions:
Code:
[root@cylon ~]# kpartx -a -v /dev/loop0
add map loop0p1 (253:2): 0 401562 linear /dev/loop0 63
add map loop0p2 (253:3): 0 390315240 linear /dev/loop0 401625
[root@cylon ~]# ls -l /dev/mapper
total 0
crw-rw---- 1 root root  10, 63 2009-01-19 18:43 control
brw-rw---- 1 root disk 253,  2 2009-01-19 18:51 loop0p1
brw-rw---- 1 root disk 253,  3 2009-01-19 18:51 loop0p2
brw-rw---- 1 root disk 253,  0 2009-01-19 18:43 VolGroupAlpha-LogVolCylonRoot
brw-rw---- 1 root disk 253,  1 2009-01-19 18:43 VolGroupAlpha-LogVolCylonSwap
LVM will kick in magically and recognize a new physical volume on /dev/mapper/loop0p2 (the 2nd partition on the loop0 device). Apparently "/dev/dm-3" is an alias for the 3rd device mapping in /dev/mapper. If the magic doesn't happen you can trigger it by typing (no quotes) "pvscan".
Code:
[root@cylon ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/dm-3
  VG Name               VolGroupPrimary
  PV Size               186.12 GB / not usable 23.61 MB
  Allocatable           yes 
  PE Size (KByte)       32768
  Total PE              5955
  Free PE               1
  Allocated PE          5954
  PV UUID               vBDvjw-qfvA-tgnp-Xajg-KHb2-fPPz-3iGcix
   
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroupAlpha
  PV Size               186.12 GB / not usable 23.61 MB
  Allocatable           yes 
  PE Size (KByte)       32768
  Total PE              5955
  Free PE               1
  Allocated PE          5954
  PV UUID               G02Ic7-BfPl-71fP-6WZl-PEDB-RmcK-0gxHLe
Now we need to activate the LVM volume group:
Code:
[root@cylon ~]# vgchange -a y
  2 logical volume(s) in volume group "VolGroupPrimary" now active
  2 logical volume(s) in volume group "VolGroupAlpha" now active
[root@cylon ~]# ls -l /dev/mapper
total 0
crw-rw---- 1 root root  10, 63 2009-01-19 18:43 control
brw-rw---- 1 root disk 253,  2 2009-01-19 18:51 loop0p1
brw-rw---- 1 root disk 253,  3 2009-01-19 18:51 loop0p2
brw-rw---- 1 root disk 253,  0 2009-01-19 18:43 VolGroupAlpha-LogVolCylonRoot
brw-rw---- 1 root disk 253,  1 2009-01-19 18:43 VolGroupAlpha-LogVolCylonSwap
brw-rw---- 1 root disk 253,  4 2009-01-19 18:54 VolGroupPrimary-LogVolRootPartn
brw-rw---- 1 root disk 253,  5 2009-01-19 18:54 VolGroupPrimary-LogVolSwapPartn
Now we are finally ready to mount it!
Code:
[root@cylon ~]# mkdir /mnt/old-disk
[root@cylon ~]# mount /dev/mapper/VolGroupPrimary-LogVolRootPartn /mnt/old-disk/
When you're done, here is how to shut everything down cleanly ...
Code:
[root@cylon ~]# umount /mnt/old-disk
[root@cylon ~]# vgchange -a n VolGroupPrimary
  0 logical volume(s) in volume group "VolGroupPrimary" now active
[root@cylon ~]# kpartx -d /dev/loop0
[root@cylon ~]# losetup -d /dev/loop0

Last edited by nt4cats; 28th January 2010 at 09:00 PM. Reason: Added necessary command in case your physical volume is not automatically recognized.
Reply With Quote
Reply

Tags
disk, image, lvm, mount

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fedora live disk creation & disk image backup itsjoy2u Using Fedora 8 14th August 2013 12:56 PM
Permission denied error when trying to mount image contained in sshfs mount openSauce Using Fedora 5 8th March 2009 03:14 PM
disk drives refuse to mount (fstab/mount) spfdz Using Fedora 10 13th November 2006 02:13 AM
Disk Image pvr Using Fedora 0 24th August 2005 06:27 AM


Current GMT-time: 15:19 (Saturday, 25-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Baturaden Photos - Ezhva - Munich Travel Photos on Instagram