guestfs-recipes(1) Virtualization Support guestfs-recipes(1) (NAME) guestfs-recipes - libguestfs guestfish virt (DESCRIPTION) libguestfs guestfish(1) virt . guestfish SSH HTTP FTP NBD iSCSI . <> guestfish(1) . libguestfs >= 1.22 qemu >= 1.5 . setuid : <> virt-ls(1). : https://rwmj.wordpress.com/2013/05/16/scanning-offline-guests-using-openscap-and-guestmount/#content Windows XP guestfish(1) Windows XP . Windows . https://lists.fedoraproject.org/pipermail/virt/2011-May/002655.html https://lists.fedoraproject.org/pipermail/virt/2011-May/002658.html LV : guestfish --ro -a disk.img run : checksum-device md5 /dev/sda1 "md5" . <> guestfs(3) . /dev/sda1 << >> . /dev/sda (LV) RAID . : guestfish --ro -a disk.img -i checksum sha256 /etc/passwd Windows: guestfish --ro -a disk.img -i \ checksum sha256 'win:\windows\system32\config\SOFTWARE' cp(1) dd(1) virt virt-sysprep(1) virt-sparsify(1) virt-resize(1) . CD-ROM / DVD / ISO (Convert a CD-ROM / DVD / ISO to a tarball) cd.iso cd.tar.gz : guestfish --ro -a cd.iso -m /dev/sda tgz-out / cd.tar.gz /files : guestfish --ro -a cd.iso -m /dev/sda tgz-out /files cd.tar.gz / (Convert from one format/filesystem to another) / / / (volume manager) . ext3 (logical volume) (sparse raw-format) . : truncate -s 10G target.img virt-format -a target.img --partition=mbr --lvm --filesystem=ext3 guestfish (pipe) : guestfish --ro -a source.img -m /dev/sda1 -- tar-out / - | \ guestfish --rw -a target.img -m /dev/VG/LV -- tar-in - / : guestfish --ro -a target.img -m /dev/VG/LV > ll / . ( ) . DVD USB (Convert Windows DVD to bootable USB key) http://rwmj.wordpress.com/2013/05/09/tip-convert-a-windows-dvd-iso-to-a-bootable-usb-key-using-guestfish/#content (Convert Xen-style partitionless image to partitioned disk image) Xen . KVM ( ) . guestfish : guestfish > add-ro input.img > sparse output.img 10G # adjust the output size > run # Create a partition table on the output disk: > part-init /dev/sdb mbr > part-add /dev/sdb p 2048 -2048 # Copy the data to the target partition: > copy-device-to-device /dev/sda /dev/sdb1 sparse:true # Optionally resize the target filesystem. Use ntfsresize # for Windows guests: > resize2fs /dev/sdb1 . initramfs ( ). guestfish "syslinux" "extlinux" SYSLINUX . (Create empty disk images) virt-format(1) . virt-make-fs(1) . (VFDs) . -N guestfish(1) . . https://rwmj.wordpress.com/2010/09/08/new-guestfish-n-options-in-1-5-9/#content virt-builder(1) . ( ) (Delete a file (or other simple file operations)) guestfish . : guestfish -a disk.img -i rm /file/to/delete touch ( ): guestfish -a disk.img -i touch /file/to/touch (stat) . --ro . guestfish --ro -a disk.img -i stat /file/to/stat . guestfish(1) "guestfish -h" ..SH " " libguestfs >= 1.26 virt-diff(1) ( ) . libguestfs virt-ls(1) . systemd "systemctl mask ..." . "cloud-init" : guestfish -a disk.img -i \ ln-sf /dev/null /etc/systemd/system/cloud-init.service tmp-on-tmpfs: guestfish -a disk.img -i \ ln-sf /dev/null /etc/systemd/system/tmp.mount . virt-ls(1) systemd : virt-ls -a /tmp/fedora-19.img -R /lib/systemd/system FUSE Windows FUSE (/C/... /D/... ) . guestmount(1) Perl : #!/usr/bin/perl -w use strict; use Sys::Guestfs; $| = 1; die "usage: $0 mountpoint disk.img" if @ARGV < 2; my $mp = shift @ARGV; my $g = new Sys::Guestfs; $g->add_drive_opts ($_) foreach @ARGV; $g->launch; my @roots = $g->inspect_os; die "$0: no operating system found" if @roots != 1; my $root = $roots[0]; die "$0: not Windows" if $g->inspect_get_type ($root) ne "windows"; my %map = $g->inspect_get_drive_mappings ($root); foreach (keys %map) { $g->mkmountpoint ("/$_"); eval { $g->mount ($map{$_}, "/$_") }; warn "$@ (ignored)\n" if $@; } $g->mount_local ($mp); print "filesystem ready on $mp\n"; $g->mount_local_run; $g->shutdown; : $ mkdir /tmp/mnt $ ./drive-letters.pl /tmp/mnt windows7.img filesystem ready on /tmp/mnt : $ cd /tmp/mnt $ ls C D $ cd C $ ls Documents and Settings PerfLogs ProgramData Program Files [etc] $ cd ../.. $ guestunmount /tmp/mnt "download" guestfish(1) ( LV RAID ): guestfish --ro -a disk.img run : download /dev/sda1 sda1.img guestfish --ro -d Guest run : download /dev/vg_guest/lv_root lv.img stdout "-" : guestfish --ro -a disk.img run : download /dev/sda1 - | gzip > sda1.gz virt-filesystems(1) . <> . grub : o . o . o . virt-edit(1) grub : virt-edit -d BrokenGuest /boot/grub2/grub.cfg virt-rescue(1) : virt-rescue -d BrokenGuest /home (VM) virt-copy-out(1) : virt-copy-out -d Guest /home . : o . . o "home" . "win:" : virt-copy-out -d WinGuest 'win:c:\windows\system32\config' . : virt-tar-out -d Guest /home - | gzip --best > home.tar.gz . FAQ : http://libguestfs.org/FAQ.html#backup initramfs (initrd) initramfs . . . 1.24 libguestfs virt-builder(1) initramfs : mkdir outputdir virt-builder --get-kernel disk.img -o outputdir ls -lh outputdir : #!/bin/sh - set -e vm="$1" dir=/home eval $(guestfish --ro -d "$vm" -i --listen) for d in $(guestfish --remote ls "$dir"); do echo -n "$dir/$d" echo -ne '\t' guestfish --remote du "$dir/$d"; done | sort -nr -k 2 guestfish --remote exit DHCP DHCP . https://rwmj.wordpress.com/2011/03/31/tip-code-for-getting-dhcp-address-from-a-virtual-machine-disk-image/#content libguestfs virt-dhcp-address.c . product-name.sh : #!/bin/sh - set -e eval "$(guestfish --ro -d "$1" --i --listen)" root="$(guestfish --remote inspect-get-roots)" guestfish --remote inspect-get-product-name "$root" guestfish --remote exit : $ product-name.sh fedora-40.img Fedora Linux 40 (Forty) "xpath" XPath XML virt-inspector(1) : $ virt-inspector -a fedora-40.img > xml $ xpath -e '//product_name' < xml Found 1 nodes in stdin: -- NODE -- Fedora Linux 40 (Forty) . https://rwmj.wordpress.com/2010/10/30/tip-use-augeas-to-get-the-default-boot-kernel-for-a-vm/#content Augeas : o o o NTP o o http://augeas.net.SH " (Hanging guests)" libguestfs : 1. virt-cat: virt-cat Guest /var/log/messages | less 2. Windows Event Log ( Windows Vista ): https://rwmj.wordpress.com/2011/04/17/decoding-the-windows-event-log-using-guestfish/#content 3. : https://rwmj.wordpress.com/2012/02/27/using-libguestfs-to-find-out-why-a-windows-guest-was-hanging/#content . (Hex-dumping sectors from the guest) (Master Boot Record / ): guestfish --ro -a disk.img run : pread-device /dev/sda 0x200 0 | hexdump -C (0x200 = 512 ) N "N" : guestfish --ro -a disk.img \ run : pread-device /dev/sda 0x200 $((N*0x200)) | hexdump -C (Hex-editing sectors in the guest) (Master Boot Record / ): guestfish --rw -a disk.img run : hexedit /dev/sda 0x200 (RPM ) (Install packages (RPMs, Debian packages) in a guest) 1.26 libguestfs virt-builder(1) virt-customize(1) virt-sysprep(1) --install . ( virt-customize virt-builder ). : virt-builder fedora-20 --install emacs (Install packages from an alternate repository) 1.26 libguestfs --edit virt-builder(1) virt-customize(1) virt-sysprep(1) . updates-testing Fedora : virt-builder fedora-20 \ --edit '/etc/yum.repos.d/fedora-updates-testing.repo: s/enabled=0/enabled=1/' \ --install emacs SYSLINUX (Install SYSLINUX bootloader in a guest) SYSLINUX . (bootable) SYSLINUX guestfish "syslinux" ( FAT) "extlinux" ( ext2/3/4 btrfs) . /dev/sda1 /boot /boot/vmlinuz /dev/sda3 . FAT "syslinux" . syslinux.cfg . SYSLINUX http://www.syslinux.org : DEFAULT linux LABEL linux SAY Booting the kernel KERNEL vmlinuz INITRD initrd APPEND ro root=/dev/sda3 Master Boot Record syslinux ( /usr/share/syslinux/mbr.bin). guestfish -a disk.img -i # Upload the master boot record and configuration file: > upload ..../mbr.bin /boot/mbr.bin > upload ..../syslinux.cfg /boot/syslinux.cfg # Put the MBR into the boot sector: > copy-file-to-device /boot/mbr.bin /dev/sda size:440 # Install syslinux on the first partition: > extlinux /boot # Set the first partition as bootable: > part-set-bootable /dev/sda 1 true : http://rwmj.wordpress.com/2013/04/04/new-in-libguestfs-use-syslinux-or-extlinux-to-make-bootable-guests/#content (List applications installed in a VM) list-apps.sh : #!/bin/sh - set -e eval "$(guestfish --ro -d "$1" --i --listen)" root="$(guestfish --remote inspect-get-roots)" guestfish --remote inspect-list-applications "$root" guestfish --remote exit : # list-apps.sh WinGuest [0] = { app_name: Mozilla Firefox (3.6.12) app_display_name: Mozilla Firefox (3.6.12) app_epoch: 0 app_version: 3.6.12 (en-GB) app_release: app_install_path: C:\Program Files\Mozilla Firefox app_trans_path: app_publisher: Mozilla app_url: http://www.mozilla.com/en-GB app_source_package: app_summary: app_description: Mozilla Firefox } [1] = { app_name: VLC media player app_display_name: VLC media player 1.1.5 app_epoch: 0 app_version: 1.1.5 app_release: app_install_path: C:\Program Files\VideoLAN\VLC app_trans_path: app_publisher: VideoLAN app_url: http://www.videolan.org app_source_package: app_summary: app_description: } ( libvirt) "-d "$1"" "-a "$1"" . : virt-inspector(1)..SH " VM" virt-ls(1) . VM VM . https://rwmj.wordpress.com/2010/12/10/tip-list-services-in-a-windows-guest/#content (sparse) virt-sparsify(1) . virt-df(1) . . http://web.archive.org/web/20130214073726/http://virt-tools.org/learning/advanced-virt-df Windows Event Log Vista ( ) guestfish(1) Windows Event Log Windows Vista . https://rwmj.wordpress.com/2011/04/17/decoding-the-windows-event-log-using-guestfish/#content (Linux) -e virt-edit(1) . root : virt-edit -d domname /etc/passwd -e 's/^root:.*?:/root::/' virt-edit -a disk.img /etc/passwd -e 's/^root:.*?:/root::/' Administrator () Administrator VM (command prompt) : https://mdbooth.wordpress.com/2010/10/18/resetting-a-windows-guests-administrator-password-with-guestfish Sysprep (Windows) <> libguestfs . Aeolus Oz ( libguestfs) . virt-sysprep(1) . https://github.com/clalancette/oz https://www.redhat.com/archives/virt-tools-list/2011-May/msg00019.html (Live CD) (Live CD) . guestfish(1) . https://rwmj.wordpress.com/2009/07/15/unpack-the-russian-doll-of-a-f11-live-cd/#content ( / copying in) ( / copying out) . https://rwmj.wordpress.com/2010/12/02/tip-uploading-and-downloading/#content guestfish(1) VM LV RAID : guestfish --rw -a disk.img run : upload sda1.img /dev/sda1 guestfish --rw -d Guest run : upload lv.img /dev/vg_guest/lv_root . libguestfs - . guestfish : guestfish --rw -d Guest run : \ upload lv.img /dev/vg_guest/lv_root : \ resize2fs /dev/vg_guest/lv_root ( NTFS "ntfsresize" ). libguestfs VMware ESX libguestfs guestfish(1) virt VMware ESX VMware VMFS sshfs . https://rwmj.wordpress.com/2011/05/10/tip-use-libguestfs-on-vmware-esx-guests/#content (SEE ALSO) guestfs(3), guestfish(1), guestfs-examples(3), guestfs-erlang(3), guestfs-golang(3), guestfs-java(3), guestfs-lua(3), guestfs-ocaml(3), guestfs-perl(3), guestfs-python(3), guestfs-ruby(3), http://libguestfs.org. (AUTHORS) Richard W.M. Jones ("rjones at redhat dot com") (COPYRIGHT) Copyright (C) 2009-2025 Red Hat Inc. (LICENSE) . ..SH " (BUGS)" libguestfs : https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools libguestfs : https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools : o libguestfs. o libguestfs ( : ). o . o libguestfs-test-tool(1) . libguestfs-1.60.1 2026-07-14 guestfs-recipes(1)