1virt-customize(1)           Virtualization Support           virt-customize(1)
2
3
4

NAME

6       virt-customize - Customize a virtual machine
7

SYNOPSIS

9        virt-customize
10           [ -a disk.img [ -a disk.img ... ] | -d domname ]
11           [--attach ISOFILE] [--attach-format FORMAT]
12           [ -c URI | --connect URI ] [ -n | --dry-run ]
13           [ --format FORMAT] [ -m MB | --memsize MB ]
14           [ --network | --no-network ]
15           [ -q | --quiet ] [--smp N] [ -v | --verbose ] [-x]
16           [--append-line FILE:LINE] [--chmod PERMISSIONS:FILE]
17           [--commands-from-file FILENAME] [--copy SOURCE:DEST]
18           [--copy-in LOCALPATH:REMOTEDIR] [--delete PATH] [--edit FILE:EXPR]
19           [--firstboot SCRIPT] [--firstboot-command 'CMD+ARGS']
20           [--firstboot-install PKG,PKG..] [--hostname HOSTNAME]
21           [--install PKG,PKG..] [--link TARGET:LINK[:LINK..]] [--mkdir DIR]
22           [--move SOURCE:DEST] [--password USER:SELECTOR]
23           [--root-password SELECTOR] [--run SCRIPT]
24           [--run-command 'CMD+ARGS'] [--scrub FILE] [--sm-attach SELECTOR]
25           [--sm-register] [--sm-remove] [--sm-unregister]
26           [--ssh-inject USER[:SELECTOR]] [--truncate FILE]
27           [--truncate-recursive PATH] [--timezone TIMEZONE] [--touch FILE]
28           [--uninstall PKG,PKG..] [--update] [--upload FILE:DEST]
29           [--write FILE:CONTENT] [--no-logfile]
30           [--password-crypto md5|sha256|sha512] [--selinux-relabel]
31           [--sm-credentials SELECTOR]
32
33
34        virt-customize [ -V | --version ]
35

WARNING

37       Using "virt-customize" on live virtual machines, or concurrently with
38       other disk editing tools, can be dangerous, potentially causing disk
39       corruption.  The virtual machine must be shut down before you use this
40       command, and disk images must not be edited concurrently.
41

DESCRIPTION

43       Virt-customize can customize a virtual machine (disk image) by
44       installing packages, editing configuration files, and so on.
45
46       Virt-customize modifies the guest or disk image in place.  The guest
47       must be shut down.  If you want to preserve the existing contents of
48       the guest, you must snapshot, copy or clone the disk first.
49
50       You do not need to run virt-customize as root.  In fact we'd generally
51       recommend that you don't.
52
53       Related tools include: virt-sysprep(1) and virt-builder(1).
54

OPTIONS

56       --help
57           Display brief help.
58
59       -a file
60       --add file
61           Add file which should be a disk image from a virtual machine.
62
63           The format of the disk image is auto-detected.  To override this
64           and force a particular format use the --format option.
65
66       -a URI
67       --add URI
68           Add a remote disk.  The URI format is compatible with guestfish.
69           See "ADDING REMOTE STORAGE" in guestfish(1).
70
71       --attach ISOFILE
72           The given disk is attached to the libguestfs appliance.  This is
73           used to provide extra software repositories or other data for
74           customization.
75
76           You probably want to ensure the volume(s) or filesystems in the
77           attached disks are labelled (or use an ISO volume name) so that you
78           can mount them by label in your run-scripts:
79
80            mkdir /tmp/mount
81            mount LABEL=EXTRA /tmp/mount
82
83           You can have multiple --attach options, and the format can be any
84           disk format (not just an ISO).
85
86       --attach-format FORMAT
87           Specify the disk format for the next --attach option.  The "FORMAT"
88           is usually "raw" or "qcow2".  Use "raw" for ISOs.
89
90       --colors
91       --colours
92           Use ANSI colour sequences to colourize messages.  This is the
93           default when the output is a tty.  If the output of the program is
94           redirected to a file, ANSI colour sequences are disabled unless you
95           use this option.
96
97       -c URI
98       --connect URI
99           If using libvirt, connect to the given URI.  If omitted, then we
100           connect to the default libvirt hypervisor.
101
102           If you specify guest block devices directly (-a), then libvirt is
103           not used at all.
104
105       -d guest
106       --domain guest
107           Add all the disks from the named libvirt guest.  Domain UUIDs can
108           be used instead of names.
109
110       -n
111       --dry-run
112           Perform a read-only "dry run" on the guest.  This runs the sysprep
113           operation, but throws away any changes to the disk at the end.
114
115       --echo-keys
116           When prompting for keys and passphrases, virt-customize normally
117           turns echoing off so you cannot see what you are typing.  If you
118           are not worried about Tempest attacks and there is no one else in
119           the room you can specify this flag to see what you are typing.
120
121       --format raw|qcow2|..
122       --format auto
123           The default for the -a option is to auto-detect the format of the
124           disk image.  Using this forces the disk format for -a options which
125           follow on the command line.  Using --format auto switches back to
126           auto-detection for subsequent -a options.
127
128           For example:
129
130            virt-customize --format raw -a disk.img
131
132           forces raw format (no auto-detection) for disk.img.
133
134            virt-customize --format raw -a disk.img --format auto -a another.img
135
136           forces raw format (no auto-detection) for disk.img and reverts to
137           auto-detection for another.img.
138
139           If you have untrusted raw-format guest disk images, you should use
140           this option to specify the disk format.  This avoids a possible
141           security problem with malicious guests (CVE-2010-3851).
142
143       --keys-from-stdin
144           Read key or passphrase parameters from stdin.  The default is to
145           try to read passphrases from the user by opening /dev/tty.
146
147       -m MB
148       --memsize MB
149           Change the amount of memory allocated to --run scripts.  Increase
150           this if you find that --run scripts or the --install option are
151           running out of memory.
152
153           The default can be found with this command:
154
155            guestfish get-memsize
156
157       --network
158       --no-network
159           Enable or disable network access from the guest during the
160           installation.
161
162           Enabled is the default.  Use --no-network to disable access.
163
164           The network only allows outgoing connections and has other minor
165           limitations.  See "NETWORK" in virt-rescue(1).
166
167           If you use --no-network then certain other options such as
168           --install will not work.
169
170           This does not affect whether the guest can access the network once
171           it has been booted, because that is controlled by your hypervisor
172           or cloud environment and has nothing to do with virt-customize.
173
174           Generally speaking you should not use --no-network.  But here are
175           some reasons why you might want to:
176
177           1.  Because the libguestfs backend that you are using doesn't
178               support the network.  (See: "BACKEND" in guestfs(3)).
179
180           2.  Any software you need to install comes from an attached ISO, so
181               you don't need the network.
182
183           3.  You don’t want untrusted guest code trying to access your host
184               network when running virt-customize.  This is particularly an
185               issue when you don't trust the source of the operating system
186               templates.  (See "SECURITY" below).
187
188           4.  You don’t have a host network (eg. in secure/restricted
189               environments).
190
191       -q
192       --quiet
193           Don’t print log messages.
194
195           To enable detailed logging of individual file operations, use -x.
196
197       --smp N
198           Enable N ≥ 2 virtual CPUs for --run scripts to use.
199
200       -v
201       --verbose
202           Enable verbose messages for debugging.
203
204       -V
205       --version
206           Display version number and exit.
207
208       -x  Enable tracing of libguestfs API calls.
209
210   Customization options
211       --append-line FILE:LINE
212           Append a single line of text to the "FILE".  If the file does not
213           already end with a newline, then one is added before the appended
214           line.  Also a newline is added to the end of the "LINE" string
215           automatically.
216
217           For example (assuming ordinary shell quoting) this command:
218
219            --append-line '/etc/hosts:10.0.0.1 foo'
220
221           will add either "10.0.0.1 foo⏎" or "⏎10.0.0.1 foo⏎" to the file,
222           the latter only if the existing file does not already end with a
223           newline.
224
225           "⏎" represents a newline character, which is guessed by looking at
226           the existing content of the file, so this command does the right
227           thing for files using Unix or Windows line endings.  It also works
228           for empty or non-existent files.
229
230           To insert several lines, use the same option several times:
231
232            --append-line '/etc/hosts:10.0.0.1 foo'
233            --append-line '/etc/hosts:10.0.0.2 bar'
234
235           To insert a blank line before the appended line, do:
236
237            --append-line '/etc/hosts:'
238            --append-line '/etc/hosts:10.0.0.1 foo'
239
240       --chmod PERMISSIONS:FILE
241           Change the permissions of "FILE" to "PERMISSIONS".
242
243           Note: "PERMISSIONS" by default would be decimal, unless you prefix
244           it with 0 to get octal, ie. use 0700 not 700.
245
246       --commands-from-file FILENAME
247           Read the customize commands from a file, one (and its arguments)
248           each line.
249
250           Each line contains a single customization command and its
251           arguments, for example:
252
253            delete /some/file
254            install some-package
255            password some-user:password:its-new-password
256
257           Empty lines are ignored, and lines starting with "#" are comments
258           and are ignored as well.  Furthermore, arguments can be spread
259           across multiple lines, by adding a "\" (continuation character) at
260           the of a line, for example
261
262            edit /some/file:\
263              s/^OPT=.*/OPT=ok/
264
265           The commands are handled in the same order as they are in the file,
266           as if they were specified as --delete /some/file on the command
267           line.
268
269       --copy SOURCE:DEST
270           Copy files or directories recursively inside the guest.
271
272           Wildcards cannot be used.
273
274       --copy-in LOCALPATH:REMOTEDIR
275           Copy local files or directories recursively into the disk image,
276           placing them in the directory "REMOTEDIR" (which must exist).
277
278           Wildcards cannot be used.
279
280       --delete PATH
281           Delete a file from the guest.  Or delete a directory (and all its
282           contents, recursively).
283
284           You can use shell glob characters in the specified path.  Be
285           careful to escape glob characters from the host shell, if that is
286           required.  For example:
287
288            virt-customize --delete '/var/log/*.log'.
289
290           See also: --upload, --scrub.
291
292       --edit FILE:EXPR
293           Edit "FILE" using the Perl expression "EXPR".
294
295           Be careful to properly quote the expression to prevent it from
296           being altered by the shell.
297
298           Note that this option is only available when Perl 5 is installed.
299
300           See "NON-INTERACTIVE EDITING" in virt-edit(1).
301
302       --firstboot SCRIPT
303           Install "SCRIPT" inside the guest, so that when the guest first
304           boots up, the script runs (as root, late in the boot process).
305
306           The script is automatically chmod +x after installation in the
307           guest.
308
309           The alternative version --firstboot-command is the same, but it
310           conveniently wraps the command up in a single line script for you.
311
312           You can have multiple --firstboot options.  They run in the same
313           order that they appear on the command line.
314
315           Please take a look at "FIRST BOOT SCRIPTS" in virt-builder(1) for
316           more information and caveats about the first boot scripts.
317
318           See also --run.
319
320       --firstboot-command 'CMD+ARGS'
321           Run command (and arguments) inside the guest when the guest first
322           boots up (as root, late in the boot process).
323
324           You can have multiple --firstboot options.  They run in the same
325           order that they appear on the command line.
326
327           Please take a look at "FIRST BOOT SCRIPTS" in virt-builder(1) for
328           more information and caveats about the first boot scripts.
329
330           See also --run.
331
332       --firstboot-install PKG,PKG..
333           Install the named packages (a comma-separated list).  These are
334           installed when the guest first boots using the guest’s package
335           manager (eg. apt, yum, etc.) and the guest’s network connection.
336
337           For an overview on the different ways to install packages, see
338           "INSTALLING PACKAGES" in virt-builder(1).
339
340       --hostname HOSTNAME
341           Set the hostname of the guest to "HOSTNAME".  You can use a dotted
342           hostname.domainname (FQDN) if you want.
343
344       --install PKG,PKG..
345           Install the named packages (a comma-separated list).  These are
346           installed during the image build using the guest’s package manager
347           (eg. apt, yum, etc.) and the host’s network connection.
348
349           For an overview on the different ways to install packages, see
350           "INSTALLING PACKAGES" in virt-builder(1).
351
352           See also --update, --uninstall.
353
354       --link TARGET:LINK[:LINK..]
355           Create symbolic link(s) in the guest, starting at "LINK" and
356           pointing at "TARGET".
357
358       --mkdir DIR
359           Create a directory in the guest.
360
361           This uses "mkdir -p" so any intermediate directories are created,
362           and it also works if the directory already exists.
363
364       --move SOURCE:DEST
365           Move files or directories inside the guest.
366
367           Wildcards cannot be used.
368
369       --no-logfile
370           Scrub "builder.log" (log file from build commands) from the image
371           after building is complete.  If you don't want to reveal precisely
372           how the image was built, use this option.
373
374           See also: "LOG FILE".
375
376       --password USER:SELECTOR
377           Set the password for "USER".  (Note this option does not create the
378           user account).
379
380           See "USERS AND PASSWORDS" in virt-builder(1) for the format of the
381           "SELECTOR" field, and also how to set up user accounts.
382
383       --password-crypto md5|sha256|sha512
384           When the virt tools change or set a password in the guest, this
385           option sets the password encryption of that password to "md5",
386           "sha256" or "sha512".
387
388           "sha256" and "sha512" require glibc ≥ 2.7 (check crypt(3) inside
389           the guest).
390
391           "md5" will work with relatively old Linux guests (eg. RHEL 3), but
392           is not secure against modern attacks.
393
394           The default is "sha512" unless libguestfs detects an old guest that
395           didn't have support for SHA-512, in which case it will use "md5".
396           You can override libguestfs by specifying this option.
397
398           Note this does not change the default password encryption used by
399           the guest when you create new user accounts inside the guest.  If
400           you want to do that, then you should use the --edit option to
401           modify "/etc/sysconfig/authconfig" (Fedora, RHEL) or
402           "/etc/pam.d/common-password" (Debian, Ubuntu).
403
404       --root-password SELECTOR
405           Set the root password.
406
407           See "USERS AND PASSWORDS" in virt-builder(1) for the format of the
408           "SELECTOR" field, and also how to set up user accounts.
409
410           Note: In virt-builder, if you don't set --root-password then the
411           guest is given a random root password.
412
413       --run SCRIPT
414           Run the shell script (or any program) called "SCRIPT" on the disk
415           image.  The script runs virtualized inside a small appliance,
416           chrooted into the guest filesystem.
417
418           The script is automatically chmod +x.
419
420           If libguestfs supports it then a limited network connection is
421           available but it only allows outgoing network connections.  You can
422           also attach data disks (eg. ISO files) as another way to provide
423           data (eg. software packages) to the script without needing a
424           network connection (--attach).  You can also upload data files
425           (--upload).
426
427           You can have multiple --run options.  They run in the same order
428           that they appear on the command line.
429
430           See also: --firstboot, --attach, --upload.
431
432       --run-command 'CMD+ARGS'
433           Run the command and arguments on the disk image.  The command runs
434           virtualized inside a small appliance, chrooted into the guest
435           filesystem.
436
437           If libguestfs supports it then a limited network connection is
438           available but it only allows outgoing network connections.  You can
439           also attach data disks (eg. ISO files) as another way to provide
440           data (eg. software packages) to the script without needing a
441           network connection (--attach).  You can also upload data files
442           (--upload).
443
444           You can have multiple --run-command options.  They run in the same
445           order that they appear on the command line.
446
447           See also: --firstboot, --attach, --upload.
448
449       --scrub FILE
450           Scrub a file from the guest.  This is like --delete except that:
451
452           ·   It scrubs the data so a guest could not recover it.
453
454           ·   It cannot delete directories, only regular files.
455
456       --selinux-relabel
457           Relabel files in the guest so that they have the correct SELinux
458           label.
459
460           This will attempt to relabel files immediately, but if the
461           operation fails this will instead touch /.autorelabel on the image
462           to schedule a relabel operation for the next time the image boots.
463
464           You should only use this option for guests which support SELinux.
465
466       --sm-attach SELECTOR
467           Attach to a pool using "subscription-manager".
468
469           See "SUBSCRIPTION-MANAGER" in virt-builder(1) for the format of the
470           "SELECTOR" field.
471
472       --sm-credentials SELECTOR
473           Set the credentials for "subscription-manager".
474
475           See "SUBSCRIPTION-MANAGER" in virt-builder(1) for the format of the
476           "SELECTOR" field.
477
478       --sm-register
479           Register the guest using "subscription-manager".
480
481           This requires credentials being set using --sm-credentials.
482
483       --sm-remove
484           Remove all the subscriptions from the guest using
485           "subscription-manager".
486
487       --sm-unregister
488           Unregister the guest using "subscription-manager".
489
490       --ssh-inject USER[:SELECTOR]
491           Inject an ssh key so the given "USER" will be able to log in over
492           ssh without supplying a password.  The "USER" must exist already in
493           the guest.
494
495           See "SSH KEYS" in virt-builder(1) for the format of the "SELECTOR"
496           field.
497
498           You can have multiple --ssh-inject options, for different users and
499           also for more keys for each user.
500
501       --timezone TIMEZONE
502           Set the default timezone of the guest to "TIMEZONE".  Use a
503           location string like "Europe/London"
504
505       --touch FILE
506           This command performs a touch(1)-like operation on "FILE".
507
508       --truncate FILE
509           This command truncates "FILE" to a zero-length file. The file must
510           exist already.
511
512       --truncate-recursive PATH
513           This command recursively truncates all files under "PATH" to zero-
514           length.
515
516       --uninstall PKG,PKG..
517           Uninstall the named packages (a comma-separated list).  These are
518           removed during the image build using the guest’s package manager
519           (eg. apt, yum, etc.).  Dependent packages may also need to be
520           uninstalled to satisfy the request.
521
522           See also --install, --update.
523
524       --update
525           Do the equivalent of "yum update", "apt-get upgrade", or whatever
526           command is required to update the packages already installed in the
527           template to their latest versions.
528
529           See also --install, --uninstall.
530
531       --upload FILE:DEST
532           Upload local file "FILE" to destination "DEST" in the disk image.
533           File owner and permissions from the original are preserved, so you
534           should set them to what you want them to be in the disk image.
535
536           "DEST" could be the final filename.  This can be used to rename the
537           file on upload.
538
539           If "DEST" is a directory name (which must already exist in the
540           guest) then the file is uploaded into that directory, and it keeps
541           the same name as on the local filesystem.
542
543           See also: --mkdir, --delete, --scrub.
544
545       --write FILE:CONTENT
546           Write "CONTENT" to "FILE".
547

SELINUX

549       For guests which make use of SELinux, special handling for them might
550       be needed when using operations which create new files or alter
551       existing ones.
552
553       For further details, see "SELINUX" in virt-builder(1).
554

EXIT STATUS

556       This program returns 0 on success, or 1 if there was an error.
557

ENVIRONMENT VARIABLES

559       "VIRT_TOOLS_DATA_DIR"
560           This can point to the directory containing data files used for
561           Windows firstboot installation.
562
563           Normally you do not need to set this.  If not set, a compiled-in
564           default will be used (something like /usr/share/virt-tools).
565
566           This directory may contain the following files:
567
568           rhsrvany.exe
569               This is the RHSrvAny Windows binary, used to install a
570               "firstboot" script in Windows guests.  It is required if you
571               intend to use the --firstboot or --firstboot-command options
572               with Windows guests.
573
574               See also: "https://github.com/rwmjones/rhsrvany"
575
576           pvvxsvc.exe
577               This is a Windows binary shipped with SUSE VMDP, used to
578               install a "firstboot" script in Windows guests.  It is required
579               if you intend to use the --firstboot or --firstboot-command
580               options with Windows guests.
581
582       For other environment variables, see "ENVIRONMENT VARIABLES" in
583       guestfs(3).
584

SEE ALSO

586       guestfs(3), guestfish(1), virt-builder(1), virt-clone(1),
587       virt-rescue(1), virt-resize(1), virt-sparsify(1), virt-sysprep(1),
588       virsh(1), lvcreate(8), qemu-img(1), scrub(1), http://libguestfs.org/,
589       http://libvirt.org/.
590

AUTHORS

592       Richard W.M. Jones http://people.redhat.com/~rjones/
593
595       Copyright (C) 2011-2018 Red Hat Inc.
596

LICENSE

598       This program is free software; you can redistribute it and/or modify it
599       under the terms of the GNU General Public License as published by the
600       Free Software Foundation; either version 2 of the License, or (at your
601       option) any later version.
602
603       This program is distributed in the hope that it will be useful, but
604       WITHOUT ANY WARRANTY; without even the implied warranty of
605       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
606       General Public License for more details.
607
608       You should have received a copy of the GNU General Public License along
609       with this program; if not, write to the Free Software Foundation, Inc.,
610       51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
611

BUGS

613       To get a list of bugs against libguestfs, use this link:
614       https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools
615
616       To report a new bug against libguestfs, use this link:
617       https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools
618
619       When reporting a bug, please supply:
620
621       ·   The version of libguestfs.
622
623       ·   Where you got libguestfs (eg. which Linux distro, compiled from
624           source, etc)
625
626       ·   Describe the bug accurately and give a way to reproduce it.
627
628       ·   Run libguestfs-test-tool(1) and paste the complete, unedited output
629           into the bug report.
630
631
632
633libguestfs-1.38.2                 2018-05-15                 virt-customize(1)
Impressum