fish: In guestfish(1) turn command references into links.
[libguestfs.git] / fish / guestfish.pod
1 =encoding utf8
2
3 =head1 NAME
4
5 guestfish - the libguestfs Filesystem Interactive SHell
6
7 =head1 SYNOPSIS
8
9  guestfish [--options] [commands]
10
11  guestfish
12
13  guestfish -a disk.img
14
15  guestfish -a disk.img -m dev[:mountpoint]
16
17  guestfish -i libvirt-domain
18
19  guestfish -i disk.img [disk.img ...]
20
21 =head1 WARNING
22
23 Using guestfish in read/write mode on live virtual machines can be
24 dangerous, potentially causing disk corruption.  Use the I<--ro>
25 (read-only) option to use guestfish safely if the disk image or
26 virtual machine might be live.
27
28 =head1 EXAMPLES
29
30 =head2 As an interactive shell
31
32  $ guestfish
33  
34  Welcome to guestfish, the libguestfs filesystem interactive shell for
35  editing virtual machine filesystems.
36  
37  Type: 'help' for help with commands
38        'quit' to quit the shell
39  
40  ><fs> help
41
42 =head2 From shell scripts
43
44 Create a new C</etc/motd> file in a guest:
45
46  guestfish <<_EOF_
47  add disk.img
48  run
49  mount /dev/vg_guest/lv_root /
50  write_file /etc/motd "Welcome, new users" 0
51  _EOF_
52
53 List the LVM logical volumes in a guest:
54
55  guestfish -a disk.img --ro <<_EOF_
56  run
57  lvs
58  _EOF_
59
60 =head2 On one command line
61
62 Update C</etc/resolv.conf> in a guest:
63
64  guestfish \
65    add disk.img : run : mount /dev/vg_guest/lv_root / : \
66    write-file /etc/resolv.conf "nameserver 1.2.3.4" 0
67
68 Edit C</boot/grub/grub.conf> interactively:
69
70  guestfish --add disk.img \
71    --mount /dev/vg_guest/lv_root \
72    --mount /dev/sda1:/boot \
73    edit /boot/grub/grub.conf
74
75 =head2 Using virt-inspector
76
77 Use the I<-i> option to get virt-inspector to mount
78 the filesystems automatically as they would be mounted
79 in the virtual machine:
80
81  guestfish --ro -i disk.img cat /etc/group
82
83 =head2 As a script interpreter
84
85 Create a 50MB disk containing an ext2-formatted partition:
86
87  #!/usr/bin/guestfish -f
88  alloc /tmp/output.img 50M
89  run
90  part-disk /dev/sda mbr
91  mkfs ext2 /dev/sda1
92
93 =head2 Remote control
94
95  eval `guestfish --listen --ro`
96  guestfish --remote add disk.img
97  guestfish --remote run
98  guestfish --remote lvs
99
100 =head1 DESCRIPTION
101
102 Guestfish is a shell and command-line tool for examining and modifying
103 virtual machine filesystems.  It uses libguestfs and exposes all of
104 the functionality of the guestfs API, see L<guestfs(3)>.
105
106 Guestfish gives you structured access to the libguestfs API, from
107 shell scripts or the command line or interactively.  If you want to
108 rescue a broken virtual machine image, you should look at the
109 L<virt-rescue(1)> command.
110
111 =head1 OPTIONS
112
113 =over 4
114
115 =item B<--help>
116
117 Displays general help on options.
118
119 =item B<-h> | B<--cmd-help>
120
121 Lists all available guestfish commands.
122
123 =item B<-h cmd> | B<--cmd-help cmd>
124
125 Displays detailed help on a single command C<cmd>.
126
127 =item B<-a image> | B<--add image>
128
129 Add a block device or virtual machine image to the shell.
130
131 =item B<-D> | B<--no-dest-paths>
132
133 Don't tab-complete paths on the guest filesystem.  It is useful to be
134 able to hit the tab key to complete paths on the guest filesystem, but
135 this causes extra "hidden" guestfs calls to be made, so this option is
136 here to allow this feature to be disabled.
137
138 =item B<-f file> | B<--file file>
139
140 Read commands from C<file>.  To write pure guestfish
141 scripts, use:
142
143  #!/usr/bin/guestfish -f
144
145 =item B<-i> | B<--inspector>
146
147 Run virt-inspector on the named libvirt domain or list of disk
148 images.  If virt-inspector is available and if it can identify
149 the domain or disk images, then partitions will be mounted
150 correctly at start-up.
151
152 Typical usage is either:
153
154  guestfish -i myguest
155
156 (for an inactive libvirt domain called I<myguest>), or:
157
158  guestfish --ro -i myguest
159
160 (for active domains, readonly), or specify the block device directly:
161
162  guestfish -i /dev/Guests/MyGuest
163
164 You cannot use I<-a>, I<-m>, I<--listen>, I<--remote> or I<--selinux>
165 in conjunction with this option, and options other than I<--ro> might
166 not behave correctly.
167
168 See also: L<virt-inspector(1)>.
169
170 =item B<--listen>
171
172 Fork into the background and listen for remote commands.  See section
173 L</REMOTE CONTROL GUESTFISH OVER A SOCKET> below.
174
175 =item B<-m dev[:mountpoint]> | B<--mount dev[:mountpoint]>
176
177 Mount the named partition or logical volume on the given mountpoint.
178
179 If the mountpoint is omitted, it defaults to C</>.
180
181 You have to mount something on C</> before most commands will work.
182
183 If any I<-m> or I<--mount> options are given, the guest is
184 automatically launched.
185
186 If you don't know what filesystems a disk image contains, you
187 can either run guestfish without this option, then list the partitions
188 and LVs available (see L</list-partitions> and L</lvs> commands),
189 or you can use the L<virt-list-filesystems(1)> program.
190
191 =item B<-n> | B<--no-sync>
192
193 Disable autosync.  This is enabled by default.  See the discussion
194 of autosync in the L<guestfs(3)> manpage.
195
196 =item B<--remote[=pid]>
197
198 Send remote commands to C<$GUESTFISH_PID> or C<pid>.  See section
199 L</REMOTE CONTROL GUESTFISH OVER A SOCKET> below.
200
201 =item B<-r> | B<--ro>
202
203 This changes the I<-a> and I<-m> options so that disks are added and
204 mounts are done read-only (see L<guestfs(3)/guestfs_mount_ro>).
205
206 The option must always be used if the disk image or virtual machine
207 might be running, and is generally recommended in cases where you
208 don't need write access to the disk.
209
210 =item B<--selinux>
211
212 Enable SELinux support for the guest.  See L<guestfs(3)/SELINUX>.
213
214 =item B<-v> | B<--verbose>
215
216 Enable very verbose messages.  This is particularly useful if you find
217 a bug.
218
219 =item B<-V> | B<--version>
220
221 Display the guestfish / libguestfs version number and exit.
222
223 =item B<-x>
224
225 Echo each command before executing it.
226
227 =back
228
229 =head1 COMMANDS ON COMMAND LINE
230
231 Any additional (non-option) arguments are treated as commands to
232 execute.
233
234 Commands to execute should be separated by a colon (C<:>), where the
235 colon is a separate parameter.  Thus:
236
237  guestfish cmd [args...] : cmd [args...] : cmd [args...] ...
238
239 If there are no additional arguments, then we enter a shell, either an
240 interactive shell with a prompt (if the input is a terminal) or a
241 non-interactive shell.
242
243 In either command line mode or non-interactive shell, the first
244 command that gives an error causes the whole shell to exit.  In
245 interactive mode (with a prompt) if a command fails, you can continue
246 to enter commands.
247
248 =head1 USING launch (OR run)
249
250 As with L<guestfs(3)>, you must first configure your guest by adding
251 disks, then launch it, then mount any disks you need, and finally
252 issue actions/commands.  So the general order of the day is:
253
254 =over 4
255
256 =item *
257
258 add or -a/--add
259
260 =item *
261
262 launch (aka run)
263
264 =item *
265
266 mount or -m/--mount
267
268 =item *
269
270 any other commands
271
272 =back
273
274 C<run> is a synonym for C<launch>.  You must C<launch> (or C<run>)
275 your guest before mounting or performing any other commands.
276
277 The only exception is that if the I<-m> or I<--mount> option was
278 given, the guest is automatically run for you (simply because
279 guestfish can't mount the disks you asked for without doing this).
280
281 =head1 QUOTING
282
283 You can quote ordinary parameters using either single or double
284 quotes.  For example:
285
286  add "file with a space.img"
287
288  rm '/file name'
289
290  rm '/"'
291
292 A few commands require a list of strings to be passed.  For these, use
293 a whitespace-separated list, enclosed in quotes.  Strings containing whitespace
294 to be passed through must be enclosed in single quotes.  A literal single quote
295 must be escaped with a backslash.
296
297  vgcreate VG "/dev/sda1 /dev/sdb1"
298  command "/bin/echo 'foo      bar'"
299  command "/bin/echo \'foo\'"
300
301 =head1 NUMBERS
302
303 Commands which take integers as parameters use the C convention which
304 is to use C<0> to prefix an octal number or C<0x> to prefix a
305 hexadecimal number.  For example:
306
307  1234      decimal number 1234
308  02322     octal number, equivalent to decimal 1234
309  0x4d2     hexadecimal number, equivalent to decimal 1234
310
311 When using the C<chmod> command, you almost always want to specify an
312 octal number for the mode, and you must prefix it with C<0> (unlike
313 the Unix L<chmod(1)> program):
314
315  chmod 0777 /public  # OK
316  chmod 777 /public   # WRONG! This is mode 777 decimal = 01411 octal.
317
318 Commands that return numbers currently always print them in decimal.
319
320 =head1 WILDCARDS AND GLOBBING
321
322 Neither guestfish nor the underlying guestfs API performs
323 wildcard expansion (globbing) by default.  So for example the
324 following will not do what you expect:
325
326  rm-rf /home/*
327
328 Assuming you don't have a directory literally called C</home/*>
329 then the above command will return an error.
330
331 To perform wildcard expansion, use the C<glob> command.
332
333  glob rm-rf /home/*
334
335 runs C<rm-rf> on each path that matches (ie. potentially running
336 the command many times), equivalent to:
337
338  rm-rf /home/jim
339  rm-rf /home/joe
340  rm-rf /home/mary
341
342 C<glob> only works on simple guest paths and not on device names.
343
344 If you have several parameters, each containing a wildcard, then glob
345 will perform a cartesian product.
346
347 =head1 COMMENTS
348
349 Any line which starts with a I<#> character is treated as a comment
350 and ignored.  The I<#> can optionally be preceeded by whitespace,
351 but B<not> by a command.  For example:
352
353  # this is a comment
354          # this is a comment
355  foo # NOT a comment
356
357 Blank lines are also ignored.
358
359 =head1 RUNNING COMMANDS LOCALLY
360
361 Any line which starts with a I<!> character is treated as a command
362 sent to the local shell (C</bin/sh> or whatever L<system(3)> uses).
363 For example:
364
365  !mkdir local
366  tgz-out /remote local/remote-data.tar.gz
367
368 will create a directory C<local> on the host, and then export
369 the contents of C</remote> on the mounted filesystem to
370 C<local/remote-data.tar.gz>.  (See C<tgz-out>).
371
372 To change the local directory, use the C<lcd> command.  C<!cd> will
373 have no effect, due to the way that subprocesses work in Unix.
374
375 =head1 PIPES
376
377 Use C<command E<lt>spaceE<gt> | command> to pipe the output of the
378 first command (a guestfish command) to the second command (any host
379 command).  For example:
380
381  cat /etc/passwd | awk -F: '$3 == 0 { print }'
382
383 (where C<cat> is the guestfish cat command, but C<awk> is the host awk
384 program).  The above command would list all accounts in the guest
385 filesystem which have UID 0, ie. root accounts including backdoors.
386 Other examples:
387
388  hexdump /bin/ls | head
389  list-devices | tail -1
390  tgz-out / - | tar ztf -
391
392 The space before the pipe symbol is required, any space after the pipe
393 symbol is optional.  Everything after the pipe symbol is just passed
394 straight to the host shell, so it can contain redirections, globs and
395 anything else that makes sense on the host side.
396
397 To use a literal argument which begins with a pipe symbol, you have
398 to quote it, eg:
399
400  echo "|"
401
402 =head1 HOME DIRECTORIES
403
404 If a parameter starts with the character C<~> then the tilde may be
405 expanded as a home directory path (either C<~> for the current user's
406 home directory, or C<~user> for another user).
407
408 Note that home directory expansion happens for users known I<on the
409 host>, not in the guest filesystem.
410
411 To use a literal argument which begins with a tilde, you have to quote
412 it, eg:
413
414  echo "~"
415
416 =head1 WINDOWS PATHS
417
418 If a path is prefixed with C<win:> then you can use Windows-style
419 paths (with some limitations).  The following commands are equivalent:
420
421  file /WINDOWS/system32/config/system.LOG
422
423  file win:/windows/system32/config/system.log
424
425  file win:\windows\system32\config\system.log
426
427  file WIN:C:\Windows\SYSTEM32\conFIG\SYSTEM.LOG
428
429 This syntax implicitly calls C<case-sensitive-path> (q.v.) so it also
430 handles case insensitivity like Windows would.  This only works in
431 argument positions that expect a path.
432
433 =head1 UPLOADING AND DOWNLOADING FILES
434
435 For commands such as C<upload>, C<download>, C<tar-in>, C<tar-out> and
436 others which upload from or download to a local file, you can use the
437 special filename C<-> to mean "from stdin" or "to stdout".  For example:
438
439  upload - /foo
440
441 reads stdin and creates from that a file C</foo> in the disk image,
442 and:
443
444  tar-out /etc - | tar tf -
445
446 writes the tarball to stdout and then pipes that into the external
447 "tar" command (see L</PIPES>).
448
449 When using C<-> to read from stdin, the input is read up to the end of
450 stdin.
451
452 =head1 EXIT ON ERROR BEHAVIOUR
453
454 By default, guestfish will ignore any errors when in interactive mode
455 (ie. taking commands from a human over a tty), and will exit on the
456 first error in non-interactive mode (scripts, commands given on the
457 command line).
458
459 If you prefix a command with a I<-> character, then that command will
460 not cause guestfish to exit, even if that (one) command returns an
461 error.
462
463 =head1 REMOTE CONTROL GUESTFISH OVER A SOCKET
464
465 Guestfish can be remote-controlled over a socket.  This is useful
466 particularly in shell scripts where you want to make several different
467 changes to a filesystem, but you don't want the overhead of starting
468 up a guestfish process each time.
469
470 Start a guestfish server process using:
471
472  eval `guestfish --listen`
473
474 and then send it commands by doing:
475
476  guestfish --remote cmd [...]
477
478 To cause the server to exit, send it the exit command:
479
480  guestfish --remote exit
481
482 Note that the server will normally exit if there is an error in a
483 command.  You can change this in the usual way.  See section
484 L</EXIT ON ERROR BEHAVIOUR>.
485
486 =head2 CONTROLLING MULTIPLE GUESTFISH PROCESSES
487
488 The C<eval> statement sets the environment variable C<$GUESTFISH_PID>,
489 which is how the I<--remote> option knows where to send the commands.
490 You can have several guestfish listener processes running using:
491
492  eval `guestfish --listen`
493  pid1=$GUESTFISH_PID
494  eval `guestfish --listen`
495  pid2=$GUESTFISH_PID
496  ...
497  guestfish --remote=$pid1 cmd
498  guestfish --remote=$pid2 cmd
499
500 =head2 REMOTE CONTROL DETAILS
501
502 Remote control happens over a Unix domain socket called
503 C</tmp/.guestfish-$UID/socket-$PID>, where C<$UID> is the effective
504 user ID of the process, and C<$PID> is the process ID of the server.
505
506 Guestfish client and server versions must match exactly.
507
508 =head1 GUESTFISH COMMANDS
509
510 The commands in this section are guestfish convenience commands, in
511 other words, they are not part of the L<guestfs(3)> API.
512
513 =head2 alloc | allocate
514
515  alloc filename size
516
517 This creates an empty (zeroed) file of the given size, and then adds
518 so it can be further examined.
519
520 For more advanced image creation, see L<qemu-img(1)> utility.
521
522 Size can be specified (where C<nn> means a number):
523
524 =over 4
525
526 =item C<nn> or C<nn>K or C<nn>KB
527
528 number of kilobytes, eg: C<1440> = standard 3.5in floppy
529
530 =item C<nn>M or C<nn>MB
531
532 number of megabytes
533
534 =item C<nn>G or C<nn>GB
535
536 number of gigabytes
537
538 =item C<nn>T or C<nn>TB
539
540 number of terabytes
541
542 =item C<nn>P or C<nn>PB
543
544 number of petabytes
545
546 =item C<nn>E or C<nn>EB
547
548 number of exabytes
549
550 =item C<nn>sects
551
552 number of 512 byte sectors
553
554 =back
555
556 =head2 echo
557
558  echo [params ...]
559
560 This echos the parameters to the terminal.
561
562 =head2 edit | vi | emacs
563
564  edit filename
565
566 This is used to edit a file.  It downloads the file, edits it
567 locally using your editor, then uploads the result.
568
569 The editor is C<$EDITOR>.  However if you use the alternate
570 commands C<vi> or C<emacs> you will get those corresponding
571 editors.
572
573 =head2 glob
574
575  glob command args...
576
577 Expand wildcards in any paths in the args list, and run C<command>
578 repeatedly on each matching path.
579
580 See section WILDCARDS AND GLOBBING.
581
582 =head2 help
583
584  help
585  help cmd
586
587 Without any parameter, this lists all commands.  With a C<cmd>
588 parameter, this displays detailed help for a command.
589
590 =head2 lcd
591
592  lcd directory
593
594 Change the local directory, ie. the current directory of guestfish
595 itself.
596
597 Note that C<!cd> won't do what you might expect.
598
599 =head2 more | less
600
601  more filename
602
603  less filename
604
605 This is used to view a file.
606
607 The default viewer is C<$PAGER>.  However if you use the alternate
608 command C<less> you will get the C<less> command specifically.
609
610 =head2 quit | exit
611
612 This exits guestfish.  You can also use C<^D> key.
613
614 =head2 reopen
615
616  reopen
617
618 Close and reopen the libguestfs handle.  It is not necessary to use
619 this normally, because the handle is closed properly when guestfish
620 exits.  However this is occasionally useful for testing.
621
622 =head2 sparse
623
624  sparse filename size
625
626 This creates an empty sparse file of the given size, and then adds
627 so it can be further examined.
628
629 In all respects it works the same as the C<alloc> command, except that
630 the image file is allocated sparsely, which means that disk blocks are
631 not assigned to the file until they are needed.  Sparse disk files
632 only use space when written to, but they are slower and there is a
633 danger you could run out of real disk space during a write operation.
634
635 For more advanced image creation, see L<qemu-img(1)> utility.
636
637 Size can be specified (where C<nn> means a number):
638
639 =over 4
640
641 =item C<nn> or C<nn>K or C<nn>KB
642
643 number of kilobytes, eg: C<1440> = standard 3.5in floppy
644
645 =item C<nn>M or C<nn>MB
646
647 number of megabytes
648
649 =item C<nn>G or C<nn>GB
650
651 number of gigabytes
652
653 =item C<nn>T or C<nn>TB
654
655 number of terabytes
656
657 =item C<nn>P or C<nn>PB
658
659 number of petabytes
660
661 =item C<nn>E or C<nn>EB
662
663 number of exabytes
664
665 =item C<nn>sects
666
667 number of 512 byte sectors
668
669 =back
670
671 =head2 time
672
673  time command args...
674
675 Run the command as usual, but print the elapsed time afterwards.  This
676 can be useful for benchmarking operations.
677
678 =head1 COMMANDS
679
680 @ACTIONS@
681
682 =head1 EXIT CODE
683
684 guestfish returns 0 if the commands completed without error, or
685 1 if there was an error.
686
687 =head1 ENVIRONMENT VARIABLES
688
689 =over 4
690
691 =item EDITOR
692
693 The C<edit> command uses C<$EDITOR> as the editor.  If not
694 set, it uses C<vi>.
695
696 =item GUESTFISH_PID
697
698 Used with the I<--remote> option to specify the remote guestfish
699 process to control.  See section
700 L</REMOTE CONTROL GUESTFISH OVER A SOCKET>.
701
702 =item HOME
703
704 If compiled with GNU readline support, various files in the
705 home directory can be used.  See L</FILES>.
706
707 =item LIBGUESTFS_APPEND
708
709 Pass additional options to the guest kernel.
710
711 =item LIBGUESTFS_DEBUG
712
713 Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages.  This has the
714 same effect as using the B<-v> option.
715
716 =item LIBGUESTFS_MEMSIZE
717
718 Set the memory allocated to the qemu process, in megabytes.  For
719 example:
720
721  LIBGUESTFS_MEMSIZE=700
722
723 =item LIBGUESTFS_PATH
724
725 Set the path that guestfish uses to search for kernel and initrd.img.
726 See the discussion of paths in L<guestfs(3)>.
727
728 =item LIBGUESTFS_QEMU
729
730 Set the default qemu binary that libguestfs uses.  If not set, then
731 the qemu which was found at compile time by the configure script is
732 used.
733
734 =item LIBGUESTFS_TRACE
735
736 Set C<LIBGUESTFS_TRACE=1> to enable command traces.
737
738 =item PAGER
739
740 The C<more> command uses C<$PAGER> as the pager.  If not
741 set, it uses C<more>.
742
743 =item TMPDIR
744
745 Location of temporary directory, defaults to C</tmp>.
746
747 If libguestfs was compiled to use the supermin appliance then each
748 handle will require rather a large amount of space in this directory
749 for short periods of time (~ 80 MB).  You can use C<$TMPDIR> to
750 configure another directory to use in case C</tmp> is not large
751 enough.
752
753 =back
754
755 =head1 FILES
756
757 =over 4
758
759 =item $HOME/.guestfish
760
761 If compiled with GNU readline support, then the command history
762 is saved in this file.
763
764 =item $HOME/.inputrc
765
766 =item /etc/inputrc
767
768 If compiled with GNU readline support, then these files can be used to
769 configure readline.  For further information, please see
770 L<readline(3)/INITIALIZATION FILE>.
771
772 To write rules which only apply to guestfish, use:
773
774  $if guestfish
775  ...
776  $endif
777
778 Variables that you can set in inputrc that change the behaviour
779 of guestfish in useful ways include:
780
781 =over 4
782
783 =item completion-ignore-case (default: on)
784
785 By default, guestfish will ignore case when tab-completing
786 paths on the disk.  Use:
787
788  set completion-ignore-case off
789
790 to make guestfish case sensitive.
791
792 =back
793
794 =back
795
796 =head1 SEE ALSO
797
798 L<guestfs(3)>,
799 L<http://libguestfs.org/>,
800 L<virt-cat(1)>,
801 L<virt-df(1)>,
802 L<virt-edit(1)>,
803 L<virt-list-filesystems(1)>,
804 L<virt-list-partitions(1)>,
805 L<virt-ls(1)>,
806 L<virt-make-fs(1)>,
807 L<virt-rescue(1)>,
808 L<virt-resize(1)>,
809 L<virt-tar(1)>,
810 L<virt-win-reg(1)>.
811
812 =head1 AUTHORS
813
814 Richard W.M. Jones (C<rjones at redhat dot com>)
815
816 =head1 COPYRIGHT
817
818 Copyright (C) 2009-2010 Red Hat Inc.
819 L<http://libguestfs.org/>
820
821 This program is free software; you can redistribute it and/or modify
822 it under the terms of the GNU General Public License as published by
823 the Free Software Foundation; either version 2 of the License, or
824 (at your option) any later version.
825
826 This program is distributed in the hope that it will be useful,
827 but WITHOUT ANY WARRANTY; without even the implied warranty of
828 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
829 GNU General Public License for more details.
830
831 You should have received a copy of the GNU General Public License
832 along with this program; if not, write to the Free Software
833 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.