vzctl(8) | Containers | vzctl(8) |
vzctl [flags] set CTID parameters [--save]
vzctl [flags] destroy | mount | umount | start | stop | restart | status | quotaon | quotaoff | quotainit CTID
vzctl [flags] exec | exec2 CTID command [arg ...]
vzctl [flags] enter CTID [--exec command [arg ...]]
vzctl runscript CTID script
vzctl --help | --version
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.
The following parameters can be used with set command.
In case container root filesystem is not mounted, it is automatically mounted, then all the appropriate file changes are applied, then it is unmounted.
Note that container should be created before using this option.
The following options can be used to reconfigure the already-created virtual Ethernet interface. To select the interface to configure, use --ifname name option.
By default, this functionality is enabled for all veth devices existing inside the Container.
The following options sets barrier and limit for various user beancounters. 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 IA32 platform.
You can also specify different suffixes for set parameters (except for the parameters 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:
g, G -- gigabytes.
m, M -- megabytes.
k, K -- kilobytes.
p, P -- pages (page is 4096 bytes on x86 architecture, other
architectures may differ).
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.
Note that in order for the value to be shown as total swap space, --meminfo parameter should be set to value other than none.
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.
This parameter control 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.
The default list of enabled iptables modules is specified 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.
Note that if you have previously set value of this parameter to 0, changing it while the container is running will not take effect.
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.
Note that vps-pci configuration script is executed by vzctl then configuring PCI devices. The script is usually located at /usr/lib[64]/vzctl/scripts/.
If the --config option is specified, values from example configuration file /etc/vz/conf/ve- name.conf-sample are put into the container configuration file. If this container configuration file already exists, it will be removed.
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.
Specify --force if you want to start a container which is disabled (see --disabled).
Note that this command can lead to execution of premount, mount and start action scripts (see ACTION SCRIPTS below).
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 both a container and its dump file exist (see chkpnt).
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).
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.
There are 8 action scripts 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/sysconfig/vz ] || exit 1 [ -f $VE_CONFFILE ] || exit 1 # Source both files. Note the order is important. . /etc/vz/vz.conf . $VE_CONFFILE mount -n --bind /mnt/disk $VE_ROOT/mnt/disk
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
16 Nov 2010 | OpenVZ |