vzctl(8) | Containers | vzctl(8) |
vzctl - perform various operations on an OpenVZ container
vzctl |
[flags] create CTID --parameter value [...] |
vzctl |
[flags] start CTID [--wait] [--force] [--skip-fsck] [--skip-remount] |
vzctl |
[flags] stop CTID [--fast] [--skip-umount] |
vzctl |
[flags] restart CTID [--wait] [--force] [--fast] [--skip-fsck] [--skip-remount] |
vzctl |
[flags] suspend | resume CTID [--dumpfile name] |
vzctl |
[flags] snapshot CTID [--id uuid] [--name name] [--description desc] [--skip-suspend] [--skip-config] |
vzctl |
[flags] snapshot-switch CTID [--skip-resume | --must-resume] [--skip-config] --id uuid |
vzctl |
[flags] snapshot-delete CTID --id uuid |
vzctl |
[flags] snapshot-mount CTID --id uuid --target dir |
vzctl |
[flags] snapshot-umount CTID --id uuid |
vzctl |
[flags] snapshot-list CTID [-H] [-o field[,field...] [--id uuid] |
vzctl |
[flags] set CTID --parameter value [...] [--save] [--force] [--setmode restart|ignore] |
vzctl |
[flags] set CTID --reset_ub |
vzctl |
[flags] destroy | delete | mount | umount | status | quotaon | quotaoff | quotainit CTID |
vzctl |
[flags] console CTID [ttynum] |
vzctl |
[flags] convert CTID [--layout ploop[:{expanded|plain|raw}]] |
vzctl |
[flags] compact CTID |
vzctl |
[flags] exec | exec2 CTID command [arg ...] |
vzctl |
[flags] enter CTID [--exec command [arg ...]] |
vzctl |
[flags] runscript CTID script |
vzctl |
--help | --version |
Utility vzctl runs on the host system (otherwise known as Hardware Node, or HN) and performs direct manipulations with containers (CTs).
Containers can be referred to by either numeric CTID or by name (see --name option). Note that CT ID <= 100 are reserved for OpenVZ internal purposes. A numeric ID should not be more than 2147483644.
These flags come before a command, and can be used with any command. They affect logging to console (terminal) only, and do not affect logging to a log file.
set |
CTID [--onboot yes|no] [--bootorder number] [--root path] [--private path] [--mount_opts options] [--userpasswd user:pass] [--disabled yes|no] [--name name] [--description string] [--ostemplate string] [--stop-timeout seconds] [--ipadd addr] [--ipdel addr|all] [--hostname name] [--nameserver addr] [--searchdomain name] [--netif_add dev[,params...]] [--netif_del dev|all] [--ifname dev [--mac hwaddr] [--host_ifname dev] [--host_mac hwaddr] [--bridge name] [--mac_filter on|off]] [--numproc items] [--numtcpsock items] [--numothersock items] [--vmguarpages pages] [--kmemsize bytes] [--tcpsndbuf bytes] [--tcprcvbuf bytes] [--othersockbuf bytes] [--dgramrcvbuf bytes] [--oomguarpages pages] [--lockedpages pages] [--privvmpages pages] [--shmpages pages] [--numfile items] [--numflock items] [--numpty items] [--numsiginfo items] [--dcachesize bytes] [--numiptent num] [--physpages pages] [--swappages pages] [--ram bytes] [--swap bytes] [--vm_overcommit float] [--cpuunits num] [--cpulimit num] [--cpus num] [--cpumask cpus|auto|all] [--nodemask nodes|all] [--meminfo none|mode:value] [--iptables name[,...]] [--netfilter disabled|stateless|stateful|full] [--netdev_add ifname] [--netdev_del ifname] [--diskquota yes|no] [--diskspace num] [--diskinodes num] [--quotatime seconds] [--quotaugidlimit num] [--capability capname:on|off[,...]] [--devnodes param] [--devices param] [--pci_add dev] [--pci_del dev] [--features name:on|off[,...]] [--applyconfig name] [--applyconfig_map group] [--ioprio num] [--iolimit mbps] [--iopslimit iops] [--save] [--force] [--reset_ub] [--setmode restart|ignore] |
Flags
Miscellaneous
In case container was not running, it is automatically started then all the appropriate changes are applied, then it is stopped.
Note that container should be created before using this option.
Special value of 0 means to use compiled-in default.
Networking
A special value of inherit can be used to auto-propagate nameserver value(s) from the host system's /etc/resolv.conf file.
A special value of inherit can be used to auto-propagate search domain value(s) from the host system's /etc/resolv.conf file.
veth interface configuration
The following options can be used to reconfigure the already-created virtual Ethernet interface. To select the interface to configure, use --ifname name option.
If you want an independent communication with the Container through the bridge, you should specify a multicast MAC address here (FE:FF:FF:FF:FF:FF).
By default, this functionality is enabled for all veth devices existing inside the Container.
VSwap limits
The following options sets memory and swap limits for VSwap-enabled kernels (kernel version 042stab042 or greater).
Argument is in bytes, unless otherwise specified by an optional suffix. Available suffixes are:
• T, t - terabytes;
• G, g - gigabytes;
• M, m - megabytes;
• K, k - kilobytes;
• P, p - memory pages (arch-specific, usually 4KB);
• B, b - bytes (this is the default).
vzctl checks if running kernel is VSwap capable, and refuses to use these parameters otherwise. This behavior can be overriden by using --force flag before parameters.
In VSwap mode, all beancounters other than RAM and swap become optional. Note though that if some optional beancounters are not set, they are calculated and set by vzctl implicitly, using the following formulae:
• lockedpages.barrier = oomguarpages.barrier = ram
• lockedpages.limit = oomguarpages.limit = unlimited
• vmguarpages.barrier = vmguarpages.limit = ram + swap
• privvmpages.barrier = privvmpages.limit = (ram + swap) * vm_overcommit
(if vm_overcommit is 0 or not set, privvmpages is set to "unlimited")
Here is an example of setting container 777 to have 512 megabytes of RAM and 1 gigabyte of swap:
vzctl set 777 --ram 512M --swap 1G --save
User Beancounter limits
The following options sets barrier and limit for various user beancounters.
Note that for VSwap-enabled kernels (version 042stab042 or greater) these limits are optional, you must only set --ram and --swap (see above). For older kernels, these limits are obligatory.
Each option requires one or two arguments. In case of one argument, vzctl sets barrier and limit to the same value. In case of two colon-separated arguments, the first is a barrier, and the second is a limit. Each argument is either a number, a number with a suffix, or a special value unlimited.
Arguments are in items, pages or bytes. Note that page size is architecture-specific, it is 4096 bytes on x86 and x86_64 platforms.
You can also specify different suffixes for User Beancounter parameters (except for those which names start with num). For example, vzctl set CTID --privvmpages 5M:6M should set privvmpages' barrier to 5 megabytes and its limit to 6 megabytes.
Available suffixes are:
• T, t - terabytes;
• G, g - gigabytes;
• M, m - megabytes;
• K, k - kilobytes;
• P, p - memory pages (arch-specific, usually 4KB);
• B, b - bytes.
You can also specify the literal word unlimited in place of a number. In that case the corresponding value will be set to LONG_MAX, i. e. the maximum possible value.
The barrier and the limit of this parameter control the upper boundary of the total size of allocated memory. Note that this upper boundary does not guarantee that container will be able to allocate that much memory. The primary mechanism to control memory allocation is the --vmguarpages guarantee.
For older kernels, this is an accounting-only parameter, showing the usage of RAM by this container. Barrier should be set to 0, and limit should be set to unlimited.
For older (pre-VSwap) kernels, the limit is used to show a total amount of swap space available inside the container. The barrier of this parameter is ignored. The default value is unlimited, meaning total swap will be reported as 0.
CPU fair scheduler parameters
These parameters control CPU usage by container.
You can set CPU weight for CT0 (host system itself) as well (use vzctl set 0 --cpuunits num). Usually, OpenVZ initscript (/etc/init.d/vz) takes care of setting this.
Memory output parameters
For VSwap-enabled kernels (042stab042 or greater), this parameter is ignored. For older kernels, it controls the output of /proc/meminfo inside a container.
You can use the following modes for mode:
• pages:value - sets total memory in pages;
• privvmpages:value - sets total memory as
privvmpages * value.
Default is privvmpages:1.
Netfilter (iptables) control parameters
Note that changing this parameter requires container restart, so consider using --setmode option.
The following arguments can be used:
Allow to use the functionality of name iptables module inside the container. Multiple comma-separated names can be specified.
The default list of enabled iptables modules is defined by the IPTABLES variable in vz.conf(5).
You can use the following values for name: iptable_filter, iptable_mangle, ipt_limit, ipt_multiport, ipt_tos, ipt_TOS, ipt_REJECT, ipt_TCPMSS, ipt_tcpmss, ipt_ttl, ipt_LOG, ipt_length, ip_conntrack, ip_conntrack_ftp, ip_conntrack_irc, ipt_conntrack, ipt_state, ipt_helper, iptable_nat, ip_nat_ftp, ip_nat_irc, ipt_REDIRECT, xt_mac, ipt_recent, ipt_owner.
Network devices control parameters
Disk quota parameters
Note that this parameter is ignored for ploop layout.
For ploop layout, initiates the procedure of resizing the ploop image file to the new size. Since there is no soft/hard limit concept in ploop, second num, if specified, is ignored.
By default, ploop resize is done online, i.e. on a mounted ploop. This is a preferred way of doing resize. Although, in a rare case a container was using lots of disk space and should now be resized to a much smaller size, an offline resize might be more appropriate. In this case, make sure the container is stopped and unmounted and use additional --offline-resize option
Note that ploop resize is NOT performed on container start, so for consistency --diskspace must be used together with --save flag.
Suffixes G, M, K can also be specified (see Resource limits section for more info on suffixes). If suffix is not specified, value is in kilobytes.
Note that this parameter is ignored for ploop layout.
Note that this parameter is ignored for ploop layout.
For simfs layout containers, non-zero value sets maximum number of user/group IDs for which disk quota is accounted.
For ploop layout containers, any non-zero value enables disk quota inside the container; the number of user/group IDs used by disk quota is not limited by OpenVZ.
Note that enabling or disabling in-container disk quotas requires container restart, so consider using --setmode option.
Capability option
Note that setting a capability when the container is running does not take immediate effect; restart the container in order for the changes to take effect (consider using --setmode option).
A container has the default set of capabilities, thus any operation on capabilities is "logical AND" with the default capability mask.
You can use the following values for capname: chown, dac_override, dac_read_search, fowner, fsetid, kill, setgid, setuid, setpcap, linux_immutable, net_bind_service, net_broadcast, net_admin, net_raw, ipc_lock, ipc_owner, sys_module, sys_rawio, sys_chroot, sys_ptrace, sys_pacct, sys_admin, sys_boot, sys_nice, sys_resource, sys_time, sys_tty_config, mknod, lease, setveid, ve_admin. For detailed description, see capabilities(7).
WARNING: setting some of those capabilities may have far reaching security implications, so do not do it unless you know what you are doing. Also note that setting setpcap:on for a container will most probably lead to inability to start it.
Device access management
vzctl set 777 --devnodes sdb:rwq
PCI device management
Note that vps-pci configuration script is executed by vzctl then configuring PCI devices. The script is usually located at /usr/lib/vzctl/vzctl/scripts/.
Features management
Apply config
I/O scheduling
If no suffix is provided, the limit is assumed to be in
megabytes per second. Available suffixes are:
• b, B -- bytes per second;
• k, K -- kilobytes per second;
• m, M -- megabytes per second (default);
• g, G -- gigabytes per second;
Checkpointing is a feature of OpenVZ kernel which allows to save a complete in-kernel state of a running container, and to restore it later.
Snapshotting is a feature based on checkpointing and ploop shapshots. It allows to save a complete state of container file system. Plus, if the container is running, it's in-memory state (as in checkpointing). Note that snapshot functionality is only working for containers on ploop device.
If a container is running, and --skip-suspend option is not specified, a container is checkpointed and then restored, and CT memory dump becomes the part of snapshot.
Unless --skip-config option is given, container configuration file is saved to the snapshot.
If uuid is not specified, it is auto-generated. Options --name and --description can be used to specify the snapshot name and description, respectively. Name is displayed by snapshot-list.
Note that the current state of a container (including its file system state and its configuration file) is lost!
Option --skip-resume is used to ignore a CT memory dump file in a snapshot, as a result the container will end up being in a stopped state (same as if a snapshot has been taken with --skip-suspend).
If option --must-resume is set, absense of a memory dump is treated as an error, and the inability to restore from the memory dump is treated as an error rather than warning.
Option option --skip-config is used to ignore the CT configuration file in a snapshot, i.e. the current configuration file will be left as is.
You can suppress displaying header using -H option.
You can use the -o option to display only the specified field(s). List of available fields can be obtained using -L option.
create |
CTID [--ostemplate name] [--config name] [--layout simfs|ploop[:{expanded|plain|raw}]] [--diskspace kbytes] [--diskinodes num] [--private path] [--root path] [--ipadd addr] [--hostname name] [--name name] [--local_uid uid] [--local_gid gid] |
By default, an OS template denoted by DEF_OSTEMPLATE parameter of vz.conf(5) is used to create a container. This can be overwritten by --ostemplate option.
By default, a new container configuration file is created from a sample configuration denoted by value of CONFIGFILE parameter of vz.conf(5). If the container configuration file already exists, it will not be modified.
The value of CONFIGFILE can be overwritten by using the --config name option. This option can not be used if the container configuration file already exists.
A new container can either be created using simfs filesystem or on a ploop device. The default is set by value of VE_LAYOUT parameter of vz.conf(5) and can be overwritten by --layout option. In case ploop is used, one can additionally specify ploop disk image format after a colon. Possible ploop formats are expanded, plain and raw. Default is expanded. Using value other than expanded is not recommended and is currently not supported.
You can use --diskspace and --diskinodes options to specify container file system size. Note that for ploop layout, you will not be able to change inodes value later.
If DISKSPACE is not specified either in the sample configuration file used for creation or in global configuration file vz.conf(5), --diskspace parameter is required for ploop layout.
Suffixes G, M, K can also be specified (see Resource limits section for more info on suffixes).
You can use --root path option to sets the path to the mount point for the container root directory (default is VE_ROOT specified in vz.conf(5) file). Argument can contain literal string $VEID, which will be substituted with the numeric CT ID.
You can use --private path option to set the path to directory in which all the files and directories specific to this very container are stored (default is VE_PRIVATE specified in vz.conf(5) file). Argument can contain literal string $VEID, which will be substituted with the numeric CT ID.
You can use --ipadd addr option to assign an IP address to a container. Note that this option can be used multiple times.
You can use --hostname name option to set a host name for a container.
When running with an upstream Linux Kernel that supports user namespaces (>= 3.8), the parameters --local_uid and --local_gid can be used to select which uid and gid respectively will be used as a base user in the host system. Note that user namespaces provide a 1:1 mapping between container users and host users. If these options are not specified, the values LOCAL_UID and LOCAL_GID from global configuration file vz.conf(5) are used. An explicit --local_uid value of 0 will disable user namespace support, and run the container as a privileged user. In this case, --local_gid is ignored.
Warning: use --local_uid and --local_gid with care, specially when migrating containers. In all situations, the container's files in the filesystem needs to be correctly owned by the host-side users.
Specify --force if you want to start a container which is disabled (see --disabled).
Specify --skip-fsck to skip fsck for ploop-based container filesystem (this option is used by vz initscript).
By default, if a container to be started happens to be already mounted, it is unmounted and mounted again. This behavior can be turned off by using --skip-remount flag.
Note that this command can lead to execution of premount, mount and start action scripts (see ACTION SCRIPTS below).
Note that vzctl stop is not asyncronous, in other words vzctl waits for container's init to exit (unless --fast is given), which can take up to a few minutes. Default wait timeout is 120 seconds; it can be changed globally, by setting STOP_TIMEOUT in vz.conf(5), or per container (STOP_TIMEOUT in ctid.conf(5), see --stop-timeout).
Note that this command can lead to execution of stop, umount and postumount action scripts (see ACTION SCRIPTS below).
Note that this command can lead to execution of some action scripts (see ACTION SCRIPTS below).
First word is literally CTID.
Second word is the numeric CT ID.
Third word is showing whether this container exists or not, it can be either exist or deleted.
Fourth word is showing the status of the container filesystem, it can be either mounted or unmounted.
Fifth word shows if the container is running, it can be either running or down.
Sixth word, if exists, is suspended. It appears if a dump file exists for a stopped container (see suspend).
This command can also be usable from scripts.
Note that stop does umount automatically.
Option --exec is used to run command with arguments after entering into container. This is useful if command to be run requires a terminal (so vzctl exec can not be used) and for some reason you can not use ssh(1).
You need to log out manually from the shell to finish session (even if you specified --exec).
Note the consoles are persistent, meaning that:
• it can be attached to even if the container is not running;
• there is no automatic detachment upon the container stop;
• detaching from the console leaves anything running in this
console as is.
The following escape sequences are recognized by vzctl console. Note that these sequences are only recognized at the beginning of a line.
• Esc then . to detach from the console.
• Esc then ! to kill anything running on the console (SAK). This is helpful when one expects a login prompt but there isn't one.
vzctl has an ability to execute user-defined scripts when a specific vzctl command is run for a container. The following vzctl commands can trigger execution of action scripts: start, stop, restart, mount and umount.
Action scripts are located in the /etc/vz/conf/ directory. There are global and per-CT scripts. Global scripts have a literal prefix of vps. and are executed for all containers. Per-CT scripts have a CTID. numeric prefix and are executed for the given container only.
Please note scripts are executed in a host system (CT0) context, with the exception of .start and .stop scripts, which are executed in a container context.
The following action scripts are currently defined:
The environment passed to all the *mount scripts is the standard environment of the parent (i.e. vzctl) with two additional variables: $VEID and $VE_CONFFILE. The first one holds the ID of the container, and the second one holds the full path to the container configuration file. If the script needs to get other CT configuration parameters, such as $VE_ROOT, it needs to get those from global and per-CT configuration files.
Here is an example of a mount script, which makes host system's /mnt/disk available to container(s). Script name can either be /etc/vz/conf/vps.mount or /etc/vz/conf/CTID.mount.
# If one of these files does not exist then something
# is really broken
[ -f /etc/vz/vz.conf ] || exit 1
[ -f $VE_CONFFILE ] || exit 1
# Source both files. Note the order is important.
. /etc/vz/vz.conf
. $VE_CONFFILE
SRC=/mnt/disk
DST=/mnt/disk
mount -n -t simfs $SRC ${VE_ROOT}${DST} -o $SRC
Returns 0 upon success, or an appropriate error code in case of an error:
To create and start "basic" container with ID of 1000 using centos-5 OS template and IP address of 192.168.10.200:
vzctl create 1000 --ostemplate centos-5 --config basic
vzctl set 1000 --ipadd 192.168.10.200 --save
vzctl start 1000
To set number of processes barrier/limit to 80/100, and PTY barrier/limit to 16/20 PTYs:
vzctl set 1000 --numproc 80:100 -t 16:20 --save
To execute command ls -la in this container:
vzctl exec 1000 /bin/ls -la
To execute command pipe ls -l / | sort in this container:
vzctl exec 1000 'ls -l / | sort'
To enter this container and execute command apt-get install vim:
vzctl enter 1000 --exec apt-get install vim
Note that in the above example you will need to log out from the container's shell after apt-get finishes.
To enter this container, execute command apt-get install vim and logout after successful installation (or stay inside the container if installation process failed) use &&:
vzctl enter 1000 --exec "apt-get install vim && logout"
To enter this container, execute command apt-get install vim and logout independently of exit code of installation process use ;:
vzctl enter 1000 --exec "apt-get install vim ; logout"
Note that you need to quote the command if you use && or ;.
To stop this container:
vzctl stop 1000
To permanently remove this container:
vzctl destroy 1000
/etc/vz/vz.conf /etc/vz/conf/CTID.conf /etc/vz/conf/vps.{premount,mount,umount,postumount} /etc/vz/conf/CTID.{premount,mount,start,stop,umount,postumount} /proc/vz/veinfo /proc/vz/vzquota /proc/user_beancounters /proc/bc/* /proc/fairsched
vz.conf(5), ctid.conf(5), arpsend(8), vzcalc(8), vzcfgvalidate(8), vzcpucheck(8), vzifup-post(8), vzlist(8), vzmemcheck(8), vzmigrate(8), vzpid(8), vzquota(8), vzsplit(8), vzubc(8), http://wiki.openvz.org/UBC.
Copyright (C) 2000-2013, Parallels, Inc. Licensed under GNU GPL.
3 Jul 2014 | OpenVZ |