libguestfs – Manage virtual machine disk images

libguestfs is a C library tool for creating, accessing and modifying virtual machine disk images. You can look inside the disk images, modify the files they contain, create them from scratch, resize them, and much more.

The easy way to modify files in a VM’s disk image without powering on the VM, you could “mount” the disk image. You then would be able to modify the content of the disk image before unmounting it. libguestfs works with any disk image, including ones created in VMware, KVM, qemu, VirtualBox, Xen, and many other hypervisors, and ones which you have created from scratch.

Manage virtual machine disk images

Overview of libguestfs

There are many tools which use libguestfs:

guestfish – Interactive and scriptable shell.

guestmount – Mount filesystems from any guest or disk image on the host.

guestunmount – unmount guest filesystem

virt-alignment – scan Check alignment of partitions in guests.

virt-builder – quick image builder

virt-cat – Display a file from a guest.

virt-copy-in – Copy files and directories into a guest.

virt-copy-out – Copies files and directories out of a virtual machine disk image or named libvirt domain.

virt-customize – customize virtual machines

virtdf Display – disk usage of a guest.

virt-diff – Differences between files in two virtual machines

virt-edit – Edit a file in a guest.

virtfilesystems – Display the partitions, filesystems, logical volumes etc. in a guest.

virt-inspector – Inspect a guest and produce a report detailing the operating system, version, applications installed and more.

virt-format – erase and make blank disks

virt-ls – List files and directories in a guest.

virt-log – display log files

virt-make-fs – Make a new filesystem.

virt-rescue – Rescue mode for guests.

virt-resize – Resize a guest.

virt-sparsify – Make a disk sparse.

virtsysprep – Reset a guest to “factory configuration”.

virt-tar-in – Copy files from a tarball into a guest.

virt-tar-out – Copy files out of a guest into a tarball.

virt-win-reg – Export and merge Windows Registry entries from a Windows guest

libguestfs-test-tool — test libguestfs

libguestfs-make-fixed-appliance — make libguestfs fixed appliance

BoxGrinder & Oz Projects that can create guests from scratch.

OpenStack Uses libguestfs to inject files into guests.

virt-manager Uses libguestfs to display icons and applications in guests.

virt-v2v & virt-p2v Migrate between physical machines and different hypervisors


How to install libguestfs toolset on Linux

On Debian-based system:

# sudo apt-get install libguestfs-tools

On Red Hat-based system:

# sudo yum install libguestfs-tools



To mount qcow2 image volume at localfolder.

guestmount -a /path/to/qcow2/image -m <device> /local_path

The “-m <device>” option is used to specify a partition within the disk image.

run the following command.

#guestmount -a /images/testcentos.qcow2 -m /dev/sda1 /mnt

By default, the disk image is mounted in “read-write” mode. So you can modify any file in /mnt after mounting it.



Cygwin – Linux Distribution on windows

Open Source tools which provide functionality similar to a Linux distribution on Windows. It is a Windows command line on steroids which runs useful Linux Unix commands. The core part is the Cygwin library which provides the POSIX system calls and environment these programs expect. Cygwin allows easy porting of many Unix/Linux programs without the need for extensive changes to the source code.

It consists of two parts:

  • A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing substantial Linux API functionality.
  • A collection of tools which provide Linux look and feel.
cygwin install

cygwin installation


Use this tool to Rsync or SCP over windows server.

Download and install the Cygwin

Goto Cygwin website Click “Install Cygwin” ⇒ Download the setup program “setup-x86_64.exe” (64-bit Windows) or “setup-x86.exe” (32-bit Windows).

Verify Cygwin

Start the Cygwin Command shell (bash or sh) by running “cygwin.bat”. You shall see the command prompt “$”. You may need to create the users’ group and password files by running the following commands:

$ mkpasswd –l > /etc/passwd
$ mkgroup –l > /etc/group


Install the Cygwin, SSH, PowerShell and Rsync using the following Windows patch script.

Deploy Cygwin, PowerShell, openssh and Rsync v3.2_latest

Download above script and Unzip and run the script. Once the installation has completed, you can use “Cygwin64 Terminal” in Desktop.