vzctl(8)
π¦ vzctl(8) β Containers π¦
okay bestie, sit down, hydrate, because this is the vzctl(8) manual page from the Containers section and it is long. But it's also iconic, and by the end of it you're gonna be running OpenVZ containers like it's nothing. no cap. π
β¨ NAME β¨
vzctl β perform various operations on an OpenVZ container π«Ά
π SYNOPSIS π
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
π DESCRIPTION π
vzctl is a utility that lives on the host system (which the cool kids also call the Hardware Node, or HN), and it does direct manipulations with containers (CTs). like, it's the one holding the reins. πβ¨
Containers can be referred to by either their numeric CTID or by name (peep the --name option for that one). π
heads up bestie: CT ID<= 100are reserved for OpenVZ internal purposes. don't touch. and a numeric ID should not be more than2147483644. that's the ceiling, fr fr. π₯
π OPTIONS π
π© Flags
These flags come before a command, and you can use them with any command. They affect logging to console (terminal) only, and they do not affect logging to a log file. so the log file stays unbothered, periodt. π
--quietβ Disables output. But ngl, scripts run byvzctlare still able to produce some output. so "quiet" is doing a little bit of a vibe, not a full silence. π--verboseβ Increments the logging level up from the default. You can use it multiple times (stack it like it's limited edition π ). The default value is set to the value of theVERBOSEparameter in the global configuration filevz.conf(5), or to0if it's not set by theVERBOSEparameter.
π οΈ Setting container parameters
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]
This command sets various container parameters. If the container is currently running, vzctl applies these parameters to the container. The following options can be used with the set command. π«Ά
π© Flags
--saveβ If this flag is given, parameters are saved in the container configuration filectid.conf(5). πΎ--forceβ If this flag is given together with--save, parameters are saved even if the current kernel doesn't support OpenVZ. β οΈ Note this flag does not make sense without--save, so--saveis required. like, it needs its buddy.--reset_ubβ If this flag is given,vzctlapplies all User Beancounter parameters from the configuration file to a running container. Super helpful in case the configuration file was modified manually. Please note this flag is exclusive, i.e. it can not be combined with any other options or flags. it's a solo act, main character energy only. π--setmode restart | ignoreβ A few parameters can only be applied by restarting the container. By default,vzctlprints a warning if such parameters are supplied and a container is running. Use--setmode restarttogether with the--saveflag to restart a container in such a case, or--setmode ignoreto suppress the warning. π
πΈ Miscellaneous
--onboot yes | noβ Sets whether the container will be started during system boot. The container will be started on boot by thevzinitscript if either this parameter is set toyes, or the container was running just before the last reboot, and this parameter is not set tono. Default value is unset, meaning the container will be started if it was running before the last reboot. β--bootorder numberβ Sets the boot order priority for this CT. The higher the number is, the earlier in the boot process this container starts. By default this parameter is unset, which is considered to be the lowest priority, so containers with unsetbootorderwill start last. π’--root pathβ Sets the path to the root directory (VE_ROOT) for this container. This is essentially a mount point for the container's root directory. The argument can contain the literal string$VEID, which will be substituted with the numeric CT ID. β¨--private pathβ Sets the path to the private directory (VE_PRIVATE) for this container. This is a directory in which all the container's files are stored. The argument can contain the literal string$VEID, which will be substituted with the numeric CT ID. π--mount_opts option[,option...]β Sets additional mount options for the container file system. Only applicable forplooplayout, ignored otherwise. π--userpasswd user:passwordβ Sets the password for the given user in a container, creating the user if it does not exist. Note that this option is not saved in the configuration file at all (so the--saveflag is useless here), it is applied directly to the container, by running distribution-specific programs inside the container. It is not recommended to combine this option with any other options. π
In case the container was not running, it is automatically started, then all the appropriate changes are applied, then it is stopped. so it does a little pop-in, does its thing, and dips. π
Note that the container should be created before using this option.
--disabled yes | noβ Disable container start. To force the start of a disabled container, usevzctl start --force. π₯--name nameβ Add a name for a container. The name can later be used in subsequent calls tovzctlin place ofCTID. Note this option can not be used without--save.--description stringβ Add a textual description for a container. cute little label for your baby. π--ostemplate stringβ Sets a new value of theOSTEMPLATEparameter in the container configuration filectid.conf(5). Requires the--saveflag. Useful after a change/upgrade of a distribution running inside the container, asvzctluses the value ofOSTEMPLATEto run distribution-specific scripts. π¦--stop-timeout secondsβ Sets a time to wait for the container to stop onvzctl stopbefore forcibly killing it, in seconds. Note this option can not be used without the--saveflag. β³
A special value of 0 means to use the compiled-in default.
π Networking
--ipadd addrβ Adds an IP addressaddrto a given container. The address can optionally have a netmask specified in the CIDR notation (e.g.10.1.2.3/25). Note that this option is incremental, soaddrare added to the already existing ones. β--ipdel addr | allβ Removes IP addressaddrfrom a container. If you want to remove all the addresses, use--ipdel all. ποΈ--hostname nameβ Sets the container hostname.vzctlwrites it to the appropriate file inside the container (distribution-dependent). π--nameserver addrβ Sets the DNS server IP address for a container. If you want to set several nameservers, you should do it at once, so use the--nameserveroption multiple times in one call tovzctl, because all the name server values set in previous calls tovzctlare overwritten. π€
A special value of inherit can be used to auto-propagate nameserver value(s) from the host system's /etc/resolv.conf file. π§
--searchdomain nameβ Sets DNS search domains for a container. If you want to set several search domains, you should do it at once, so use the--searchdomainoption multiple times in one call tovzctl, because all the search domain values set in previous calls tovzctlare overwritten. π€
A special value of inherit can be used to auto-propagate search domain value(s) from the host system's /etc/resolv.conf file. π§
--netif_add ifname[,mac,host_ifname,host_mac,bridge]β Adds a virtual Ethernet device (veth) to a given container. Hereifnameis the Ethernet device name in the container,macis its MAC address,host_ifnameis the Ethernet device name on the host, andhost_macis its MAC address. MAC addresses should be in the format likeXX:XX:XX:XX:XX:XX.bridgeis an optional parameter which can be used in custom network start scripts to automatically add the interface to a bridge. All parameters exceptifnameare optional and are automatically generated if not specified. π--netif_del dev_name | allβ Removes a virtual Ethernet device from a container. If you want to remove all devices, useall. π
π¦ veth interface configuration
The following options can be used to reconfigure the already-created virtual Ethernet interface. To select the interface to configure, use the --ifname name option. π―
--mac XX:XX:XX:XX:XX:XXβ MAC address of the interface inside a container.--host_ifname nameβ interface name for the virtual interface in the host system.--host_macXX:XX:XX:XX:XX:XX β the MAC address of the interface in the host system, bestie. π
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). β¨
--bridgename β bridge name. Custom network start scripts can use this value to automatically add the interface to a bridge. π--mac_filteron | off β enables/disables MAC address filtering for the Container veth device and the possibility of configuring the MAC address of this device from inside the Container. If the filtering is turned on:- the veth device accepts only those packets that have a MAC address in their headers corresponding to that of this device (excluding all broadcast and multicast packets);
- it is impossible to modify the veth MAC address from inside the Container.
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). No cap. π§
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).--rambytes β sets physical memory (RAM) available to a container. Actually, the option is a shortcut for setting--physpageslimit (the barrier is set to 0). π§--swapbytes β set swap space available to a container. Actually, the option is a shortcut for setting--swappageslimit (the barrier is set to 0). πΎ--vm_overcommitfloat β set VM overcommitment value to float. If set, it is used to calculateprivmmpagesparameter in case it is not set explicitly (see below). Default value is0, meaning unlimitedprivvmpages. π
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. π
Bestie, if your kernel isn't VSwap capable, vzctl will straight up refuse. Use --force if you know what you're doing. π
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=ramlockedpages.limit=oomguarpages.limit=unlimitedvmguarpages.barrier=vmguarpages.limit=ram + swapprivvmpages.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. π
--numprocitems[:items] β maximum number of processes and kernel-level threads. Setting the barrier and the limit to different values does not make practical sense. π§΅--numtcpsockitems[:items] β maximum number of TCP sockets. This parameter limits the number of TCP connections and, thus, the number of clients the server application can handle in parallel. Setting the barrier and the limit to different values does not make practical sense. π--numothersockitems[:items] β maximum number of non-TCP sockets (local sockets, UDP and other types of sockets). Setting the barrier and the limit to different values does not make practical sense. π‘--vmguarpagespages[:pages] β memory allocation guarantee. This parameter controls how much memory is available to a container. The barrier is the amount of memory that container's applications are guaranteed to be able to allocate. The meaning of the limit is currently unspecified; it should be set tounlimited. π‘οΈ--kmemsizebytes[:bytes] β maximum amount of kernel memory used. This parameter is related to--numproc. Each process consumes certain amount of kernel memory -16 KBat least,30-50 KBtypically. Very large processes may consume a bit more. It is important to have a certain safety gap between the barrier and the limit of this parameter: equal barrier and limit may lead to the situation where the kernel will need to kill container's applications to keep thekmemsizeusage under the limit. π
Safety gap, bestie! Don't skip it. β
--tcpsndbufbytes[:bytes] β maximum size of TCP send buffers. Barrier should be not less than64 KB, and difference between barrier and limit should be equal to or more than value ofnumtcpsockmultiplied by2.5 KB. π€--tcprcvbufbytes[:bytes] β maximum size of TCP receive buffers. Barrier should be not less than64 KB, and difference between barrier and limit should be equal to or more than value ofnumtcpsockmultiplied by2.5 KB. π₯--othersockbufbytes[:bytes] β maximum size of other (non-TCP) socket send buffers. If container's processes needs to send very large datagrams, the barrier should be set accordingly. Increased limit is necessary for high performance of communications through local (UNIX-domain) sockets. π¨--dgramrcvbufbytes[:bytes] β maximum size of other (non-TCP) socket receive buffers. If container's processes needs to receive very large datagrams, the barrier should be set accordingly. The difference between the barrier and the limit is not needed. π©--oomguarpagespages[:pages] β guarantees against OOM kill. Under this beancounter the kernel accounts the total amount of memory and swap space used by the container's processes. The barrier of this parameter is the out-of-memory guarantee. If theoomguarpagesusage is below the barrier, processes of this container are guaranteed not to be killed in out-of-memory situations. The meaning of limit is currently unspecified; it should be set tounlimited. π«--lockedpagespages[:pages] β maximum number of pages acquired bymlock(2). π--privvmpagespages[:pages] β allows controlling the amount of memory allocated by the applications. For shared (mapped asMAP_SHARED) pages, each container really using a memory page is charged for the fraction of the page (depending on the number of others using it). For "potentially private" pages (mapped asMAP_PRIVATE), container is charged either for a fraction of the size or for the full size if the allocated address space. In the latter case, the physical pages associated with the allocated address space may be in memory, in swap or not physically allocated yet. π§
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. π‘
--shmpagespages[:pages] β maximum IPC SHM segment size. Setting the barrier and the limit to different values does not make practical sense. π§©--numfileitems[:items] β maximum number of open files. In most cases the barrier and the limit should be set to the same value. Setting the barrier to0effectively disables pre-charging optimization for this beancounter in the kernel, which leads to the held value being precise but could slightly degrade file open performance. π--numflockitems[:items] β maximum number of file locks. Safety gap should be between barrier and limit. π--numptyitems[:items] β number of pseudo-terminals (PTY). Note that in OpenVZ each container can have not more than255PTYs. Setting the barrier and the limit to different values does not make practical sense. π₯οΈ--numsiginfoitems[:items] β number of siginfo structures. Setting the barrier and the limit to different values does not make practical sense. πΆ--dcachesizebytes[:bytes] β maximum size of filesystem-related caches, such as directory entry and inode caches. Exists as a separate parameter to impose a limit causing file operations to sense memory shortage and return anerrnoto applications, protecting from memory shortages during critical operations that should not fail. Safety gap should be between barrier and limit. ποΈ--numiptentnum[:num] β number of iptables (netfilter) entries. Setting the barrier and the limit to different values does not make practical sense. π₯--physpagespages[:pages] β on VSwap-enabled kernels, this limits the amount of physical memory (RAM) available to a container. The barrier should be set to0, and the limit to a total size of RAM that can be used used by a container. π§
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. π
--swappages pages[:pages]β okay so swap, bestie. On VSwap-enabled kernels (042stab042 or greater), this caps how much swap space a container can actually touch. You set the barrier to 0, and the limit to the total swap a container is allowed to use. π«§
On the old-school pre-VSwap kernels it's a whole different story: the limit is just used to report a total amount of swap space available inside the container, and the barrier gets completely ignored. Default is unlimited, which means total swap gets reported as 0. π
π CPU fair scheduler parameters π
These ones run the CPU usage of a container, no cap.
--cpuunits numβ the CPU weight for a container. Argument is a positive non-zero number, passed to and used in the kernel fair scheduler. Bigger number = more CPU time this container gets. Maximum is 500000, minimum is 8. The number is relative to the weights of all the other running containers, so it's giving "everybody's fighting for the same slice" energy. If you don't specify cpuunits, the default 1000 is used. β¨
You can also set CPU weight for CT0 (the host system itself, yes really) with vzctl set 0 --cpuunits num. Usually the OpenVZ initscript (/etc/init.d/vz) handles this for you, so don't stress.
--cpulimit num[%]β the limit of CPU usage for the container, in per cent. Heads up: if the computer has 2 CPUs, it has a total of 200% CPU time, so the percentages stack up. Default CPU limit is 0 (no CPU limit at all, free rein π ).--cpus numβ sets the number of CPUs available in the container.--cpumask cpus | auto | allβ sets the list of allowed CPUs for the container. Input format is a comma-separated list of decimal numbers and/or ranges. Consecutively set bits show up as two hyphen-separated decimal numbers: the smallest and largest bit numbers set in the range. For example, if you want the container to execute on CPUs 0, 1, 2, 7, you pass0-2,7. Default value is all (container can execute on any CPU, main character energy). If you use it with the--nodemaskoption, the value auto assigns all CPUs from the specified NUMA node to a container. π§--nodemask nodes | allβ sets the list of allowed NUMA nodes for the container. Input format is the same as for--cpumask. Note that--nodemaskmust be used together with the--cpumaskoption, they're a package deal. π«Ά
πΈ Memory output parameters πΈ
For VSwap-enabled kernels (042stab042 or greater), this parameter is ignored, periodt. For older kernels, it controls the output of /proc/meminfo inside a container.
--meminfo noneβ no/proc/meminfovirtualization (the same as on the host system).--meminfo mode:valueβ configure the total memory output in a container. The reported free memory gets evaluated according to the mode you set. The reported swap gets evaluated according to the settings of the--swappagesparameter. π
You can use these 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 π
--netfilter disabled|stateless|stateful|fullβ restricts access to the netfilter/iptables modules for a container. This option replaces the obsoleted--iptables.
Heads up bestie: changing this parameter requires a container restart, so consider using the --setmode option. π₯
The following arguments can be used:
disabledβ no modules are allowedstatelessβ all modules except NAT and conntracks are allowed (i.e. filter and mangle); this is the defaultstatefulβ all modules except NAT are allowedfullβ all modules are allowed
--iptables name[,...]β ngl, this option is obsoleted,--netfiltershould be used instead.
Allows you to use the functionality of the 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 π¦
--netdev_add nameβ move network device from the host system to a specified container.--netdev_del nameβ delete network device from a specified container.
π Disk quota parameters π
--diskquota yes | noβ lets you enable or disable disk quota for a container. By default, a global value (DISK_QUOTA) fromvz.conf(5)is used.
Note that this parameter is ignored for ploop layout.
--diskspace num[:num]β for simfs layout, sets soft and hard disk quota limits. First parameter is the soft limit, second is the hard limit.
For ploop layout, this initiates the procedure of resizing the ploop image file to the new size. Since there's no soft/hard limit concept in ploop, the second num, if specified, is ignored. π
By default, ploop resize is done online, i.e. on a mounted ploop. This is the preferred way of doing resize. Although β rare case incoming β if 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 that case, make sure the container is stopped and unmounted and use the additional --offline-resize option.
Note that ploop resize is NOT performed on container start, so for consistency--diskspacemust be used together with the--saveflag. Don't forget it, fr fr. π
Suffixes G, M, K can also be specified (see the Resource limits section for more info on suffixes). If no suffix is specified, the value is in kilobytes.
--diskinodes num[:num]β sets soft and hard disk quota limits, in i-nodes. First parameter is the soft limit, second is the hard limit.
Note that this parameter is ignored for ploop layout.
--quotatime secondsβ sets the quota grace period. The container is permitted to exceed its soft limits for the grace period, but once it has expired, the soft limit is enforced as a hard limit. So it's giving "you have a little wiggle room and then we get strict". β¨
Note that this parameter is ignored for ploop layout.
--quotaugidlimit numβ enables or disables in-container per-user and per-group disk quotas. If the value is set to0or not set, disk quotas inside the container are disabled and not accounted.
For simfs layout containers, a non-zero value sets the 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 a container restart, so consider using the --setmode option.
π Capability option π
--capability capname:on|off[,...]β sets a capability for a container. Multiple comma-separated capabilities can be specified.
Note that setting a capability while the container is running does not take immediate effect; restart the container in order for the changes to take effect (consider using the --setmode option).
A container has the default set of capabilities, so any operation on capabilities is a "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 a 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. π Please be careful, bestie.
π Device access management π
--devnodes device:[r][w][q]|noneβ give the container access (rβ read,wβ write,qβ disk quota management,noneβ no access) to a device designated by the special file/dev/device. The device file is created in a container byvzctl. Example:
vzctl set 777 --devnodes sdb:rwq
--devices b|c:major:minor|all:[r][w][q]|noneβ give the container access to a block or character device designated by its major and minor numbers. The device file has to be created manually.
π PCI device management π
--pci_add [domain:]bus:slot.funcβ give the container access to a specified PCI device. All numbers are hexadecimal (as printed bylspci(8)in the first column). π--pci_del [domain:]bus:slot.funcβ delete a PCI device from the container.
Note that the vps-pci configuration script is executed by vzctl when configuring PCI devices. The script is usually located at /usr/lib/vzctl/vzctl/scripts/.
πΈ Features management πΈ
--features name:on|off[,...]β enable or disable a specific container feature. Known features are:sysfs,nfs,sit,ipip,ppp,ipgre,bridge,nfsd. A few features can be specified at once, comma-separated. π§
β Apply config β
--applyconfig nameβ read container parameters from the container sample configuration file/etc/vz/conf/ve-name.conf-sample, and apply them; if the--saveoption is specified, save to the container config file. The following parameters are not changed:HOSTNAME,IP_ADDRESS,OSTEMPLATE,VE_ROOT, andVE_PRIVATE.--applyconfig_map groupβ apply container config parameters selected by group. Right now the only possible value for group isname: to restore the container name based on theNAMEvariable in the container configuration file.
π I/O scheduling π
--ioprio priorityβ assigns disk I/O priority to a container. Priority range is0-7. The greater the priority is, the more time for I/O activity the container has. By default each container has a priority of4. π--iolimit limit[B|K|M|G]β bestie, this is your disk I/O bandwidth cap for the container. The value is either a number with an optional suffix, or the literal stringunlimited. A value of0means "unlimited" too. Out of the box a container has no I/O limit at all. The max you're allowed is 2 gigabytes per second β anything over that gets truncated. π
If you don't give a suffix, it's assumed to be megabytes per second. The suffixes you can use are:
b,Bβ bytes per secondk,Kβ kilobytes per secondm,Mβ megabytes per second (this is the default)g,Gβ gigabytes per second
--iopslimit iopsβ this one caps the IOPS, aka input/output operations per second, for a container. Value is a number or the literal stringunlimited.0means "unlimited". By default a container has no IOPS limit. β¨
Suspending and resuming
Checkpointing is a feature of the OpenVZ kernel that lets you save a complete in-kernel state of a running container, and restore it later. It's giving "save point in a video game" honestly. π
suspend|chkpnt CTID [--dumpfile name]
Suspends a container to a dump file. If you don't set the --dumpfile option, the default dump file name /var/lib/vz/dump/Dump.CTID is used.
resume|restore CTID [--dumpfile name]
Restores a container from the dump file that the suspend command created. π¦
Snapshotting
Snapshotting is a feature built on checkpointing and ploop snapshots. It lets you save a complete state of the container file system. Plus, if the container is running, it grabs its in-memory state too (just like checkpointing). Heads up though: the snapshot functionality only works for containers on a ploop device. π
snapshot CTID [--id uuid] [--name name] [--description desc] [--skip-suspend] [--skip-config]
Creates a container snapshot, i.e. saves the current container state β including its file system state, running processes state, and configuration file. It's the whole vibe, preserved. πΈ
If the container is running, and --skip-suspend is not specified, the container gets checkpointed and then restored, and the CT memory dump becomes part of the snapshot.
Unless --skip-config is given, the container configuration file is saved to the snapshot too.
If uuid isn't specified, it's auto-generated. --name and --description let you set the snapshot name and description, respectively. The name is what snapshot-list displays.
snapshot-switch CTID [--skip-resume | --must-resume] [--skip-config] --id uuid
Switches the container to a snapshot identified by uuid, restoring its file system state, configuration (if available) and its running state (if available).
β οΈ Note that the current state of the container β including its file system state and its configuration file β is lost! No undo, bestie, this is not a drafts folder. π
Option --skip-resume is used to ignore a CT memory dump file in a snapshot; as a result the container will end up in a stopped state (same as if the snapshot was taken with --skip-suspend).
If --must-resume is set, the absence 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 a warning.
The --skip-config option is used to ignore the CT configuration file in a snapshot, i.e. the current configuration file will be left as is.
snapshot-delete CTID --id uuid
Removes a specified snapshot. bye bye π«Ά
snapshot-mount CTID --id uuid --target directory
Mounts a snapshot specified by uuid to a directory. Note this mount is read-only.
snapshot-umount CTID --id uuid
Unmounts a specified snapshot.
snapshot-list CTID [-H] [-o field[,field...] [--id uuid]
Lists the container's snapshots.
You can suppress the header using the -H option.
You can use the -o option to display only the specified field(s). The list of available fields can be obtained using the -L option.
Performing container actions
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]
Creates a new container area. This is a once-and-done operation β you do it before the first start of the container. β¨
By default, an OS template denoted by the DEF_OSTEMPLATE parameter of vz.conf(5) is used to create a container. You can overwrite that with the --ostemplate option.
By default, a new container configuration file is created from a sample configuration denoted by the value of the 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 the simfs filesystem or on a ploop device. The default is set by the value of the VE_LAYOUT parameter of vz.conf(5) and can be overwritten by the --layout option. If ploop is used, you can additionally specify the ploop disk image format after a colon. The possible ploop formats are expanded, plain and raw. Default is expanded. Using a value other than expanded is not recommended and is currently not supported. π
You can use the --diskspace and --diskinodes options to specify the container file system size. Note that for ploop layout, you will not be able to change the inodes value later.
If DISKSPACE is not specified either in the sample configuration file used for creation or in the global configuration file vz.conf(5), the --diskspace parameter is required for ploop layout.
Suffixes G, M, K can also be specified (see the Resource limits section for more info on suffixes).
You can use the --root path option to set the path to the mount point for the container root directory (default is VE_ROOT specified in the vz.conf(5) file). The argument can contain the literal string $VEID, which will be substituted with the numeric CT ID.
You can use the --private path option to set the path to the directory in which all the files and directories specific to this very container are stored (default is VE_PRIVATE specified in the vz.conf(5) file). The argument can contain the literal string $VEID, which will be substituted with the numeric CT ID.
You can use the --ipadd addr option to assign an IP address to a container. Note that this option can be used multiple times. π
You can use the --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 aren't specified, the values LOCAL_UID and LOCAL_GID from the 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 that case, --local_gid is ignored.
β οΈ Warning: use--local_uidand--local_gidwith care, especially when migrating containers. In all situations, the container's files in the filesystem need to be correctly owned by the host-side users. No cap, be careful. π
destroy | delete CTID
Removes a container private area by deleting all files, directories and the configuration file of this container. poof, gone π¦
start CTID [--wait] [--force] [--skip-fsck] [--skip-remount]
Mounts (if necessary) and starts a container. Unless the --wait option is specified, vzctl will return immediately; otherwise an attempt to wait till the default runlevel is reached will be made by vzctl.
Specify --force if you want to start a container which is disabled (see --disabled).
Specify --skip-fsck to skip fsck for a ploop-based container filesystem (this option is used by the 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 the --skip-remount flag.
Note that this command can lead to execution of premount, mount and start action scripts (see ACTION SCRIPTS below).
stop CTID [--fast] [--skip-umount]
Stops a container and unmounts it (unless --skip-umount is given). Normally, halt(8) is executed inside a container; the --fast option makes vzctl use the reboot(2) syscall instead, which is faster but can lead to an unclean container shutdown. π
Note that vzctl stop is not asynchronous β in other words, vzctl waits for the container's init to exit (unless --fast is given), which can take up to a few minutes. The 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).
restart CTID [--wait] [--force] [--fast] [--skip-fsck]
Restarts a container, i.e. stops it if it's running, and starts it again. Accepts all the start and stop options.
Note that this command can lead to execution of some action scripts (see ACTION SCRIPTS below).
status CTID
Shows a container status. This is a line with five or six words, separated by spaces. She's giving telegram, honestly. π
- First word is literally
CTID. - Second word is the numeric CT ID.
- Third word shows whether this container exists or not; it can be either
existordeleted. - Fourth word shows the status of the container filesystem; it can be either
mountedorunmounted. - Fifth word shows if the container is running; it can be either
runningordown. - Sixth word, if it exists, is
suspended. It appears if a dump file exists for a stopped container (seesuspend).
This command can also be usable from scripts. π₯
mount CTID
Mounts the container private area. Note that this command can lead to execution of premount and mount action scripts (see ACTION SCRIPTS below).
umount CTID
Unmounts the container private area. Note that this command can lead to execution of umount and postumount action scripts (see ACTION SCRIPTS below).
Note that stop does umount automatically. π
convert CTID [--layout ploop[:{expanded|plain|raw}]]β Convert the CT private area so it lives on aploopdevice (available in kernel version042stab052.8and greater). Do this while the container is stopped, and also set the disk space quota, bestie. β¨compact CTIDβ Compact the container image. This only makes sense forplooplayout. π§Όquotaon CTIDβ Turn disk quota on. Note thatmountandstartdo that automatically anyway. πquotaoff CTIDβ Turn disk quota off. Note thatumountandstopdo that automatically anyway. π€quotainit CTIDβ Initialize disk quota (i.e. runvzquota init) with the parameters taken from the CT configuration filectid.conf(5). π οΈexec CTID commandβ Executescommandin a container. Environment variables are not set inside the container. Signal handlers may differ from default settings. Ifcommandis-, commands are read fromstdin. π₯exec2 CTID commandβ Same asexec, but the return code is that ofcommand. π―runscript CTID scriptβ Run the specified shell script in the container. The argumentscriptis a file on the host system; its contents are read byvzctland executed in the context of the container. For a running container, the command jumps into the container and executes the script. For a stopped container, it enters the container, mounts the container's root filesystem, executes the script, and unmounts CT root. In that latter case, the container is not really started, no file systems other than root (such as/proc) are mounted, no startup scripts are executed, etc. So the environment in which the script runs is far from normal and only usable for very basic operations. β οΈenter CTID [--exec command [arg ...]]β Enters into a container (giving you a container's root shell). This option is a back-door for host root only. The proper way to get a CT root shell is to usessh(1). πͺ
Option --exec is used to run command with arguments after entering the container. This is useful if the 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 the session (even if you specified --exec). π
console CTID [ttynum]β Attach to a container console. The optionalttynumargument is the tty number (such as4fortty4); the default is1, which is used for the container's/dev/console. π€
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. β¨οΈ
Escthen.to detach from the console. πͺEscthen!to kill anything running on the console (SAK). This is helpful when one expects a login prompt but there isn't one. π
β¨ Other options β¨
--helpβ Prints a help message with a brief list of possible options. π--versionβ Printsvzctlversion. π¦
π¬ ACTION SCRIPTS π¬
vzctl has the 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 live 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.startand.stopscripts, which are executed in a container context. π§
The following action scripts are currently defined:
vps.premount,CTID.premountβ Global and per-CT mount scripts which are executed for a container before it is mounted. Scripts are executed in the host system context, while a CT is not yet mounted or running. The global script, if it exists, is executed first. ποΈvps.mount,CTID.mountβ Global and per-CT mount scripts which are executed for a container right after it is mounted. Otherwise they are the same as.premountscripts. πͺCTID.startβ Right aftervzctlhas started a container, it executes this script in a container context. πCTID.stopβ Right beforevzctlhas stopped a container, it executes this script in a container context. πvps.umount,CTID.umountβ Global and per-CT umount scripts which are executed for a container before it is unmounted. Scripts are executed in the host system context, while a CT is mounted. The global script, if it exists, is executed first. π§Ήvps.postumount,CTID.postumountβ Global and per-CT umount scripts which are executed for a container right after it is unmounted. Otherwise they are the same as.umountscripts. β¨
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 the 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
π¦ EXIT STATUS π¦
Returns 0 upon success, or an appropriate error code in case of an error:
1β Failed to set a UBC parameter2β Failed to set a fair scheduler parameter3β Generic system error5β The running kernel is not an OpenVZ kernel (or some OpenVZ modules are not loaded)6β Not enough system resources7βENV_CREATEioctl failed8β Command executed byvzctl execreturned non-zero exit code9β Container is locked by anothervzctlinvocation10β Global OpenVZ configuration filevz.conf(5)not found11β Avzctlhelper script file not found12β Permission denied13β Capability setting failed14β Container configuration filectid.conf(5)not found15β Timeout onvzctl exec16β Error duringvzctl suspend17β Error duringvzctl resume18β Error fromsetluid()syscall20β Invalid command line parameter21β Invalid value for command line parameter22β Container root directory (VE_ROOT) not set23β Container private directory (VE_PRIVATE) not set24β Container template directory (TEMPLATE) not set28β Not all required UBC parameters are set, unable to start container29β OS template is not specified, unable to create container31β Container not running32β Container already running33β Unable to stop container34β Unable to add IP address to container40β Container not mounted41β Container already mounted43β Container private area not found44β Container private area already exists46β Not enough disk space47β Bad/broken container (/sbin/initor/bin/shnot found)48β Unable to create a new container private area49β Unable to create a new container root area50β Unable to mount container51β Unable to unmount container52β Unable to delete a container53β Container private area not exist60βvzquota onfailed61βvzquota initfailed62βvzquota setlimitfailed63β ParameterDISKSPACEnot set64β ParameterDISKINODESnot set65β Error setting in-container disk quotas66βvzquota offfailed67βugidquota not initialized71β Incorrect IP address format74β Error changing password78β IP address already in use79β Container action script returned an error82β Config file copying error86β Error setting devices (--devicesor--devnodes)89β IP address not available91β OS template not found99β Ploop is not supported by either the running kernel orvzctl.100β Unable to find container IP address104βVE_NETDEVioctl error105β Container start disabled106β Unable to set iptables on a running container107β Distribution-specific configuration file not found109β Unable to apply a config129β Unable to set meminfo parameter130β Error setting veth interface131β Error setting container name133β Waiting for container start failed139β Error saving container configuration file148β Error setting container IO parameters (ioprio)150β Ploop image file not found151β Error creating ploop image152β Error mounting ploop image153β Error unmounting ploop image154β Error resizing ploop image155β Error converting container to ploop layout156β Error creating ploop snapshot157β Error merging ploop snapshot158β Error deleting ploop snapshot159β Error switching ploop snapshot166β Error compacting ploop image167β Error listing ploop snapsots
πΈ EXAMPLES πΈ
okay bestie, real talk, this is the part everyone actually scrolls to, so let's go. β¨
Wanna create AND start a "basic" container with ID <code>1000</code> using the <code>centos-5</code> OS template and IP <code>192.168.10.200</code>? Boom, three lines, you're a sysadmin:
vzctl create 1000 --ostemplate centos-5 --config basic
vzctl set 1000 --ipadd 192.168.10.200 --save
vzctl start 1000
Setting the number of processes barrier/limit to <code>80/100</code>, plus PTY barrier/limit to <code>16/20</code> PTYs? Say less:
vzctl set 1000 --numproc 80:100 -t 16:20 --save
Running <code>ls -la</code> inside this container? Exec it, periodt:
vzctl exec 1000 /bin/ls -la
Running a whole pipe, like <code>ls -l / | sort</code>, inside this container? Just quote it, bestie:
vzctl exec 1000 'ls -l / | sort'
Entering this container and running <code>apt-get install vim</code>?
vzctl enter 1000 --exec apt-get install vim
β οΈ heads up, no cap: in the example above you WILL need to log out from the container's shell after apt-get finishes. it's not gonna do it for you. π
okay so now the glow-up version. Wanna enter this container, run <code>apt-get install vim</code>, and log out after a successful install β but stay inside the container if the installation failed? Use &&:
vzctl enter 1000 --exec "apt-get install vim && logout"
Wanna enter this container, run <code>apt-get install vim</code>, and log out no matter what the exit code of the install was? Use ;:
vzctl enter 1000 --exec "apt-get install vim ; logout"
π important: you need to quote the command if you use&∨. no quoting, no vibes.
Stopping this container?
vzctl stop 1000
Permanently removing this container? (gone gone, not coming back π)
vzctl destroy 1000
π FILES π
here's where everything lives, bestie. memorize it, iykyk:
/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
π SEE ALSO π
go read your sisters, they're all iconic:
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
βοΈ LICENSE βοΈ
Copyright (C) 2000-2013, Parallels, Inc. Licensed under GNU GPL.
and that's the whole page, bestie!! π«Ά this one came from OpenVZ, dated 3 Jul 2014, and it's the manual for vzctl(8). go forth and containerize responsibly. slay. πβ¨π
π¦ where this page comes from
- ubuntu jammy: vzctl 4.9.4-6
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms