Mounting / Unmounting KVM Image: Difference between revisions

From Leo's Notes
This page was last edited on 24 February 2017, at 19:12.
mNo edit summary
m Text replacement - "<code>" to "{{code|"
Line 1: Line 1:
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>.
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:
To list partitions in the disk image:
Line 6: Line 6:
  vol_vm1-kvm101_img2 : 0 1048576 /dev/vol_vm1/kvm101_img 61861504
  vol_vm1-kvm101_img2 : 0 1048576 /dev/vol_vm1/kvm101_img 61861504


Knowing that the first partition is <code>/</code> and the second is the swap, we will attempt to mount the first partition.
Knowing that the first partition is {{code|/</code> and the second is the swap, we will attempt to mount the first partition.


To map the parititions:
To map the parititions:

Revision as of 19:12, 24 February 2017

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.

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 {{code|/ 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