5 guestfish - the libguestfs filesystem interactive shell
9 guestfish [--options] [commands]
11 guestfish -i libvirt-domain
13 guestfish -i disk-image(s)
17 =head2 From shell scripts
19 Create a new C</etc/motd> file in a guest:
24 mount /dev/VolGroup00/LogVol00 /
25 write_file /etc/motd "Hello users" 0
28 List the LVs in a guest:
36 =head2 On the command line
38 List the LVM PVs in a guest image:
40 guestfish add disk.img : run : pvs
42 Remove C</boot/grub/menu.lst> (in reality not such a great idea):
44 guestfish --add disk.img \
45 --mount /dev/VolGroup00/LogVol00 \
46 --mount /dev/sda1:/boot \
47 rm /boot/grub/menu.lst
49 =head2 As an interactive shell
53 Welcome to guestfish, the libguestfs filesystem interactive shell for
54 editing virtual machine filesystems.
56 Type: 'help' for help with commands
57 'quit' to quit the shell
61 =head2 As a script interpreter
63 #!/usr/bin/guestfish -f
64 alloc /tmp/output.img 10M
66 sfdisk /dev/sda 0 0 0 ,
71 eval `guestfish --listen`
72 guestfish --remote cmd
76 Guestfish is a shell and command-line tool for examining and modifying
77 virtual machine filesystems. It uses libguestfs and exposes all of
78 the functionality of the guestfs API, see L<guestfs(3)>.
86 Displays general help on options.
88 =item B<-h> | B<--cmd-help>
90 Lists all available guestfish commands.
92 =item B<-h cmd> | B<--cmd-help cmd>
94 Displays detailed help on a single command C<cmd>.
96 =item B<-a image> | B<--add image>
98 Add a block device or virtual machine image to the shell.
100 =item B<-D> | B<--no-dest-paths>
102 Don't tab-complete paths on the guest filesystem. It is useful to be
103 able to hit the tab key to complete paths on the guest filesystem, but
104 this causes extra "hidden" guestfs calls to be made, so this option is
105 here to allow this feature to be disabled.
107 =item B<-f file> | B<--file file>
109 Read commands from C<file>. To write pure guestfish
112 #!/usr/bin/guestfish -f
114 =item B<-i> | B<--inspector>
116 Run virt-inspector on the named libvirt domain or list of disk
117 images. If virt-inspector is available and if it can identify
118 the domain or disk images, then partitions will be mounted
119 correctly at start-up.
121 Typical usage is either:
125 (for an inactive libvirt domain called I<myguest>), or:
127 guestfish --ro -i myguest
129 (for active domains, readonly), or specify the block device directly:
131 guestfish -i /dev/Guests/MyGuest
133 You cannot use I<-a>, I<-m>, I<--listen>, I<--remote> or I<--selinux>
134 in conjunction with this option, and options other than I<--ro> might
135 not behave correctly.
137 See also: L<virt-inspector(1)>.
141 Fork into the background and listen for remote commands. See section
142 I<REMOTE CONTROL GUESTFISH OVER A SOCKET> below.
144 =item B<-m dev[:mountpoint]> | B<--mount dev[:mountpoint]>
146 Mount the named partition or logical volume on the given mountpoint.
148 If the mountpoint is omitted, it defaults to C</>.
150 You have to mount something on C</> before most commands will work.
152 If any C<-m> or C<--mount> options are given, the guest is
153 automatically launched.
155 =item B<-n> | B<--no-sync>
157 Disable autosync. This is enabled by default. See the discussion
158 of autosync in the L<guestfs(3)> manpage.
160 =item B<--remote[=pid]>
162 Send remote commands to C<$GUESTFISH_PID> or C<pid>. See section
163 I<REMOTE CONTROL GUESTFISH OVER A SOCKET> below.
165 =item B<-r> | B<--ro>
167 This changes the C<-m> option so that mounts are done read-only
168 (see C<guestfs_mount_ro> in the L<guestfs(3)> manpage).
172 Enable SELinux support for the guest. See L<guestfs(3)/SELINUX>.
174 =item B<-v> | B<--verbose>
176 Enable very verbose messages. This is particularly useful if you find
179 =item B<-V> | B<--version>
181 Display the guestfish / libguestfs version number and exit.
185 Echo each command before executing it.
189 =head1 COMMANDS ON COMMAND LINE
191 Any additional (non-option) arguments are treated as commands to
194 Commands to execute should be separated by a colon (C<:>), where the
195 colon is a separate parameter. Thus:
197 guestfish cmd [args...] : cmd [args...] : cmd [args...] ...
199 If there are no additional arguments, then we enter a shell, either an
200 interactive shell with a prompt (if the input is a terminal) or a
201 non-interactive shell.
203 In either command line mode or non-interactive shell, the first
204 command that gives an error causes the whole shell to exit. In
205 interactive mode (with a prompt) if a command fails, you can continue
208 =head1 USING launch (OR run)
210 As with L<guestfs(3)>, you must first configure your guest by adding
211 disks, then launch it, then mount any disks you need, and finally
212 issue actions/commands. So the general order of the day is:
234 C<run> is a synonym for C<launch>. You must C<launch> (or C<run>)
235 your guest before mounting or performing any other commands.
237 The only exception is that if the C<-m> or C<--mount> option was
238 given, the guest is automatically run for you (simply because
239 guestfish can't mount the disks you asked for without doing this).
243 You can quote ordinary parameters using either single or double
246 add "file with a space.img"
252 A few commands require a list of strings to be passed. For these, use
253 a space-separated list, enclosed in quotes. For example:
255 vgcreate VG "/dev/sda1 /dev/sdb1"
257 =head1 WILDCARDS AND GLOBBING
259 Neither guestfish nor the underlying guestfs API performs
260 wildcard expansion (globbing) by default. So for example the
261 following will not do what you expect:
265 Assuming you don't have a directory literally called C</home/*>
266 then the above command will return an error.
268 To perform wildcard expansion, use the C<glob> command.
272 runs C<rm-rf> on each path that matches (ie. potentially running
273 the command many times), equivalent to:
279 C<glob> only works on simple guest paths and not on device names.
281 If you have several parameters, each containing a wildcard, then glob
282 will perform a cartesian product.
286 Any line which starts with a I<#> character is treated as a comment
287 and ignored. The I<#> can optionally be preceeded by whitespace,
288 but B<not> by a command. For example:
294 Blank lines are also ignored.
296 =head1 RUNNING COMMANDS LOCALLY
298 Any line which starts with a I<!> character is treated as a command
299 sent to the local shell (C</bin/sh> or whatever L<system(3)> uses).
303 tgz-out /remote local/remote-data.tar.gz
305 will create a directory C<local> on the host, and then export
306 the contents of C</remote> on the mounted filesystem to
307 C<local/remote-data.tar.gz>. (See C<tgz-out>).
311 Use C<command E<lt>spaceE<gt> | command> to pipe the output of the
312 first command (a guestfish command) to the second command (any host
313 command). For example:
315 cat /etc/passwd | awk -F: '$3 == 0 { print }'
317 (where C<cat> is the guestfish cat command, but C<awk> is the host awk
318 program). The above command would list all accounts in the guest
319 filesystem which have UID 0, ie. root accounts including backdoors.
322 hexdump /bin/ls | head
323 list-devices | tail -1
325 The space before the pipe symbol is required, any space after the pipe
326 symbol is optional. Everything after the pipe symbol is just passed
327 straight to the host shell, so it can contain redirections, globs and
328 anything else that makes sense on the host side.
330 To use a literal argument which begins with a pipe symbol, you have
335 =head1 HOME DIRECTORIES
337 If a parameter starts with the character C<~> then the tilde may be
338 expanded as a home directory path (either C<~> for the current user's
339 home directory, or C<~user> for another user).
341 Note that home directory expansion happens for users known I<on the
342 host>, not in the guest filesystem.
344 To use a literal argument which begins with a tilde, you have to quote
349 =head1 EXIT ON ERROR BEHAVIOUR
351 By default, guestfish will ignore any errors when in interactive mode
352 (ie. taking commands from a human over a tty), and will exit on the
353 first error in non-interactive mode (scripts, commands given on the
356 If you prefix a command with a I<-> character, then that command will
357 not cause guestfish to exit, even if that (one) command returns an
360 =head1 REMOTE CONTROL GUESTFISH OVER A SOCKET
362 Guestfish can be remote-controlled over a socket. This is useful
363 particularly in shell scripts where you want to make several different
364 changes to a filesystem, but you don't want the overhead of starting
365 up a guestfish process each time.
367 Start a guestfish server process using:
369 eval `guestfish --listen`
371 and then send it commands by doing:
373 guestfish --remote cmd [...]
375 To cause the server to exit, send it the exit command:
377 guestfish --remote exit
379 Note that the server will normally exit if there is an error in a
380 command. You can change this in the usual way. See section I<EXIT ON
383 =head2 CONTROLLING MULTIPLE GUESTFISH PROCESSES
385 The C<eval> statement sets the environment variable C<$GUESTFISH_PID>,
386 which is how the C<--remote> option knows where to send the commands.
387 You can have several guestfish listener processes running using:
389 eval `guestfish --listen`
391 eval `guestfish --listen`
394 guestfish --remote=$pid1 cmd
395 guestfish --remote=$pid2 cmd
397 =head2 STANDARD OUTPUT DURING REMOTE CONTROL
399 Because of limitations in the C<eval> statement, stdout from the
400 listener is currently redirected to C</dev/null>.
404 =head2 REMOTE CONTROL DETAILS
406 Remote control happens over a Unix domain socket called
407 C</tmp/.guestfish-$UID/socket-$PID>, where C<$UID> is the effective
408 user ID of the process, and C<$PID> is the process ID of the server.
410 Guestfish client and server versions must match exactly.
412 =head1 GUESTFISH COMMANDS
414 The commands in this section are guestfish convenience commands, in
415 other words, they are not part of the L<guestfs(3)> API.
417 =head2 alloc | allocate
421 This creates an empty (zeroed) file of the given size, and then adds
422 so it can be further examined.
424 For more advanced image creation, see L<qemu-img(1)> utility.
426 Size can be specified (where C<nn> means a number):
430 =item C<nn> or C<nn>K or C<nn>KB
432 number of kilobytes, eg: C<1440> = standard 3.5in floppy
434 =item C<nn>M or C<nn>MB
438 =item C<nn>G or C<nn>GB
444 number of 512 byte sectors
452 This echos the parameters to the terminal.
454 =head2 edit | vi | emacs
458 This is used to edit a file. It downloads the file, edits it
459 locally using your editor, then uploads the result.
461 The editor is C<$EDITOR>. However if you use the alternate
462 commands C<vi> or C<emacs> you will get those corresponding
465 NOTE: This will not work reliably for large files
466 (> 2 MB) or binary files containing \0 bytes.
472 Expand wildcards in any paths in the args list, and run C<command>
473 repeatedly on each matching path.
475 See section WILDCARDS AND GLOBBING.
482 Without any parameter, this lists all commands. With a C<cmd>
483 parameter, this displays detailed help for a command.
489 Change the local directory, ie. the current directory of guestfish
492 Note that C<!cd> won't do what you might expect.
500 This is used to view a file.
502 The default viewer is C<$PAGER>. However if you use the alternate
503 command C<less> you will get the C<less> command specifically.
505 NOTE: This will not work reliably for large files
506 (> 2 MB) or binary files containing \0 bytes.
510 This exits guestfish. You can also use C<^D> key.
516 Close and reopen the libguestfs handle. It is not necessary to use
517 this normally, because the handle is closed properly when guestfish
518 exits. However this is occasionally useful for testing.
524 Run the command as usual, but print the elapsed time afterwards. This
525 can be useful for benchmarking operations.
531 =head1 ENVIRONMENT VARIABLES
537 The C<edit> command uses C<$EDITOR> as the editor. If not
542 Used with the I<--remote> option to specify the remote guestfish
543 process to control. See section I<REMOTE CONTROL GUESTFISH OVER A
548 If compiled with GNU readline support, then the command history
549 is saved in C<$HOME/.guestfish>
551 =item LIBGUESTFS_APPEND
553 Pass additional options to the guest kernel.
555 =item LIBGUESTFS_DEBUG
557 Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages. This has the
558 same effect as using the B<-v> option.
560 =item LIBGUESTFS_MEMSIZE
562 Set the memory allocated to the qemu process, in megabytes. For
565 LIBGUESTFS_MEMSIZE=700
567 =item LIBGUESTFS_PATH
569 Set the path that guestfish uses to search for kernel and initrd.img.
570 See the discussion of paths in L<guestfs(3)>.
572 =item LIBGUESTFS_QEMU
574 Set the default qemu binary that libguestfs uses. If not set, then
575 the qemu which was found at compile time by the configure script is
580 The C<more> command uses C<$PAGER> as the pager. If not
581 set, it uses C<more>.
585 Location of temporary directory, defaults to C</tmp>.
587 If libguestfs was compiled to use the supermin appliance then each
588 handle will require rather a large amount of space in this directory
589 for short periods of time (~ 80 MB). You can use C<$TMPDIR> to
590 configure another directory to use in case C</tmp> is not large
597 guestfish returns I<0> if the commands completed without error, or
598 I<1> if there was an error.
603 L<http://libguestfs.org/>.
607 Richard W.M. Jones (C<rjones at redhat dot com>)
611 Copyright (C) 2009 Red Hat Inc.
612 L<http://libguestfs.org/>
614 This program is free software; you can redistribute it and/or modify
615 it under the terms of the GNU General Public License as published by
616 the Free Software Foundation; either version 2 of the License, or
617 (at your option) any later version.
619 This program is distributed in the hope that it will be useful,
620 but WITHOUT ANY WARRANTY; without even the implied warranty of
621 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
622 GNU General Public License for more details.
624 You should have received a copy of the GNU General Public License
625 along with this program; if not, write to the Free Software
626 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.