Skip to content

Instantly share code, notes, and snippets.

@gwarf
Last active March 14, 2019 15:39
Show Gist options
  • Save gwarf/bb826af336dc2c72c14043d1917b884d to your computer and use it in GitHub Desktop.
Save gwarf/bb826af336dc2c72c14043d1917b884d to your computer and use it in GitHub Desktop.
Mount a VM image

Mount a VM image

raw image disk

losetup /dev/loop0 image.img
# or
losetup -f file.raw
# if /dev/loop0p1 does not exist
kpartx -a /dev/loop0
# Mount part
mount /dev/loop0p1 /mnt/image
# Stopping
kpartx -d /dev/loop0
losetup -d /dev/loop0

qcow2 image disk

modprobe nbd max_part=63
qemu-nbd -c /dev/nbd0 file.qcow2
mount /dev/nbd0p1 /mnt/image
# Stopping
nbd-client -d /dev/nbd0

Using guestfish CLI applciation

guestfish
add-ro /apth/to/image.disk
run
list-filesysmtems
cat /etc/fstab
exit

Converting qcow2 to raw

qemu-img convert -f qcow2 /home/your_current_image.qcow2 -O raw /home/your_new_image.raw

With LVM

kpartx -av /dev/VolGroup00/disk_image
vgscan
# vgrename if clashing with VG on host
# Activate guest Vol if needed
vgchange -ay VolGroupXX
lvscan
mount /dev/VolGroupXX/disk_image /mnt
# Cleaning
umount /mnt
vgchange -an VolGroupXX
kpartk -dv /dev/VolGroup00/disk_image
pvscan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment