Mounting / Unmounting KVM Image: Difference between revisions

From Leo's Notes
This page was last edited on 21 May 2013, at 18:41.
Created page with "Suppose you have a KVM virtual machine using a virtual disk located in a LV group. To gain access to the data, use <code>kpartx</code>. To list partitions in the disk image:..."
 
mNo edit summary
Line 9: Line 9:


To map the parititions:
To map the parititions:
  # kpartx -av /dev/vol_vm1_kvm101_img
  # kpartx -av /dev/vol_vm1/kvm101_img
  add map vol_vm1-kvm101_img1 (253:6): 0 61861441 linear /dev/vol_vm1/kvm101_img 63
  add map vol_vm1-kvm101_img1 (253:6): 0 61861441 linear /dev/vol_vm1/kvm101_img 63
  add map vol_vm1-kvm101_img2 (253:7): 0 1048576 linear /dev/vol_vm1/kvm101_img 61861504
  add map vol_vm1-kvm101_img2 (253:7): 0 1048576 linear /dev/vol_vm1/kvm101_img 61861504

Revision as of 18:41, 21 May 2013

Suppose you have a KVM virtual machine using a virtual disk located in a LV group. To gain access to the data, use kpartx.

To list partitions in the disk image:

# kpartx -l /dev/vol_vm1/kvm101_img
vol_vm1-kvm101_img1 : 0 61861441 /dev/vol_vm1/kvm101_img 63
vol_vm1-kvm101_img2 : 0 1048576 /dev/vol_vm1/kvm101_img 61861504

Knowing that the first partition is / and the second is the swap, we will attempt to mount the first partition.

To map the parititions:

# kpartx -av /dev/vol_vm1/kvm101_img
add map vol_vm1-kvm101_img1 (253:6): 0 61861441 linear /dev/vol_vm1/kvm101_img 63
add map vol_vm1-kvm101_img2 (253:7): 0 1048576 linear /dev/vol_vm1/kvm101_img 61861504

To mount the newly mapped partitions:

# mount -t ext4 -o ro /dev/mapper/vol_vm1-kvm101_img1 /mnt/vm101

Once completed, simply unmount and unmap the image:

# umount /mnt/vm101
# kpartx -d /dev/vol_vm1/kvm101_img