virt-customize(1) | Virtualization Support | virt-customize(1) |
virt-customize - Customize a virtual machine
virt-customize [ -a disk.img [ -a disk.img ... ] | -d domname ] [--attach ISOFILE] [--attach-format FORMAT] [ -c URI | --connect URI ] [ -n | --dry-run ] [ --format FORMAT] [ -m MB | --memsize MB ] [ --network | --no-network ] [ -q | --quiet ] [--smp N] [ -v | --verbose ] [-x] [--append-line FILE:LINE] [--chmod PERMISSIONS:FILE] [--commands-from-file FILENAME] [--copy SOURCE:DEST] [--copy-in LOCALPATH:REMOTEDIR] [--delete PATH] [--edit FILE:EXPR] [--firstboot SCRIPT] [--firstboot-command 'CMD+ARGS'] [--firstboot-install PKG,PKG..] [--hostname HOSTNAME] [--install PKG,PKG..] [--link TARGET:LINK[:LINK..]] [--mkdir DIR] [--move SOURCE:DEST] [--password USER:SELECTOR] [--root-password SELECTOR] [--run SCRIPT] [--run-command 'CMD+ARGS'] [--scrub FILE] [--sm-attach SELECTOR] [--sm-register] [--sm-remove] [--sm-unregister] [--ssh-inject USER[:SELECTOR]] [--truncate FILE] [--truncate-recursive PATH] [--timezone TIMEZONE] [--touch FILE] [--uninstall PKG,PKG..] [--update] [--upload FILE:DEST] [--write FILE:CONTENT] [--no-logfile] [--password-crypto md5|sha256|sha512] [--selinux-relabel] [--sm-credentials SELECTOR] virt-customize [ -V | --version ]
Using "virt-customize" on live virtual machines, or concurrently with other disk editing tools, can be dangerous, potentially causing disk corruption. The virtual machine must be shut down before you use this command, and disk images must not be edited concurrently.
Virt-customize can customize a virtual machine (disk image) by installing packages, editing configuration files, and so on.
Virt-customize modifies the guest or disk image in place. The guest must be shut down. If you want to preserve the existing contents of the guest, you must snapshot, copy or clone the disk first.
You do not need to run virt-customize as root. In fact we'd generally recommend that you don't.
Related tools include: virt-sysprep(1) and virt-builder(1).
The format of the disk image is auto-detected. To override this and force a particular format use the --format option.
You probably want to ensure the volume(s) or filesystems in the attached disks are labelled (or use an ISO volume name) so that you can mount them by label in your run-scripts:
mkdir /tmp/mount mount LABEL=EXTRA /tmp/mount
You can have multiple --attach options, and the format can be any disk format (not just an ISO).
If you specify guest block devices directly (-a), then libvirt is not used at all.
For example:
virt-customize --format raw -a disk.img
forces raw format (no auto-detection) for disk.img.
virt-customize --format raw -a disk.img --format auto -a another.img
forces raw format (no auto-detection) for disk.img and reverts to auto-detection for another.img.
If you have untrusted raw-format guest disk images, you should use this option to specify the disk format. This avoids a possible security problem with malicious guests (CVE-2010-3851).
The default can be found with this command:
guestfish get-memsize
Enabled is the default. Use --no-network to disable access.
The network only allows outgoing connections and has other minor limitations. See "NETWORK" in virt-rescue(1).
If you use --no-network then certain other options such as --install will not work.
This does not affect whether the guest can access the network once it has been booted, because that is controlled by your hypervisor or cloud environment and has nothing to do with virt-customize.
Generally speaking you should not use --no-network. But here are some reasons why you might want to:
To enable detailed logging of individual file operations, use -x.
For example (assuming ordinary shell quoting) this command:
--append-line '/etc/hosts:10.0.0.1 foo'
will add either "10.0.0.1 foo⏎" or "⏎10.0.0.1 foo⏎" to the file, the latter only if the existing file does not already end with a newline.
"⏎" represents a newline character, which is guessed by looking at the existing content of the file, so this command does the right thing for files using Unix or Windows line endings. It also works for empty or non-existent files.
To insert several lines, use the same option several times:
--append-line '/etc/hosts:10.0.0.1 foo' --append-line '/etc/hosts:10.0.0.2 bar'
To insert a blank line before the appended line, do:
--append-line '/etc/hosts:' --append-line '/etc/hosts:10.0.0.1 foo'
Note: "PERMISSIONS" by default would be decimal, unless you prefix it with 0 to get octal, ie. use 0700 not 700.
Each line contains a single customization command and its arguments, for example:
delete /some/file install some-package password some-user:password:its-new-password
Empty lines are ignored, and lines starting with "#" are comments and are ignored as well. Furthermore, arguments can be spread across multiple lines, by adding a "\" (continuation character) at the of a line, for example
edit /some/file:\ s/^OPT=.*/OPT=ok/
The commands are handled in the same order as they are in the file, as if they were specified as --delete /some/file on the command line.
Wildcards cannot be used.
Wildcards cannot be used.
You can use shell glob characters in the specified path. Be careful to escape glob characters from the host shell, if that is required. For example:
virt-customize --delete '/var/log/*.log'.
See also: --upload, --scrub.
Be careful to properly quote the expression to prevent it from being altered by the shell.
Note that this option is only available when Perl 5 is installed.
See "NON-INTERACTIVE EDITING" in virt-edit(1).
The script is automatically chmod +x after installation in the guest.
The alternative version --firstboot-command is the same, but it conveniently wraps the command up in a single line script for you.
You can have multiple --firstboot options. They run in the same order that they appear on the command line.
Please take a look at "FIRST BOOT SCRIPTS" in virt-builder(1) for more information and caveats about the first boot scripts.
See also --run.
You can have multiple --firstboot options. They run in the same order that they appear on the command line.
Please take a look at "FIRST BOOT SCRIPTS" in virt-builder(1) for more information and caveats about the first boot scripts.
See also --run.
For an overview on the different ways to install packages, see "INSTALLING PACKAGES" in virt-builder(1).
For an overview on the different ways to install packages, see "INSTALLING PACKAGES" in virt-builder(1).
See also --update, --uninstall.
This uses "mkdir -p" so any intermediate directories are created, and it also works if the directory already exists.
Wildcards cannot be used.
See also: "LOG FILE".
See "USERS AND PASSWORDS" in virt-builder(1) for the format of the "SELECTOR" field, and also how to set up user accounts.
"sha256" and "sha512" require glibc ≥ 2.7 (check crypt(3) inside the guest).
"md5" will work with relatively old Linux guests (eg. RHEL 3), but is not secure against modern attacks.
The default is "sha512" unless libguestfs detects an old guest that didn't have support for SHA-512, in which case it will use "md5". You can override libguestfs by specifying this option.
Note this does not change the default password encryption used by the guest when you create new user accounts inside the guest. If you want to do that, then you should use the --edit option to modify "/etc/sysconfig/authconfig" (Fedora, RHEL) or "/etc/pam.d/common-password" (Debian, Ubuntu).
See "USERS AND PASSWORDS" in virt-builder(1) for the format of the "SELECTOR" field, and also how to set up user accounts.
Note: In virt-builder, if you don't set --root-password then the guest is given a random root password.
The script is automatically chmod +x.
If libguestfs supports it then a limited network connection is available but it only allows outgoing network connections. You can also attach data disks (eg. ISO files) as another way to provide data (eg. software packages) to the script without needing a network connection (--attach). You can also upload data files (--upload).
You can have multiple --run options. They run in the same order that they appear on the command line.
See also: --firstboot, --attach, --upload.
If libguestfs supports it then a limited network connection is available but it only allows outgoing network connections. You can also attach data disks (eg. ISO files) as another way to provide data (eg. software packages) to the script without needing a network connection (--attach). You can also upload data files (--upload).
You can have multiple --run-command options. They run in the same order that they appear on the command line.
See also: --firstboot, --attach, --upload.
This will attempt to relabel files immediately, but if the operation fails this will instead touch /.autorelabel on the image to schedule a relabel operation for the next time the image boots.
You should only use this option for guests which support SELinux.
See "SUBSCRIPTION-MANAGER" in virt-builder(1) for the format of the "SELECTOR" field.
See "SUBSCRIPTION-MANAGER" in virt-builder(1) for the format of the "SELECTOR" field.
This requires credentials being set using --sm-credentials.
See "SSH KEYS" in virt-builder(1) for the format of the "SELECTOR" field.
You can have multiple --ssh-inject options, for different users and also for more keys for each user.
See also --install, --update.
See also --install, --uninstall.
"DEST" could be the final filename. This can be used to rename the file on upload.
If "DEST" is a directory name (which must already exist in the guest) then the file is uploaded into that directory, and it keeps the same name as on the local filesystem.
See also: --mkdir, --delete, --scrub.
For guests which make use of SELinux, special handling for them might be needed when using operations which create new files or alter existing ones.
For further details, see "SELINUX" in virt-builder(1).
This program returns 0 on success, or 1 if there was an error.
Normally you do not need to set this. If not set, a compiled-in default will be used (something like /usr/share/virt-tools).
This directory may contain the following files:
See also: "https://github.com/rwmjones/rhsrvany"
For other environment variables, see "ENVIRONMENT VARIABLES" in guestfs(3).
guestfs(3), guestfish(1), virt-builder(1), virt-clone(1), virt-rescue(1), virt-resize(1), virt-sparsify(1), virt-sysprep(1), virsh(1), lvcreate(8), qemu-img(1), scrub(1), http://libguestfs.org/, http://libvirt.org/.
Richard W.M. Jones http://people.redhat.com/~rjones/
Copyright (C) 2011-2019 Red Hat Inc.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
To get a list of bugs against libguestfs, use this link: https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools
To report a new bug against libguestfs, use this link: https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools
When reporting a bug, please supply:
2019-02-07 | libguestfs-1.40.2 |