Implement upload and download commands.
[libguestfs.git] / guestfish-actions.pod
1 =head2 add-cdrom | cdrom
2
3  add-cdrom filename
4
5 This function adds a virtual CD-ROM disk image to the guest.
6
7 This is equivalent to the qemu parameter C<-cdrom filename>.
8
9 =head2 add-drive | add
10
11  add-drive filename
12
13 This function adds a virtual machine disk image C<filename> to the
14 guest.  The first time you call this function, the disk appears as IDE
15 disk 0 (C</dev/sda>) in the guest, the second time as C</dev/sdb>, and
16 so on.
17
18 You don't necessarily need to be root when using libguestfs.  However
19 you obviously do need sufficient permissions to access the filename
20 for whatever operations you want to perform (ie. read access if you
21 just want to read the image or write access if you want to modify the
22 image).
23
24 This is equivalent to the qemu parameter C<-drive file=filename>.
25
26 =head2 aug-close
27
28  aug-close
29
30 Close the current Augeas handle and free up any resources
31 used by it.  After calling this, you have to call
32 C<aug_init> again before you can use any other
33 Augeas functions.
34
35 =head2 aug-defnode
36
37  aug-defnode name expr val
38
39 Defines a variable C<name> whose value is the result of
40 evaluating C<expr>.
41
42 If C<expr> evaluates to an empty nodeset, a node is created,
43 equivalent to calling C<aug_set> C<expr>, C<value>.
44 C<name> will be the nodeset containing that single node.
45
46 On success this returns a pair containing the
47 number of nodes in the nodeset, and a boolean flag
48 if a node was created.
49
50 =head2 aug-defvar
51
52  aug-defvar name expr
53
54 Defines an Augeas variable C<name> whose value is the result
55 of evaluating C<expr>.  If C<expr> is NULL, then C<name> is
56 undefined.
57
58 On success this returns the number of nodes in C<expr>, or
59 C<0> if C<expr> evaluates to something which is not a nodeset.
60
61 =head2 aug-get
62
63  aug-get path
64
65 Look up the value associated with C<path>.  If C<path>
66 matches exactly one node, the C<value> is returned.
67
68 =head2 aug-init
69
70  aug-init root flags
71
72 Create a new Augeas handle for editing configuration files.
73 If there was any previous Augeas handle associated with this
74 guestfs session, then it is closed.
75
76 You must call this before using any other C<aug_*>
77 commands.
78
79 C<root> is the filesystem root.  C<root> must not be NULL,
80 use C</> instead.
81
82 The flags are the same as the flags defined in
83 E<lt>augeas.hE<gt>, the logical I<or> of the following
84 integers:
85
86 =over 4
87
88 =item C<AUG_SAVE_BACKUP> = 1
89
90 Keep the original file with a C<.augsave> extension.
91
92 =item C<AUG_SAVE_NEWFILE> = 2
93
94 Save changes into a file with extension C<.augnew>, and
95 do not overwrite original.  Overrides C<AUG_SAVE_BACKUP>.
96
97 =item C<AUG_TYPE_CHECK> = 4
98
99 Typecheck lenses (can be expensive).
100
101 =item C<AUG_NO_STDINC> = 8
102
103 Do not use standard load path for modules.
104
105 =item C<AUG_SAVE_NOOP> = 16
106
107 Make save a no-op, just record what would have been changed.
108
109 =item C<AUG_NO_LOAD> = 32
110
111 Do not load the tree in C<aug_init>.
112
113 =back
114
115 To close the handle, you can call C<aug_close>.
116
117 To find out more about Augeas, see L<http://augeas.net/>.
118
119 =head2 aug-insert
120
121  aug-insert path label true|false
122
123 Create a new sibling C<label> for C<path>, inserting it into
124 the tree before or after C<path> (depending on the boolean
125 flag C<before>).
126
127 C<path> must match exactly one existing node in the tree, and
128 C<label> must be a label, ie. not contain C</>, C<*> or end
129 with a bracketed index C<[N]>.
130
131 =head2 aug-load
132
133  aug-load
134
135 Load files into the tree.
136
137 See C<aug_load> in the Augeas documentation for the full gory
138 details.
139
140 =head2 aug-ls
141
142  aug-ls path
143
144 This is just a shortcut for listing C<aug_match>
145 C<path/*> and sorting the resulting nodes into alphabetical order.
146
147 =head2 aug-match
148
149  aug-match path
150
151 Returns a list of paths which match the path expression C<path>.
152 The returned paths are sufficiently qualified so that they match
153 exactly one node in the current tree.
154
155 =head2 aug-mv
156
157  aug-mv src dest
158
159 Move the node C<src> to C<dest>.  C<src> must match exactly
160 one node.  C<dest> is overwritten if it exists.
161
162 =head2 aug-rm
163
164  aug-rm path
165
166 Remove C<path> and all of its children.
167
168 On success this returns the number of entries which were removed.
169
170 =head2 aug-save
171
172  aug-save
173
174 This writes all pending changes to disk.
175
176 The flags which were passed to C<aug_init> affect exactly
177 how files are saved.
178
179 =head2 aug-set
180
181  aug-set path val
182
183 Set the value associated with C<path> to C<value>.
184
185 =head2 blockdev-flushbufs
186
187  blockdev-flushbufs device
188
189 This tells the kernel to flush internal buffers associated
190 with C<device>.
191
192 This uses the L<blockdev(8)> command.
193
194 =head2 blockdev-getbsz
195
196  blockdev-getbsz device
197
198 This returns the block size of a device.
199
200 (Note this is different from both I<size in blocks> and
201 I<filesystem block size>).
202
203 This uses the L<blockdev(8)> command.
204
205 =head2 blockdev-getro
206
207  blockdev-getro device
208
209 Returns a boolean indicating if the block device is read-only
210 (true if read-only, false if not).
211
212 This uses the L<blockdev(8)> command.
213
214 =head2 blockdev-getsize64
215
216  blockdev-getsize64 device
217
218 This returns the size of the device in bytes.
219
220 See also C<blockdev_getsz>.
221
222 This uses the L<blockdev(8)> command.
223
224 =head2 blockdev-getss
225
226  blockdev-getss device
227
228 This returns the size of sectors on a block device.
229 Usually 512, but can be larger for modern devices.
230
231 (Note, this is not the size in sectors, use C<blockdev_getsz>
232 for that).
233
234 This uses the L<blockdev(8)> command.
235
236 =head2 blockdev-getsz
237
238  blockdev-getsz device
239
240 This returns the size of the device in units of 512-byte sectors
241 (even if the sectorsize isn't 512 bytes ... weird).
242
243 See also C<blockdev_getss> for the real sector size of
244 the device, and C<blockdev_getsize64> for the more
245 useful I<size in bytes>.
246
247 This uses the L<blockdev(8)> command.
248
249 =head2 blockdev-rereadpt
250
251  blockdev-rereadpt device
252
253 Reread the partition table on C<device>.
254
255 This uses the L<blockdev(8)> command.
256
257 =head2 blockdev-setbsz
258
259  blockdev-setbsz device blocksize
260
261 This sets the block size of a device.
262
263 (Note this is different from both I<size in blocks> and
264 I<filesystem block size>).
265
266 This uses the L<blockdev(8)> command.
267
268 =head2 blockdev-setro
269
270  blockdev-setro device
271
272 Sets the block device named C<device> to read-only.
273
274 This uses the L<blockdev(8)> command.
275
276 =head2 blockdev-setrw
277
278  blockdev-setrw device
279
280 Sets the block device named C<device> to read-write.
281
282 This uses the L<blockdev(8)> command.
283
284 =head2 cat
285
286  cat path
287
288 Return the contents of the file named C<path>.
289
290 Note that this function cannot correctly handle binary files
291 (specifically, files containing C<\0> character which is treated
292 as end of string).  For those you need to use the C<download>
293 function which has a more complex interface.
294
295 Because of the message protocol, there is a transfer limit 
296 of somewhere between 2MB and 4MB.  To transfer large files you should use
297 FTP.
298
299 =head2 chmod
300
301  chmod mode path
302
303 Change the mode (permissions) of C<path> to C<mode>.  Only
304 numeric modes are supported.
305
306 =head2 chown
307
308  chown owner group path
309
310 Change the file owner to C<owner> and group to C<group>.
311
312 Only numeric uid and gid are supported.  If you want to use
313 names, you will need to locate and parse the password file
314 yourself (Augeas support makes this relatively easy).
315
316 =head2 command
317
318  command arguments,...
319
320 This call runs a command from the guest filesystem.  The
321 filesystem must be mounted, and must contain a compatible
322 operating system (ie. something Linux, with the same
323 or compatible processor architecture).
324
325 The single parameter is an argv-style list of arguments.
326 The first element is the name of the program to run.
327 Subsequent elements are parameters.  The list must be
328 non-empty (ie. must contain a program name).
329
330 The C<$PATH> environment variable will contain at least
331 C</usr/bin> and C</bin>.  If you require a program from
332 another location, you should provide the full path in the
333 first parameter.
334
335 Shared libraries and data files required by the program
336 must be available on filesystems which are mounted in the
337 correct places.  It is the caller's responsibility to ensure
338 all filesystems that are needed are mounted at the right
339 locations.
340
341 =head2 command-lines
342
343  command-lines arguments,...
344
345 This is the same as C<command>, but splits the
346 result into a list of lines.
347
348 =head2 config
349
350  config qemuparam qemuvalue
351
352 This can be used to add arbitrary qemu command line parameters
353 of the form C<-param value>.  Actually it's not quite arbitrary - we
354 prevent you from setting some parameters which would interfere with
355 parameters that we use.
356
357 The first character of C<param> string must be a C<-> (dash).
358
359 C<value> can be NULL.
360
361 =head2 download
362
363  download remotefilename (filename|-)
364
365 Download file C<remotefilename> and save it as C<filename>
366 on the local machine.
367
368 C<filename> can also be a named pipe.
369
370 See also C<upload>, C<cat>.
371
372 Use C<-> instead of a filename to read/write from stdin/stdout.
373
374 =head2 exists
375
376  exists path
377
378 This returns C<true> if and only if there is a file, directory
379 (or anything) with the given C<path> name.
380
381 See also C<is_file>, C<is_dir>, C<stat>.
382
383 =head2 file
384
385  file path
386
387 This call uses the standard L<file(1)> command to determine
388 the type or contents of the file.  This also works on devices,
389 for example to find out whether a partition contains a filesystem.
390
391 The exact command which runs is C<file -bsL path>.  Note in
392 particular that the filename is not prepended to the output
393 (the C<-b> option).
394
395 =head2 get-autosync
396
397  get-autosync
398
399 Get the autosync flag.
400
401 =head2 get-path
402
403  get-path
404
405 Return the current search path.
406
407 This is always non-NULL.  If it wasn't set already, then this will
408 return the default path.
409
410 =head2 get-state
411
412  get-state
413
414 This returns the current state as an opaque integer.  This is
415 only useful for printing debug and internal error messages.
416
417 For more information on states, see L<guestfs(3)>.
418
419 =head2 get-verbose
420
421  get-verbose
422
423 This returns the verbose messages flag.
424
425 =head2 is-busy
426
427  is-busy
428
429 This returns true iff this handle is busy processing a command
430 (in the C<BUSY> state).
431
432 For more information on states, see L<guestfs(3)>.
433
434 =head2 is-config
435
436  is-config
437
438 This returns true iff this handle is being configured
439 (in the C<CONFIG> state).
440
441 For more information on states, see L<guestfs(3)>.
442
443 =head2 is-dir
444
445  is-dir path
446
447 This returns C<true> if and only if there is a directory
448 with the given C<path> name.  Note that it returns false for
449 other objects like files.
450
451 See also C<stat>.
452
453 =head2 is-file
454
455  is-file path
456
457 This returns C<true> if and only if there is a file
458 with the given C<path> name.  Note that it returns false for
459 other objects like directories.
460
461 See also C<stat>.
462
463 =head2 is-launching
464
465  is-launching
466
467 This returns true iff this handle is launching the subprocess
468 (in the C<LAUNCHING> state).
469
470 For more information on states, see L<guestfs(3)>.
471
472 =head2 is-ready
473
474  is-ready
475
476 This returns true iff this handle is ready to accept commands
477 (in the C<READY> state).
478
479 For more information on states, see L<guestfs(3)>.
480
481 =head2 kill-subprocess
482
483  kill-subprocess
484
485 This kills the qemu subprocess.  You should never need to call this.
486
487 =head2 launch | run
488
489  launch
490
491 Internally libguestfs is implemented by running a virtual machine
492 using L<qemu(1)>.
493
494 You should call this after configuring the handle
495 (eg. adding drives) but before performing any actions.
496
497 =head2 list-devices
498
499  list-devices
500
501 List all the block devices.
502
503 The full block device names are returned, eg. C</dev/sda>
504
505 =head2 list-partitions
506
507  list-partitions
508
509 List all the partitions detected on all block devices.
510
511 The full partition device names are returned, eg. C</dev/sda1>
512
513 This does not return logical volumes.  For that you will need to
514 call C<lvs>.
515
516 =head2 ll
517
518  ll directory
519
520 List the files in C<directory> (relative to the root directory,
521 there is no cwd) in the format of 'ls -la'.
522
523 This command is mostly useful for interactive sessions.  It
524 is I<not> intended that you try to parse the output string.
525
526 =head2 ls
527
528  ls directory
529
530 List the files in C<directory> (relative to the root directory,
531 there is no cwd).  The '.' and '..' entries are not returned, but
532 hidden files are shown.
533
534 This command is mostly useful for interactive sessions.  Programs
535 should probably use C<readdir> instead.
536
537 =head2 lstat
538
539  lstat path
540
541 Returns file information for the given C<path>.
542
543 This is the same as C<stat> except that if C<path>
544 is a symbolic link, then the link is stat-ed, not the file it
545 refers to.
546
547 This is the same as the C<lstat(2)> system call.
548
549 =head2 lvcreate
550
551  lvcreate logvol volgroup mbytes
552
553 This creates an LVM volume group called C<logvol>
554 on the volume group C<volgroup>, with C<size> megabytes.
555
556 =head2 lvm-remove-all
557
558  lvm-remove-all
559
560 This command removes all LVM logical volumes, volume groups
561 and physical volumes.
562
563 B<This command is dangerous.  Without careful use you
564 can easily destroy all your data>.
565
566 =head2 lvs
567
568  lvs
569
570 List all the logical volumes detected.  This is the equivalent
571 of the L<lvs(8)> command.
572
573 This returns a list of the logical volume device names
574 (eg. C</dev/VolGroup00/LogVol00>).
575
576 See also C<lvs_full>.
577
578 =head2 lvs-full
579
580  lvs-full
581
582 List all the logical volumes detected.  This is the equivalent
583 of the L<lvs(8)> command.  The "full" version includes all fields.
584
585 =head2 mkdir
586
587  mkdir path
588
589 Create a directory named C<path>.
590
591 =head2 mkdir-p
592
593  mkdir-p path
594
595 Create a directory named C<path>, creating any parent directories
596 as necessary.  This is like the C<mkdir -p> shell command.
597
598 =head2 mkfs
599
600  mkfs fstype device
601
602 This creates a filesystem on C<device> (usually a partition
603 of LVM logical volume).  The filesystem type is C<fstype>, for
604 example C<ext3>.
605
606 =head2 mount
607
608  mount device mountpoint
609
610 Mount a guest disk at a position in the filesystem.  Block devices
611 are named C</dev/sda>, C</dev/sdb> and so on, as they were added to
612 the guest.  If those block devices contain partitions, they will have
613 the usual names (eg. C</dev/sda1>).  Also LVM C</dev/VG/LV>-style
614 names can be used.
615
616 The rules are the same as for L<mount(2)>:  A filesystem must
617 first be mounted on C</> before others can be mounted.  Other
618 filesystems can only be mounted on directories which already
619 exist.
620
621 The mounted filesystem is writable, if we have sufficient permissions
622 on the underlying device.
623
624 The filesystem options C<sync> and C<noatime> are set with this
625 call, in order to improve reliability.
626
627 =head2 mounts
628
629  mounts
630
631 This returns the list of currently mounted filesystems.  It returns
632 the list of devices (eg. C</dev/sda1>, C</dev/VG/LV>).
633
634 Some internal mounts are not shown.
635
636 =head2 pvcreate
637
638  pvcreate device
639
640 This creates an LVM physical volume on the named C<device>,
641 where C<device> should usually be a partition name such
642 as C</dev/sda1>.
643
644 =head2 pvs
645
646  pvs
647
648 List all the physical volumes detected.  This is the equivalent
649 of the L<pvs(8)> command.
650
651 This returns a list of just the device names that contain
652 PVs (eg. C</dev/sda2>).
653
654 See also C<pvs_full>.
655
656 =head2 pvs-full
657
658  pvs-full
659
660 List all the physical volumes detected.  This is the equivalent
661 of the L<pvs(8)> command.  The "full" version includes all fields.
662
663 =head2 read-lines
664
665  read-lines path
666
667 Return the contents of the file named C<path>.
668
669 The file contents are returned as a list of lines.  Trailing
670 C<LF> and C<CRLF> character sequences are I<not> returned.
671
672 Note that this function cannot correctly handle binary files
673 (specifically, files containing C<\0> character which is treated
674 as end of line).  For those you need to use the C<read_file>
675 function which has a more complex interface.
676
677 =head2 rm
678
679  rm path
680
681 Remove the single file C<path>.
682
683 =head2 rm-rf
684
685  rm-rf path
686
687 Remove the file or directory C<path>, recursively removing the
688 contents if its a directory.  This is like the C<rm -rf> shell
689 command.
690
691 =head2 rmdir
692
693  rmdir path
694
695 Remove the single directory C<path>.
696
697 =head2 set-autosync | autosync
698
699  set-autosync true|false
700
701 If C<autosync> is true, this enables autosync.  Libguestfs will make a
702 best effort attempt to run C<sync> when the handle is closed
703 (also if the program exits without closing handles).
704
705 =head2 set-path | path
706
707  set-path path
708
709 Set the path that libguestfs searches for kernel and initrd.img.
710
711 The default is C<$libdir/guestfs> unless overridden by setting
712 C<LIBGUESTFS_PATH> environment variable.
713
714 The string C<path> is stashed in the libguestfs handle, so the caller
715 must make sure it remains valid for the lifetime of the handle.
716
717 Setting C<path> to C<NULL> restores the default path.
718
719 =head2 set-verbose | verbose
720
721  set-verbose true|false
722
723 If C<verbose> is true, this turns on verbose messages (to C<stderr>).
724
725 Verbose messages are disabled unless the environment variable
726 C<LIBGUESTFS_DEBUG> is defined and set to C<1>.
727
728 =head2 sfdisk
729
730  sfdisk device cyls heads sectors lines,...
731
732 This is a direct interface to the L<sfdisk(8)> program for creating
733 partitions on block devices.
734
735 C<device> should be a block device, for example C</dev/sda>.
736
737 C<cyls>, C<heads> and C<sectors> are the number of cylinders, heads
738 and sectors on the device, which are passed directly to sfdisk as
739 the I<-C>, I<-H> and I<-S> parameters.  If you pass C<0> for any
740 of these, then the corresponding parameter is omitted.  Usually for
741 'large' disks, you can just pass C<0> for these, but for small
742 (floppy-sized) disks, sfdisk (or rather, the kernel) cannot work
743 out the right geometry and you will need to tell it.
744
745 C<lines> is a list of lines that we feed to C<sfdisk>.  For more
746 information refer to the L<sfdisk(8)> manpage.
747
748 To create a single partition occupying the whole disk, you would
749 pass C<lines> as a single element list, when the single element being
750 the string C<,> (comma).
751
752 B<This command is dangerous.  Without careful use you
753 can easily destroy all your data>.
754
755 =head2 stat
756
757  stat path
758
759 Returns file information for the given C<path>.
760
761 This is the same as the C<stat(2)> system call.
762
763 =head2 statvfs
764
765  statvfs path
766
767 Returns file system statistics for any mounted file system.
768 C<path> should be a file or directory in the mounted file system
769 (typically it is the mount point itself, but it doesn't need to be).
770
771 This is the same as the C<statvfs(2)> system call.
772
773 =head2 sync
774
775  sync
776
777 This syncs the disk, so that any writes are flushed through to the
778 underlying disk image.
779
780 You should always call this if you have modified a disk image, before
781 closing the handle.
782
783 =head2 touch
784
785  touch path
786
787 Touch acts like the L<touch(1)> command.  It can be used to
788 update the timestamps on a file, or, if the file does not exist,
789 to create a new zero-length file.
790
791 =head2 tune2fs-l
792
793  tune2fs-l device
794
795 This returns the contents of the ext2 or ext3 filesystem superblock
796 on C<device>.
797
798 It is the same as running C<tune2fs -l device>.  See L<tune2fs(8)>
799 manpage for more details.  The list of fields returned isn't
800 clearly defined, and depends on both the version of C<tune2fs>
801 that libguestfs was built against, and the filesystem itself.
802
803 =head2 umount | unmount
804
805  umount pathordevice
806
807 This unmounts the given filesystem.  The filesystem may be
808 specified either by its mountpoint (path) or the device which
809 contains the filesystem.
810
811 =head2 umount-all | unmount-all
812
813  umount-all
814
815 This unmounts all mounted filesystems.
816
817 Some internal mounts are not unmounted by this call.
818
819 =head2 upload
820
821  upload (filename|-) remotefilename
822
823 Upload local file C<filename> to C<remotefilename> on the
824 filesystem.
825
826 C<filename> can also be a named pipe.
827
828 See also C<download>.
829
830 Use C<-> instead of a filename to read/write from stdin/stdout.
831
832 =head2 vgcreate
833
834  vgcreate volgroup physvols,...
835
836 This creates an LVM volume group called C<volgroup>
837 from the non-empty list of physical volumes C<physvols>.
838
839 =head2 vgs
840
841  vgs
842
843 List all the volumes groups detected.  This is the equivalent
844 of the L<vgs(8)> command.
845
846 This returns a list of just the volume group names that were
847 detected (eg. C<VolGroup00>).
848
849 See also C<vgs_full>.
850
851 =head2 vgs-full
852
853  vgs-full
854
855 List all the volumes groups detected.  This is the equivalent
856 of the L<vgs(8)> command.  The "full" version includes all fields.
857
858 =head2 write-file
859
860  write-file path content size
861
862 This call creates a file called C<path>.  The contents of the
863 file is the string C<content> (which can contain any 8 bit data),
864 with length C<size>.
865
866 As a special case, if C<size> is C<0>
867 then the length is calculated using C<strlen> (so in this case
868 the content cannot contain embedded ASCII NULs).
869
870 Because of the message protocol, there is a transfer limit 
871 of somewhere between 2MB and 4MB.  To transfer large files you should use
872 FTP.
873