Use /var/tmp for the cached appliance (for FHS compliance).
[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 [--ro|--rw] -a disk.img
14
15  guestfish [--ro|--rw] -a disk.img -m dev[:mountpoint]
16
17  guestfish -d libvirt-domain
18
19  guestfish [--ro|--rw] -a disk.img -i
20
21  guestfish -d libvirt-domain -i
22
23 =head1 WARNING
24
25 Using guestfish in read/write mode on live virtual machines can be
26 dangerous, potentially causing disk corruption.  Use the I<--ro>
27 (read-only) option to use guestfish safely if the disk image or
28 virtual machine might be live.
29
30 =head1 DESCRIPTION
31
32 Guestfish is a shell and command-line tool for examining and modifying
33 virtual machine filesystems.  It uses libguestfs and exposes all of
34 the functionality of the guestfs API, see L<guestfs(3)>.
35
36 Guestfish gives you structured access to the libguestfs API, from
37 shell scripts or the command line or interactively.  If you want to
38 rescue a broken virtual machine image, you should look at the
39 L<virt-rescue(1)> command.
40
41 =head1 EXAMPLES
42
43 =head2 As an interactive shell
44
45  $ guestfish
46  
47  Welcome to guestfish, the libguestfs filesystem interactive shell for
48  editing virtual machine filesystems.
49  
50  Type: 'help' for a list of commands
51        'man' to read the manual
52        'quit' to quit the shell
53  
54  ><fs> add-ro disk.img
55  ><fs> run
56  ><fs> list-filesystems
57  /dev/sda1: ext4
58  /dev/vg_guest/lv_root: ext4
59  /dev/vg_guest/lv_swap: swap
60  ><fs> mount /dev/vg_guest/lv_root /
61  ><fs> cat /etc/fstab
62  # /etc/fstab
63  # Created by anaconda
64  [...]
65  ><fs> exit
66
67 =head2 From shell scripts
68
69 Create a new C</etc/motd> file in a guest or disk image:
70
71  guestfish <<_EOF_
72  add disk.img
73  run
74  mount /dev/vg_guest/lv_root /
75  write /etc/motd "Welcome, new users"
76  _EOF_
77
78 List the LVM logical volumes in a disk image:
79
80  guestfish -a disk.img --ro <<_EOF_
81  run
82  lvs
83  _EOF_
84
85 List all the filesystems in a disk image:
86
87  guestfish -a disk.img --ro <<_EOF_
88  run
89  list-filesystems
90  _EOF_
91
92 =head2 On one command line
93
94 Update C</etc/resolv.conf> in a guest:
95
96  guestfish \
97    add disk.img : run : mount /dev/vg_guest/lv_root / : \
98    write /etc/resolv.conf "nameserver 1.2.3.4"
99
100 Edit C</boot/grub/grub.conf> interactively:
101
102  guestfish --rw --add disk.img \
103    --mount /dev/vg_guest/lv_root \
104    --mount /dev/sda1:/boot \
105    edit /boot/grub/grub.conf
106
107 =head2 Mount disks automatically
108
109 Use the I<-i> option to automatically mount the
110 disks from a virtual machine:
111
112  guestfish --ro -a disk.img -i cat /etc/group
113
114  guestfish --ro -d libvirt-domain -i cat /etc/group
115
116 Another way to edit C</boot/grub/grub.conf> interactively is:
117
118  guestfish --rw -a disk.img -i edit /boot/grub/grub.conf
119
120 =head2 As a script interpreter
121
122 Create a 100MB disk containing an ext2-formatted partition:
123
124  #!/usr/bin/guestfish -f
125  sparse test1.img 100M
126  run
127  part-disk /dev/sda mbr
128  mkfs ext2 /dev/sda1
129
130 =head2 Start with a prepared disk
131
132 An alternate way to create a 100MB disk called C<test1.img> containing
133 a single ext2-formatted partition:
134
135  guestfish -N fs
136
137 To list what is available do:
138
139  guestfish -N help | less
140
141 =head2 Remote control
142
143  eval "`guestfish --listen`"
144  guestfish --remote add-ro disk.img
145  guestfish --remote run
146  guestfish --remote lvs
147
148 =head1 OPTIONS
149
150 =over 4
151
152 =item B<--help>
153
154 Displays general help on options.
155
156 =item B<-h>
157
158 =item B<--cmd-help>
159
160 Lists all available guestfish commands.
161
162 =item B<-h cmd>
163
164 =item B<--cmd-help cmd>
165
166 Displays detailed help on a single command C<cmd>.
167
168 =item B<-a image>
169
170 =item B<--add image>
171
172 Add a block device or virtual machine image to the shell.
173
174 The format of the disk image is auto-detected.  To override this and
175 force a particular format use the I<--format=..> option.
176
177 Using this flag is mostly equivalent to using the C<add> command,
178 with C<readonly:true> if the I<--ro> flag was given, and
179 with C<format:...> if the I<--format:...> flag was given.
180
181 =item B<-c URI>
182
183 =item B<--connect URI>
184
185 When used in conjunction with the I<-d> option, this specifies
186 the libvirt URI to use.  The default is to use the default libvirt
187 connection.
188
189 =item B<--csh>
190
191 If using the I<--listen> option and a csh-like shell, use this option.
192 See section L</REMOTE CONTROL AND CSH> below.
193
194 =item B<-d libvirt-domain>
195
196 =item B<--domain libvirt-domain>
197
198 Add disks from the named libvirt domain.  If the I<--ro> option is
199 also used, then any libvirt domain can be used.  However in write
200 mode, only libvirt domains which are shut down can be named here.
201
202 Using this flag is mostly equivalent to using the C<add-domain> command,
203 with C<readonly:true> if the I<--ro> flag was given, and
204 with C<format:...> if the I<--format:...> flag was given.
205
206 =item B<-D>
207
208 =item B<--no-dest-paths>
209
210 Don't tab-complete paths on the guest filesystem.  It is useful to be
211 able to hit the tab key to complete paths on the guest filesystem, but
212 this causes extra "hidden" guestfs calls to be made, so this option is
213 here to allow this feature to be disabled.
214
215 =item B<--echo-keys>
216
217 When prompting for keys and passphrases, guestfish normally turns
218 echoing off so you cannot see what you are typing.  If you are not
219 worried about Tempest attacks and there is no one else in the room
220 you can specify this flag to see what you are typing.
221
222 =item B<-f file>
223
224 =item B<--file file>
225
226 Read commands from C<file>.  To write pure guestfish
227 scripts, use:
228
229  #!/usr/bin/guestfish -f
230
231 =item B<--format=raw|qcow2|..>
232
233 =item B<--format>
234
235 The default for the I<-a> option is to auto-detect the format of the
236 disk image.  Using this forces the disk format for I<-a> options which
237 follow on the command line.  Using I<--format> with no argument
238 switches back to auto-detection for subsequent I<-a> options.
239
240 For example:
241
242  guestfish --format=raw -a disk.img
243
244 forces raw format (no auto-detection) for C<disk.img>.
245
246  guestfish --format=raw -a disk.img --format -a another.img
247
248 forces raw format (no auto-detection) for C<disk.img> and reverts to
249 auto-detection for C<another.img>.
250
251 If you have untrusted raw-format guest disk images, you should use
252 this option to specify the disk format.  This avoids a possible
253 security problem with malicious guests (CVE-2010-3851).  See also
254 L</add-drive-opts>.
255
256 =item B<-i>
257
258 =item B<--inspector>
259
260 Using L<virt-inspector(1)> code, inspect the disks looking for
261 an operating system and mount filesystems as they would be
262 mounted on the real virtual machine.
263
264 Typical usage is either:
265
266  guestfish -d myguest -i
267
268 (for an inactive libvirt domain called I<myguest>), or:
269
270  guestfish --ro -d myguest -i
271
272 (for active domains, readonly), or specify the block device directly:
273
274  guestfish --rw -a /dev/Guests/MyGuest -i
275
276 Note that the command line syntax changed slightly over older
277 versions of guestfish.  You can still use the old syntax:
278
279  guestfish [--ro] -i disk.img
280
281  guestfish [--ro] -i libvirt-domain
282
283 Using this flag is mostly equivalent to using the C<inspect-os>
284 command and then using other commands to mount the filesystems that
285 were found.
286
287 =item B<--keys-from-stdin>
288
289 Read key or passphrase parameters from stdin.  The default is
290 to try to read passphrases from the user by opening C</dev/tty>.
291
292 =item B<--listen>
293
294 Fork into the background and listen for remote commands.  See section
295 L</REMOTE CONTROL GUESTFISH OVER A SOCKET> below.
296
297 =item B<-m dev[:mountpoint]>
298
299 =item B<--mount dev[:mountpoint]>
300
301 Mount the named partition or logical volume on the given mountpoint.
302
303 If the mountpoint is omitted, it defaults to C</>.
304
305 You have to mount something on C</> before most commands will work.
306
307 If any I<-m> or I<--mount> options are given, the guest is
308 automatically launched.
309
310 If you don't know what filesystems a disk image contains, you can
311 either run guestfish without this option, then list the partitions,
312 filesystems and LVs available (see L</list-partitions>,
313 L</list-filesystems> and L</lvs> commands), or you can use the
314 L<virt-filesystems(1)> program.
315
316 Using this flag is mostly equivalent to using the C<mount-options>
317 command or the C<mount-ro> command if the I<--ro> flag was given.
318
319 =item B<-n>
320
321 =item B<--no-sync>
322
323 Disable autosync.  This is enabled by default.  See the discussion
324 of autosync in the L<guestfs(3)> manpage.
325
326 =item B<-N type>
327
328 =item B<--new type>
329
330 =item B<-N help>
331
332 Prepare a fresh disk image formatted as "type".  This is an
333 alternative to the I<-a> option: whereas I<-a> adds an existing disk,
334 I<-N> creates a preformatted disk with a filesystem and adds it.
335 See L</PREPARED DISK IMAGES> below.
336
337 =item B<--progress-bars>
338
339 Enable progress bars, even when guestfish is used non-interactively.
340
341 Progress bars are enabled by default when guestfish is used as an
342 interactive shell.
343
344 =item B<--no-progress-bars>
345
346 Disable progress bars.
347
348 =item B<--remote[=pid]>
349
350 Send remote commands to C<$GUESTFISH_PID> or C<pid>.  See section
351 L</REMOTE CONTROL GUESTFISH OVER A SOCKET> below.
352
353 =item B<-r>
354
355 =item B<--ro>
356
357 This changes the I<-a>, I<-d> and I<-m> options so that disks are
358 added and mounts are done read-only.
359
360 The option must always be used if the disk image or virtual machine
361 might be running, and is generally recommended in cases where you
362 don't need write access to the disk.
363
364 Note that prepared disk images created with I<-N> are not affected by
365 this option.  Also commands like C<add> are not affected - you have to
366 specify the C<readonly:true> option explicitly if you need it.
367
368 See also L</OPENING DISKS FOR READ AND WRITE> below.
369
370 =item B<--selinux>
371
372 Enable SELinux support for the guest.  See L<guestfs(3)/SELINUX>.
373
374 =item B<-v>
375
376 =item B<--verbose>
377
378 Enable very verbose messages.  This is particularly useful if you find
379 a bug.
380
381 =item B<-V>
382
383 =item B<--version>
384
385 Display the guestfish / libguestfs version number and exit.
386
387 =item B<-w>
388
389 =item B<--rw>
390
391 This option does nothing at the moment.
392 See L</OPENING DISKS FOR READ AND WRITE> below.
393
394 =item B<-x>
395
396 Echo each command before executing it.
397
398 =back
399
400 =head1 COMMANDS ON COMMAND LINE
401
402 Any additional (non-option) arguments are treated as commands to
403 execute.
404
405 Commands to execute should be separated by a colon (C<:>), where the
406 colon is a separate parameter.  Thus:
407
408  guestfish cmd [args...] : cmd [args...] : cmd [args...] ...
409
410 If there are no additional arguments, then we enter a shell, either an
411 interactive shell with a prompt (if the input is a terminal) or a
412 non-interactive shell.
413
414 In either command line mode or non-interactive shell, the first
415 command that gives an error causes the whole shell to exit.  In
416 interactive mode (with a prompt) if a command fails, you can continue
417 to enter commands.
418
419 =head1 USING launch (OR run)
420
421 As with L<guestfs(3)>, you must first configure your guest by adding
422 disks, then launch it, then mount any disks you need, and finally
423 issue actions/commands.  So the general order of the day is:
424
425 =over 4
426
427 =item *
428
429 add or -a/--add
430
431 =item *
432
433 launch (aka run)
434
435 =item *
436
437 mount or -m/--mount
438
439 =item *
440
441 any other commands
442
443 =back
444
445 C<run> is a synonym for C<launch>.  You must C<launch> (or C<run>)
446 your guest before mounting or performing any other commands.
447
448 The only exception is that if any of the I<-i>, I<-m>, I<--mount>,
449 I<-N> or I<--new> options were given then C<run> is done
450 automatically, simply because guestfish can't perform the action you
451 asked for without doing this.
452
453 =head1 OPENING DISKS FOR READ AND WRITE
454
455 The guestfish (and L<guestmount(1)>) options I<--ro> and I<--rw>
456 affect whether the other command line options I<-a>, I<-c>, I<-d>,
457 I<-i> and I<-m> open disk images read-only or for writing.
458
459 In libguestfs E<lt> 1.6.2, guestfish and guestmount defaulted to
460 opening disk images supplied on the command line for write.  To open a
461 disk image read-only you have to do I<-a image --ro>.
462
463 This matters: If you accidentally open a live VM disk image writable
464 then you will cause irreversible disk corruption.
465
466 By libguestfs 1.10 we intend to change the default the other way.  Disk
467 images will be opened read-only.  You will have to either specify
468 I<guestfish --rw> or change a configuration file in order to get write
469 access for disk images specified by those other command line options.
470
471 This version of guestfish has a I<--rw> option which does nothing (it
472 is already the default).  However it is highly recommended that you
473 use this option to indicate that guestfish needs write access, and to
474 prepare your scripts for the day when this option will be required for
475 write access.
476
477 B<Note:> This does I<not> affect commands like L</add> and L</mount>,
478 or any other libguestfs program apart from guestfish and guestmount.
479
480 =head1 QUOTING
481
482 You can quote ordinary parameters using either single or double
483 quotes.  For example:
484
485  add "file with a space.img"
486
487  rm '/file name'
488
489  rm '/"'
490
491 A few commands require a list of strings to be passed.  For these, use
492 a whitespace-separated list, enclosed in quotes.  Strings containing whitespace
493 to be passed through must be enclosed in single quotes.  A literal single quote
494 must be escaped with a backslash.
495
496  vgcreate VG "/dev/sda1 /dev/sdb1"
497  command "/bin/echo 'foo      bar'"
498  command "/bin/echo \'foo\'"
499
500 =head1 OPTIONAL ARGUMENTS
501
502 Some commands take optional arguments.  These arguments appear in this
503 documentation as C<[argname:..]>.  You can use them as in these
504 examples:
505
506  add-drive-opts filename
507
508  add-drive-opts filename readonly:true
509
510  add-drive-opts filename format:qcow2 readonly:false
511
512 Each optional argument can appear at most once.  All optional
513 arguments must appear after the required ones.
514
515 =head1 NUMBERS
516
517 This section applies to all commands which can take integers
518 as parameters.
519
520 =head2 SIZE SUFFIX
521
522 When the command takes a parameter measured in bytes, you can use one
523 of the following suffixes to specify kilobytes, megabytes and larger
524 sizes:
525
526 =over 4
527
528 =item B<k> or B<K> or B<KiB>
529
530 The size in kilobytes (multiplied by 1024).
531
532 =item B<KB>
533
534 The size in SI 1000 byte units.
535
536 =item B<M> or B<MiB>
537
538 The size in megabytes (multiplied by 1048576).
539
540 =item B<MB>
541
542 The size in SI 1000000 byte units.
543
544 =item B<G> or B<GiB>
545
546 The size in gigabytes (multiplied by 2**30).
547
548 =item B<GB>
549
550 The size in SI 10**9 byte units.
551
552 =item B<T> or B<TiB>
553
554 The size in terabytes (multiplied by 2**40).
555
556 =item B<TB>
557
558 The size in SI 10**12 byte units.
559
560 =item B<P> or B<PiB>
561
562 The size in petabytes (multiplied by 2**50).
563
564 =item B<PB>
565
566 The size in SI 10**15 byte units.
567
568 =item B<E> or B<EiB>
569
570 The size in exabytes (multiplied by 2**60).
571
572 =item B<EB>
573
574 The size in SI 10**18 byte units.
575
576 =item B<Z> or B<ZiB>
577
578 The size in zettabytes (multiplied by 2**70).
579
580 =item B<ZB>
581
582 The size in SI 10**21 byte units.
583
584 =item B<Y> or B<YiB>
585
586 The size in yottabytes (multiplied by 2**80).
587
588 =item B<YB>
589
590 The size in SI 10**24 byte units.
591
592 =back
593
594 For example:
595
596  truncate-size /file 1G
597
598 would truncate the file to 1 gigabyte.
599
600 Be careful because a few commands take sizes in kilobytes or megabytes
601 (eg. the parameter to L</memsize> is specified in megabytes already).
602 Adding a suffix will probably not do what you expect.
603
604 =head2 OCTAL AND HEXADECIMAL NUMBERS
605
606 For specifying the radix (base) use the C convention: C<0> to prefix
607 an octal number or C<0x> to prefix a hexadecimal number.  For example:
608
609  1234      decimal number 1234
610  02322     octal number, equivalent to decimal 1234
611  0x4d2     hexadecimal number, equivalent to decimal 1234
612
613 When using the C<chmod> command, you almost always want to specify an
614 octal number for the mode, and you must prefix it with C<0> (unlike
615 the Unix L<chmod(1)> program):
616
617  chmod 0777 /public  # OK
618  chmod 777 /public   # WRONG! This is mode 777 decimal = 01411 octal.
619
620 Commands that return numbers usually print them in decimal, but
621 some commands print numbers in other radices (eg. C<umask> prints
622 the mode in octal, preceeded by C<0>).
623
624 =head1 WILDCARDS AND GLOBBING
625
626 Neither guestfish nor the underlying guestfs API performs
627 wildcard expansion (globbing) by default.  So for example the
628 following will not do what you expect:
629
630  rm-rf /home/*
631
632 Assuming you don't have a directory called literally C</home/*>
633 then the above command will return an error.
634
635 To perform wildcard expansion, use the C<glob> command.
636
637  glob rm-rf /home/*
638
639 runs C<rm-rf> on each path that matches (ie. potentially running
640 the command many times), equivalent to:
641
642  rm-rf /home/jim
643  rm-rf /home/joe
644  rm-rf /home/mary
645
646 C<glob> only works on simple guest paths and not on device names.
647
648 If you have several parameters, each containing a wildcard, then glob
649 will perform a Cartesian product.
650
651 =head1 COMMENTS
652
653 Any line which starts with a I<#> character is treated as a comment
654 and ignored.  The I<#> can optionally be preceeded by whitespace,
655 but B<not> by a command.  For example:
656
657  # this is a comment
658          # this is a comment
659  foo # NOT a comment
660
661 Blank lines are also ignored.
662
663 =head1 RUNNING COMMANDS LOCALLY
664
665 Any line which starts with a I<!> character is treated as a command
666 sent to the local shell (C</bin/sh> or whatever L<system(3)> uses).
667 For example:
668
669  !mkdir local
670  tgz-out /remote local/remote-data.tar.gz
671
672 will create a directory C<local> on the host, and then export
673 the contents of C</remote> on the mounted filesystem to
674 C<local/remote-data.tar.gz>.  (See C<tgz-out>).
675
676 To change the local directory, use the C<lcd> command.  C<!cd> will
677 have no effect, due to the way that subprocesses work in Unix.
678
679 =head2 LOCAL COMMANDS WITH INLINE EXECUTION
680
681 If a line starts with I<E<lt>!> then the shell command is executed (as
682 for I<!>), but subsequently any output (stdout) of the shell command
683 is parsed and executed as guestfish commands.
684
685 Thus you can use shell script to construct arbitrary guestfish
686 commands which are then parsed by guestfish.
687
688 For example it is tedious to create a sequence of files
689 (eg. C</foo.1> through C</foo.100>) using guestfish commands
690 alone.  However this is simple if we use a shell script to
691 create the guestfish commands for us:
692
693  <! for n in `seq 1 100`; do echo write /foo.$n $n; done
694
695 or with names like C</foo.001>:
696
697  <! for n in `seq 1 100`; do printf "write /foo.%03d %d\n" $n $n; done
698
699 When using guestfish interactively it can be helpful to just run the
700 shell script first (ie. remove the initial C<E<lt>> character so it is
701 just an ordinary I<!> local command), see what guestfish commands it
702 would run, and when you are happy with those prepend the C<E<lt>>
703 character to run the guestfish commands for real.
704
705 =head1 PIPES
706
707 Use C<command E<lt>spaceE<gt> | command> to pipe the output of the
708 first command (a guestfish command) to the second command (any host
709 command).  For example:
710
711  cat /etc/passwd | awk -F: '$3 == 0 { print }'
712
713 (where C<cat> is the guestfish cat command, but C<awk> is the host awk
714 program).  The above command would list all accounts in the guest
715 filesystem which have UID 0, ie. root accounts including backdoors.
716 Other examples:
717
718  hexdump /bin/ls | head
719  list-devices | tail -1
720  tgz-out / - | tar ztf -
721
722 The space before the pipe symbol is required, any space after the pipe
723 symbol is optional.  Everything after the pipe symbol is just passed
724 straight to the host shell, so it can contain redirections, globs and
725 anything else that makes sense on the host side.
726
727 To use a literal argument which begins with a pipe symbol, you have
728 to quote it, eg:
729
730  echo "|"
731
732 =head1 HOME DIRECTORIES
733
734 If a parameter starts with the character C<~> then the tilde may be
735 expanded as a home directory path (either C<~> for the current user's
736 home directory, or C<~user> for another user).
737
738 Note that home directory expansion happens for users known I<on the
739 host>, not in the guest filesystem.
740
741 To use a literal argument which begins with a tilde, you have to quote
742 it, eg:
743
744  echo "~"
745
746 =head1 ENCRYPTED DISKS
747
748 Libguestfs has some support for Linux guests encrypted according to
749 the Linux Unified Key Setup (LUKS) standard, which includes nearly all
750 whole disk encryption systems used by modern Linux guests.  Currently
751 only LVM-on-LUKS is supported.
752
753 Identify encrypted block devices and partitions using L</vfs-type>:
754
755  ><fs> vfs-type /dev/sda2
756  crypto_LUKS
757
758 Then open those devices using L</luks-open>.  This creates a
759 device-mapper device called C</dev/mapper/luksdev>.
760
761  ><fs> luks-open /dev/sda2 luksdev
762  Enter key or passphrase ("key"): <enter the passphrase>
763
764 Finally you have to tell LVM to scan for volume groups on
765 the newly created mapper device:
766
767  vgscan
768  vg-activate-all true
769
770 The logical volume(s) can now be mounted in the usual way.
771
772 Before closing a LUKS device you must unmount any logical volumes on
773 it and deactivate the volume groups by calling C<vg-activate false VG>
774 on each one.  Then you can close the mapper device:
775
776  vg-activate false /dev/VG
777  luks-close /dev/mapper/luksdev
778
779 =head1 WINDOWS PATHS
780
781 If a path is prefixed with C<win:> then you can use Windows-style
782 paths (with some limitations).  The following commands are equivalent:
783
784  file /WINDOWS/system32/config/system.LOG
785
786  file win:/windows/system32/config/system.log
787
788  file win:\windows\system32\config\system.log
789
790  file WIN:C:\Windows\SYSTEM32\conFIG\SYSTEM.LOG
791
792 This syntax implicitly calls C<case-sensitive-path> (q.v.) so it also
793 handles case insensitivity like Windows would.  This only works in
794 argument positions that expect a path.
795
796 =head1 UPLOADING AND DOWNLOADING FILES
797
798 For commands such as C<upload>, C<download>, C<tar-in>, C<tar-out> and
799 others which upload from or download to a local file, you can use the
800 special filename C<-> to mean "from stdin" or "to stdout".  For example:
801
802  upload - /foo
803
804 reads stdin and creates from that a file C</foo> in the disk image,
805 and:
806
807  tar-out /etc - | tar tf -
808
809 writes the tarball to stdout and then pipes that into the external
810 "tar" command (see L</PIPES>).
811
812 When using C<-> to read from stdin, the input is read up to the end of
813 stdin.  You can also use a special "heredoc"-like syntax to read up to
814 some arbitrary end marker:
815
816  upload -<<END /foo
817  input line 1
818  input line 2
819  input line 3
820  END
821
822 Any string of characters can be used instead of C<END>.  The end
823 marker must appear on a line of its own, without any preceeding or
824 following characters (not even spaces).
825
826 Note that the C<-E<lt>E<lt>> syntax only applies to parameters used to
827 upload local files (so-called "FileIn" parameters in the generator).
828
829 =head1 EXIT ON ERROR BEHAVIOUR
830
831 By default, guestfish will ignore any errors when in interactive mode
832 (ie. taking commands from a human over a tty), and will exit on the
833 first error in non-interactive mode (scripts, commands given on the
834 command line).
835
836 If you prefix a command with a I<-> character, then that command will
837 not cause guestfish to exit, even if that (one) command returns an
838 error.
839
840 =head1 REMOTE CONTROL GUESTFISH OVER A SOCKET
841
842 Guestfish can be remote-controlled over a socket.  This is useful
843 particularly in shell scripts where you want to make several different
844 changes to a filesystem, but you don't want the overhead of starting
845 up a guestfish process each time.
846
847 Start a guestfish server process using:
848
849  eval "`guestfish --listen`"
850
851 and then send it commands by doing:
852
853  guestfish --remote cmd [...]
854
855 To cause the server to exit, send it the exit command:
856
857  guestfish --remote exit
858
859 Note that the server will normally exit if there is an error in a
860 command.  You can change this in the usual way.  See section
861 L</EXIT ON ERROR BEHAVIOUR>.
862
863 =head2 CONTROLLING MULTIPLE GUESTFISH PROCESSES
864
865 The C<eval> statement sets the environment variable C<$GUESTFISH_PID>,
866 which is how the I<--remote> option knows where to send the commands.
867 You can have several guestfish listener processes running using:
868
869  eval "`guestfish --listen`"
870  pid1=$GUESTFISH_PID
871  eval "`guestfish --listen`"
872  pid2=$GUESTFISH_PID
873  ...
874  guestfish --remote=$pid1 cmd
875  guestfish --remote=$pid2 cmd
876
877 =head2 REMOTE CONTROL AND CSH
878
879 When using csh-like shells (csh, tcsh etc) you have to add the
880 I<--csh> option:
881
882  eval "`guestfish --listen --csh`"
883
884 =head2 REMOTE CONTROL DETAILS
885
886 Remote control happens over a Unix domain socket called
887 C</tmp/.guestfish-$UID/socket-$PID>, where C<$UID> is the effective
888 user ID of the process, and C<$PID> is the process ID of the server.
889
890 Guestfish client and server versions must match exactly.
891
892 =head1 PREPARED DISK IMAGES
893
894 Use the I<-N type> or I<--new type> parameter to select one of a set
895 of preformatted disk images that guestfish can make for you to save
896 typing.  This is particularly useful for testing purposes.  This
897 option is used instead of the I<-a> option, and like I<-a> can appear
898 multiple times (and can be mixed with I<-a>).
899
900 The new disk is called C<test1.img> for the first I<-N>, C<test2.img>
901 for the second and so on.  Existing files in the current directory are
902 I<overwritten>.
903
904 The type briefly describes how the disk should be sized, partitioned,
905 how filesystem(s) should be created, and how content should be added.
906 Optionally the type can be followed by extra parameters, separated by
907 C<:> (colon) characters.  For example, I<-N fs> creates a default
908 100MB, sparsely-allocated disk, containing a single partition, with
909 the partition formatted as ext2.  I<-N fs:ext4:1G> is the same, but
910 for an ext4 filesystem on a 1GB disk instead.
911
912 To list the available types and any extra parameters they take, run:
913
914  guestfish -N help | less
915
916 Note that the prepared filesystem is not mounted.  You would usually
917 have to use the C<mount /dev/sda1 /> command or add the
918 I<-m /dev/sda1> option.
919
920 If any I<-N> or I<--new> options are given, the guest is automatically
921 launched.
922
923 =head2 EXAMPLES
924
925 Create a 100MB disk with an ext4-formatted partition:
926
927  guestfish -N fs:ext4
928
929 Create a 32MB disk with a VFAT-formatted partition, and mount it:
930
931  guestfish -N fs:vfat:32M -m /dev/sda1
932
933 Create a blank 200MB disk:
934
935  guestfish -N disk:200M
936
937 =head1 PROGRESS BARS
938
939 Some (not all) long-running commands send progress notification
940 messages as they are running.  Guestfish turns these messages into
941 progress bars.
942
943 When a command that supports progress bars takes longer than two
944 seconds to run, and if progress bars are enabled, then you will see
945 one appearing below the command:
946
947  ><fs> copy-size /large-file /another-file 2048M
948  / 10% [#####-----------------------------------------] 00:30
949
950 The spinner on the left hand side moves round once for every progress
951 notification received from the backend.  This is a (reasonably) golden
952 assurance that the command is "doing something" even if the progress
953 bar is not moving, because the command is able to send the progress
954 notifications.  When the bar reaches 100% and the command finishes,
955 the spinner disappears.
956
957 Progress bars are enabled by default when guestfish is used
958 interactively.  You can enable them even for non-interactive modes
959 using I<--progress-bars>, and you can disable them completely using
960 I<--no-progress-bars>.
961
962 =head1 GUESTFISH COMMANDS
963
964 The commands in this section are guestfish convenience commands, in
965 other words, they are not part of the L<guestfs(3)> API.
966
967 =head2 help
968
969  help
970  help cmd
971
972 Without any parameter, this provides general help.
973
974 With a C<cmd> parameter, this displays detailed help for that command.
975
976 =head2 quit | exit
977
978 This exits guestfish.  You can also use C<^D> key.
979
980 @FISH_COMMANDS@
981
982 =head1 COMMANDS
983
984 @ACTIONS@
985
986 =head1 EXIT CODE
987
988 guestfish returns 0 if the commands completed without error, or
989 1 if there was an error.
990
991 =head1 ENVIRONMENT VARIABLES
992
993 =over 4
994
995 =item EDITOR
996
997 The C<edit> command uses C<$EDITOR> as the editor.  If not
998 set, it uses C<vi>.
999
1000 =item GUESTFISH_PID
1001
1002 Used with the I<--remote> option to specify the remote guestfish
1003 process to control.  See section
1004 L</REMOTE CONTROL GUESTFISH OVER A SOCKET>.
1005
1006 =item HEXEDITOR
1007
1008 The L</hexedit> command uses C<$HEXEDITOR> as the external hex
1009 editor.  If not specified, the external L<hexedit(1)> program
1010 is used.
1011
1012 =item HOME
1013
1014 If compiled with GNU readline support, various files in the
1015 home directory can be used.  See L</FILES>.
1016
1017 =item LIBGUESTFS_APPEND
1018
1019 Pass additional options to the guest kernel.
1020
1021 =item LIBGUESTFS_DEBUG
1022
1023 Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages.  This has the
1024 same effect as using the B<-v> option.
1025
1026 =item LIBGUESTFS_MEMSIZE
1027
1028 Set the memory allocated to the qemu process, in megabytes.  For
1029 example:
1030
1031  LIBGUESTFS_MEMSIZE=700
1032
1033 =item LIBGUESTFS_PATH
1034
1035 Set the path that guestfish uses to search for kernel and initrd.img.
1036 See the discussion of paths in L<guestfs(3)>.
1037
1038 =item LIBGUESTFS_QEMU
1039
1040 Set the default qemu binary that libguestfs uses.  If not set, then
1041 the qemu which was found at compile time by the configure script is
1042 used.
1043
1044 =item LIBGUESTFS_TRACE
1045
1046 Set C<LIBGUESTFS_TRACE=1> to enable command traces.
1047
1048 =item PAGER
1049
1050 The C<more> command uses C<$PAGER> as the pager.  If not
1051 set, it uses C<more>.
1052
1053 =item TMPDIR
1054
1055 Location of temporary directory, defaults to C</tmp> except for the
1056 cached supermin appliance which defaults to C</var/tmp>.
1057
1058 If libguestfs was compiled to use the supermin appliance then the
1059 real appliance is cached in this directory, shared between all
1060 handles belonging to the same EUID.  You can use C<$TMPDIR> to
1061 configure another directory to use in case C</var/tmp> is not large
1062 enough.
1063
1064 =back
1065
1066 =head1 FILES
1067
1068 =over 4
1069
1070 =item $HOME/.guestfish
1071
1072 If compiled with GNU readline support, then the command history
1073 is saved in this file.
1074
1075 =item $HOME/.inputrc
1076
1077 =item /etc/inputrc
1078
1079 If compiled with GNU readline support, then these files can be used to
1080 configure readline.  For further information, please see
1081 L<readline(3)/INITIALIZATION FILE>.
1082
1083 To write rules which only apply to guestfish, use:
1084
1085  $if guestfish
1086  ...
1087  $endif
1088
1089 Variables that you can set in inputrc that change the behaviour
1090 of guestfish in useful ways include:
1091
1092 =over 4
1093
1094 =item completion-ignore-case (default: on)
1095
1096 By default, guestfish will ignore case when tab-completing
1097 paths on the disk.  Use:
1098
1099  set completion-ignore-case off
1100
1101 to make guestfish case sensitive.
1102
1103 =back
1104
1105 =item test1.img
1106
1107 =item test2.img (etc)
1108
1109 When using the C<-N> or C<--new> option, the prepared disk or
1110 filesystem will be created in the file C<test1.img> in the current
1111 directory.  The second use of C<-N> will use C<test2.img> and so on.
1112 Any existing file with the same name will be overwritten.
1113
1114 =back
1115
1116 =head1 SEE ALSO
1117
1118 L<guestfs(3)>,
1119 L<http://libguestfs.org/>,
1120 L<virt-cat(1)>,
1121 L<virt-copy-in(1)>,
1122 L<virt-copy-out(1)>,
1123 L<virt-df(1)>,
1124 L<virt-edit(1)>,
1125 L<virt-filesystems(1)>,
1126 L<virt-inspector(1)>,
1127 L<virt-list-filesystems(1)>,
1128 L<virt-list-partitions(1)>,
1129 L<virt-ls(1)>,
1130 L<virt-make-fs(1)>,
1131 L<virt-rescue(1)>,
1132 L<virt-resize(1)>,
1133 L<virt-tar(1)>,
1134 L<virt-tar-in(1)>,
1135 L<virt-tar-out(1)>,
1136 L<virt-win-reg(1)>,
1137 L<hexedit(1)>.
1138
1139 =head1 AUTHORS
1140
1141 Richard W.M. Jones (C<rjones at redhat dot com>)
1142
1143 =head1 COPYRIGHT
1144
1145 Copyright (C) 2009-2010 Red Hat Inc.
1146 L<http://libguestfs.org/>
1147
1148 This program is free software; you can redistribute it and/or modify
1149 it under the terms of the GNU General Public License as published by
1150 the Free Software Foundation; either version 2 of the License, or
1151 (at your option) any later version.
1152
1153 This program is distributed in the hope that it will be useful,
1154 but WITHOUT ANY WARRANTY; without even the implied warranty of
1155 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1156 GNU General Public License for more details.
1157
1158 You should have received a copy of the GNU General Public License
1159 along with this program; if not, write to the Free Software
1160 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.