2

How can I mount a root virtual disk from another VM on my CentOS ? In order to change some files on it, not to use it as a real root disk.

there are 2 partitions on my virtual disk : /boot (Linux partition) and / (LVM)

I've already added it to my VM by using virsh attach-disk, then I can see it on my CentOS but I can't use it :

mount /dev/vdx /mnt/test
mount: unknown filesystem type 'LVM2_member'

And something really weird, if I add my disk on my VM template, my centOS use the /boot partition of it (/dev/vdc1) instead of the /boot partition (/dev/vda1) that it has to use...

Thanks for help

[EDIT] :

This is the actual situation and my problem :

  • VM1 has virtual drive #1, provided by hypervisor (logical volume LVM). This VM is KO, I can't boot it because of I/O errors.
  • VM2 has virtual drive #2, provided by hypervisor (LVM too). It works fine.

The 2 virtual drives are cut like that on their VM : - /dev/vda1 = /boot (Linux partition) - /dev/vda2 = / (LVM partition)

Problem : I need to recover datas from VM1.

So I've already attach vd#1 to VM2. On VM2 I can see that drive, as /dev/vdc, but how can I mount it and read it ?

Thanks.


@psusi and @Halfgaar

Hypervisor :

virsh attach-disk my_VM /dev/vgdata/disk10 vdc

on my VM :

ls -la /dev/vd*

brw-rw---- 1 root disk 252, 0 Dec 22 11:22 /dev/vda
brw-rw---- 1 root disk 252, 1 Dec 22 11:22 /dev/vda1
brw-rw---- 1 root disk 252, 2 Dec 22 11:22 /dev/vda2
brw-rw---- 1 root disk 252, 16 Dec 22 11:22 /dev/vdb
brw-rw---- 1 root disk 252, 32 Dec 22 11:48 /dev/vdc
brw-rw---- 1 root disk 252, 33 Dec 22 11:48 /dev/vdc1
brw-rw---- 1 root disk 252, 34 Dec 22 11:48 /dev/vdc2

vgchange -ay ok. But how can I activate the volumes inside /dev/vdc if they are the same as my actual VM?

  • May be the dm_mod module is not loaded. Can you check whether dm_mod is getting listed in the output of lsmod ? – Sree Dec 21 '14 at 4:46
  • It looks to me as though you're connecting the wrong device. It kind of looks like you're attaching the physical volume of a LVM. Can you edit your post and specify your storage arrangement? Are all VM disks on a logical volume? Or are partitions (not disks) on LVs? – Halfgaar Dec 21 '14 at 8:38
3

In addition to my request for more information: Whether you have a virtual disk on a logical volume or a file, the following will work.

You can do fdisk -lu <diskimage> and see the partition table. Then you can see the offset at which your partition begins (except if it's GPT...). Then use losetup -d /dev/loop0 -o 512 * <startsector> <diskimage>. Then you can mount /dev/loop0 on any point. Make sure you mount with -o ro first, in case something went wrong. And, backup your image if you can.

If you do have a GPT partition table, I don't know from the top of my head how. You can probaly obtain the same info with gdisk of parted

If you have a Xen setup that serves partitions to the guest instead of disks, it's even easier; you can just mount it directly. But, I suspect you don't have that, even though you didn't say.

  • That won't work when the guest is using lvm – psusi Dec 21 '14 at 14:59
  • Are you sure? Why not? – Halfgaar Dec 21 '14 at 17:33
  • Because an lvm physical volume is not a filesystem you can mount; you have to mount the logical volume. – psusi Dec 21 '14 at 17:53
  • oh, you mean if the guest has LVM inside. Yeah, true... – Halfgaar Dec 21 '14 at 22:07
1

Your guest is using lvm so you need ot mount the logical volume, not the physical volume. Make sure vgchange -ay activates it and the logical volumes should appear in /dev/mapper.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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