Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I trying to do following on KVM host:

# kpartx -av /dev/VolGroup00/kvm101_img
add map kvm101_img1 : 0 208782 linear /dev/VolGroup00/kvm101_img 63
add map kvm101_img2 : 0 125612235 linear /dev/VolGroup00/kvm101_img 208845
# mount /dev/mapper/kvm101_img1 /mnt

then I'm getting /boot partition mounted. But I'm getting an error if I then type following:

# mount /dev/mapper/kvm101_img2 /mnt
mount: you must specify the filesystem type

Here is a fdisk layout on guest machine:

# fdisk -l
Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14        7832    62806117+  8e  Linux LVM

Is it possible to find a root partition on guest and mount it on host system?

share|improve this question
I suppose your reference to kvm101_img2 is a typo. It should be _img1 instead, right? – joechip Jul 5 '11 at 23:10
_img1 mounts correctly with method above, but _img1 is a /boot partition, equivalent to /dev/hda1 on guest. Problem was that I couldn't mount _img2 containing /dev/hda2 Linux LVM. That partition layout is default for CentOS installer. – Evolver Jul 6 '11 at 7:12
Oh OK, I was thrown out by the reference to KVM. There's nothing KVM specific about this question then, it's simply one LVM structure inside another. – joechip Jul 6 '11 at 16:43

Seems that I finally figured out how to do things I needed. Here is what I did:

# kpartx -av /dev/VolGroup00/kvm101_img
# vgscan

if VolGroup names identical in guest and host systems, then you have to rename guest VolGroup

# vgrename <uuid> VolGroupXX

uuid of VolGroups you can check in vgdisplay. So, the trick is in activating guest VolGroup:

# lvscan
# vgchange -ay VolGroupXX
# lvscan

After that it's easily mounted:

# mount /dev/VolGroupXX/LogVol00 /mnt

Finally, the backward process is:

# umount /mnt
# vgchange -an VolGroupXX
# kpartx -dv /dev/VolGroup00/kvm101_img
# pvscan

The last command cleans the LVM cache and removes the physical volume created by kpartx from LVM.

share|improve this answer
You might have to edit the guest's fstab in order to use VolGroupXX instead of VolGroup00 then. – joechip Jul 6 '11 at 16:44

I'm glad you figured it out for your situation.

In the more general case, the guest drive could be in a variety of formats such as qcow, qcow2, etc., so you wouldn't be able to work on them directly. In this case, you might use something like on the host:

# modprobe nbd
# kvm-nbd -c /dev/nbd0 file.qcow2

Then you could access /dev/nbd0 as the raw guest drive. To stop using this device you should run:

# nbd-client -d /dev/nbd0

If, on the other hand, the guest drive were in raw format, you would use losetup:

# losetup -f file.raw

This would find and use the first available loop device (e.g., /dev/loop0). To stop using it run:

# losetup -d /dev/loop0

After this you would be able to do the kpartx / vgscan / lvscan / mount procedure you describe in your answer.

share|improve this answer

you can do it using guestfish -

share|improve this answer
Thanks for suggestion, but unfortunately I couldn't even install guestfish: I spent hours of googling and investigating - all useless, it's not works :( Maybe there is some another way to mount linux partition? I don't need all-in-one tool to mount everything, just LVM. – Evolver Jul 5 '11 at 15:38
try to run qemu-img info /path/to/image. if what you get in the Type box is not "RAW" then there is no way an OS can mount this image as a partition, because it is formatted as a qemu-specific virtual disk. This is what guestfish deals with, it's not just a simple mounting tool – dyasny Jul 5 '11 at 16:21

It might be easier just to use guestfish from the libguestfs package which should work out all the annoying details for you instead of trying to do it manually

share|improve this answer

protected by Tom O'Connor Jul 25 '13 at 8:54

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.