How To Mount VM Images with Guestmount?

guestmount is a tool used to mount VM images. This VM images can be different formats like qcow, vmdk, vdi, etc. In this tutorial, we will examine different use cases about guestmount.

Mount Disk Image

We will start by mounting given image partition to the specified directory. We will provide the image with the -a option. -m option will be used to point the partition we want to mount which resides in the image. The last parameter to the guestmount is the local directory we want to mount. In this example we will mount image cirros.. partition sda1 into the local directory test2

$ guestmount -a cirros-0.3.0-i386-disk.img -m /dev/sda1 test2
$ ls test2/
bin boot dev etc home init initrd.img lib linuxrc lost+found mnt old-root opt proc root run sbin sys tmp usr var vmlinuz

Mount Readonly

Normally guestmount mounts the disk or partition with read-write options if you want to mount read-only use -r option. We can not write anything to this image which will make safe for modifications.

$ guestmount -r -a cirros-0.3.0-i386-disk.img -m /dev/sda1 test2

Automatically Mount

Specifying partition is not a must. We can use -i option to automatically look for partition with guestmount.

$ guestmount -a cirros-0.3.0-i386-disk.img -i test2

Enable SELinux

Normally SELinux will not be enabled while using guestmount. We can enable SELinux support on-disk image with --selinux option.

$ guestmount -a cirros-0.3.0-i386-disk.img -i test2 --selinux

Provide Mount Options

We can specify mount options about image partitions with the -o option. In this example, we will enable to read this partition directory by other users with allow_user

$ guestmount -a cirros-0.3.0-i386-disk.img -i test2 -o allow_other

1 thought on “How To Mount VM Images with Guestmount?”

Leave a Comment