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