VirTips wind between the clouds

Tag Archives: Libguestfs

Editing files inside vm image

There are some situations when you have to edit file from vm image and you can’t or don’t want to start virtual machine to do it.

Old way

If you have raw image without partitons you can just mount it via loop device:

If you have paritions it’s getting more complicated. You can play with offset option for mount command or for example you can use program called kpartx.

Then you can mount partitions from /mnt/mappert/loop0p1 and so on. It’s getting even more complicated when you are using no raw image formats, for example qcow2. Then you can use program called qemu-nbd.

virt-edit for rescue

All this are old days. Currently you can just use already mentioned on this blog project libguestfs. There is a program virt-edit. Just run:

Change file, save it and quit program. That’s all what you need.

You can also try guestfish and virt-rescue programs.

Getting disk space usage from running VM.

There is amazing tool which may help in many administrative tasks. It is called libguestfs. To get information about disk space usage you can use program virt-df.
To get disks stats from all running vms just run(libvirt required):

To get disks stats from specific vm:

If you do not have libvirt, you can manually specify disk

Libguestfs is mainly written in C, but it provides bindings for other languages : C++, Erlang, Java, OCaml, Perl, Python, Ruby.
For example to get  disk stats in python you can use this code:



Get every new post delivered to your Inbox

Join other followers