22.4. The guestfish Shell
guestfish --ro -a /path/to/disk/image
libguestfsto edit a live guest virtual machine, and attempting to will result in irreversible disk corruption.
guestfish --ro -a /path/to/disk/imageWelcome to guestfish, the guest filesystem shell for editing virtual machine filesystems and disk images. Type: 'help' for help on commands 'man' to read the manual 'quit' to quit the shell ><fs>
22.4.1. Viewing File Systems with guestfish
18.104.22.168. Manual Listing and Viewing
list-filesystemscommand will list file systems found by libguestfs. This output shows a Red Hat Enterprise Linux 4 disk image:
><fs> run ><fs> list-filesystems /dev/vda1: ext3 /dev/VolGroup00/LogVol00: ext3 /dev/VolGroup00/LogVol01: swap
file. You can get more information and help on any command by typing
helpcommand, as shown in the following output:
><fs> help vfs-type NAME vfs-type - get the Linux VFS type corresponding to a mounted device SYNOPSIS vfs-type mountable DESCRIPTION This command gets the filesystem type corresponding to the filesystem on "device". For most filesystems, the result is the name of the Linux VFS module which would be used to mount this filesystem if you mounted it without specifying the filesystem type. For example a string such as "ext3" or "ntfs".
tar-outto view and download files and directories.
cdcommand to change directories. All paths must be fully qualified starting at the top with a forward slash (/) character. Use the Tab key to complete paths.
22.214.171.124. Via guestfish inspection
guestfish --ro -a /path/to/disk/image -iWelcome to guestfish, the guest filesystem shell for editing virtual machine filesystems and disk images. Type: 'help' for help on commands 'man' to read the manual 'quit' to quit the shell Operating system: Red Hat Enterprise Linux AS release 4 (Nahant Update 8) /dev/VolGroup00/LogVol00 mounted on / /dev/vda1 mounted on /boot ><fs> ll / total 210 drwxr-xr-x. 24 root root 4096 Oct 28 09:09 . drwxr-xr-x 21 root root 4096 Nov 17 15:10 .. drwxr-xr-x. 2 root root 4096 Oct 27 22:37 bin drwxr-xr-x. 4 root root 1024 Oct 27 21:52 boot drwxr-xr-x. 4 root root 4096 Oct 27 21:21 dev drwxr-xr-x. 86 root root 12288 Oct 28 09:09 etc ...
runcommand is not necessary when using the
-ioption works for many common Linux guest virtual machines.
126.96.36.199. Accessing a guest virtual machine by name
virsh list --all). Use the
-doption to access a guest virtual machine by its name, with or without the
guestfish --ro -d GuestName -i
22.4.2. Adding Files with guestfish
guestfish -a disk.img
guestfish -a file:///directory/disk.img
guestfish -a nbd://example.com[:port]
guestfish -a nbd://example.com[:port]/exportname
guestfish -a nbd://?socket=/socket
guestfish -a nbd:///exportname?socket=/socket
guestfish -a rbd:///pool/disk
guestfish -a rbd://example.com[:port]/pool/disk
22.4.3. Modifying Files with guestfish
/boot/grub/grub.conffile. When you are sure the guest virtual machine is shut down you can omit the
--roflag in order to get write access via a command such as:
guestfish -d RHEL3 -iWelcome to guestfish, the guest filesystem shell for editing virtual machine filesystems and disk images. Type: 'help' for help on commands 'man' to read the manual 'quit' to quit the shell Operating system: Red Hat Enterprise Linux AS release 3 (Taroon Update 9) /dev/vda2 mounted on / /dev/vda1 mounted on /boot ><fs> edit /boot/grub/grub.conf
emacs. Many commands also exist for creating files and directories, such as
22.4.4. Other Actions with guestfish
22.4.5. Shell Scripting with guestfish
#!/bin/bash - set -e guestname="$1" guestfish -d "$guestname" -i <<'EOF' write /etc/motd "Welcome to Acme Incorporated." chmod 0644 /etc/motd EOF
22.4.6. Augeas and libguestfs Scripting
#!/bin/bash - set -e guestname="$1" guestfish -d "$1" -i --ro <<'EOF' aug-init / 0 aug-get /files/etc/sysconfig/keyboard/LAYOUT EOF
#!/bin/bash - set -e guestname="$1" guestfish -d "$1" -i <<'EOF' aug-init / 0 aug-set /files/etc/sysconfig/keyboard/LAYOUT '"gb"' aug-save EOF
--rooption has been removed in the second example, giving the ability to write to the guest virtual machine.
aug-getcommand has been changed to
aug-setto modify the value instead of fetching it. The new value will be
"gb"(including the quotes).
aug-savecommand is used here so Augeas will write the changes out to disk.
guestfish -N fs
><fs> copy-out /home /tmp/home