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