libguestfs: access and modify disk images of virtual machines

libguestfs

Perhaps not many know libguestfs, a library written in C and a set of tools that allow you to access and modify the virtual disk images used in virtual machines. In addition, you will be able to work with several Linux KVM-based virtualization platforms, and the VM images will be mounted directly on the host using the FUSE module and the guestmount/guestunmount tools.

Another nice thing about libguestfs is that can access almost any FS, or file system, and that includes all Linux (ext2, ext3, ext4, XFS, btrfs,…), MS Windows (VFAT and NTFS), macOS (HFS and HFS+), as well as BSD, and even LVM2 volume management. All this in both MBR and GPT.

As for virtual disk types which you can access, can be:

  • qcow2
  • VirtualBox .vdi
  • VMWare .vmdk
  • Hyper-V .vhd and .vhdx

You can also access and modify files, local devices, ISO images, SD memory cards, or do it remotely via protocols on the table:

  • FTP
  • HTTP
  • SSH
  • iSCSI
  • NBD
  • GlusterFS
  • front
  • sheep dog
  • etc.

On the other hand, libguestfs does not need privileges, which is also interesting. Thanks to this project, you will have various command line tools like guestfish, guestmount, guestunmount, virt-rescue to fix unbootable VMs, virt-cat, virt-tar, etc.

libguestfs also acts as an API to be able to link management programs in various programming languages:

  • C
  • C++
  • Perl
  • Python
  • Ruby
  • Java
  • PHP
  • Haskell
  • Erlang
  • Moon
  • C#
  • etc.

You can also use it from scripts, which is very practical when administering systems. Also, this project by Richard Jones can be installed from the repos of many of the well-known distros in this way:

  • Debian / Ubuntu and derivatives
sudo apt install libguestfs-tools

  • Fedora/CentOS/RHEL and derivatives
sudo dnf install libguestfs

  • Arch Linux and derivatives
sudo pacman -Sy libguestfs

By the way, if you're using libvirt and you try to invoke any of the utilities or tools included in libguestfs, you will receive a error like this:

libguestfs: error: could not create appliance through libvirt.

La solution it's as simple as exporting a variable as "direct" like so:

export LIBGUESTFS_BACKEND=direct

More information - Official Web site


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.