Menu

Elsewhere

Contact me

Directly access the file system inside a VM disk image

Consider a situation that you want to change some settings i.e. edit some files
in VM, it’ll be nice if you don’t have to boot it up then log in to make some
changes. So the question becomes how to access the file system inside the VM
disk image file?

To simplify the problem, assume you were using RAW format, if not, convert it by:

Look at the startsector 2048 portion of output, this means that the
filesystem itself starts on sector 2048, and typically this is the /boot
partition. So to access the /boot partition you can mount the image with an
offset parameter, which in this case is 2048 times 512 (the size of
a sector), 1048576. For other partitions, fdisk -l hd.raw will be useful.

$ mount -o loop,offset=1048576 hd.raw /mnt/hdp1

Further, if there is LVM inside, partitions cannot be mounted using ‘mount’. In
such a case the image could be mounted with: bash
$ vgscan
Reading all physical volumes. This may take a while...
Found volume group "<VGName>" using metadata type lvm2
$ vgchange -ay
2 logical volume(s) in volume group "<VGName>" now active
$ mount /dev/<VGName>/<LogicalVolumeName> /mnt/hdpN