Mounting / Unmounting KVM Image: Difference between revisions

From Leo's Notes
This page was last edited on 1 September 2019, at 05:08.
m Text replacement - "</code>" to "}}"
m Text replacement - "Category:Linux" to "Category:Linux{{Navbox Linux}}"
Line 20: Line 20:
  # kpartx -d /dev/vol_vm1/kvm101_img
  # kpartx -d /dev/vol_vm1/kvm101_img
   
   
[[Category:Linux]]
[[Category:Linux]]{{Navbox Linux}}

Revision as of 05:08, 1 September 2019

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