Virtualization (LXC Containers): Difference between revisions
(documenting LXC (in progress)) |
(Major LXC update, remove linux vserver) |
||
Line 1: | Line 1: | ||
⚫ | As of Fall 2009, we use [http://lxc.sourceforge.net/ Linux containers] to maintain virtual machines, most notably [[Machine_List#caffeine|caffeine]], which is hosted on [[Machine_List#glomag|glomag]]. The various commands to manipulate Linux containers are prefixed with "lxc-"; see their individual manpages for usage. |
||
= Linux Containers = |
|||
= Creating a new container = |
|||
⚫ | As of Fall 2009, we use [http://lxc.sourceforge.net/ Linux containers] to maintain |
||
Create a new container using `lxc-create`: |
|||
# Create new container "containername" with root fs located at /vm/containername |
|||
lxc-create --dir=/vm/containername -n containername --template download |
|||
This will prompt you for distribution, release, and architecture. (Architecture *must* match host machine.) |
|||
# List containers |
|||
lxc-ls |
|||
to ensure that your container has been successfully created; it should be listed. You can also list its root directory if you like. To start it in the background and obtain a root shell, do |
|||
# Start and attach a root shell |
|||
lxc-start -d -n containername |
|||
lxc-attach -n containername |
|||
Now you're ready to [[New CSC Machine|configure your machine]]. |
|||
== Networking == |
|||
Networking might not be enabled on your container by default. If this is the case (easily checked with `ifconfig`), you'll need to modify its config file, located at /var/lib/lxc/containername/config: |
|||
# Network configuration |
|||
lxc.network.type = veth |
|||
lxc.network.flags = up |
|||
# that's the interface defined above in host's interfaces file |
|||
lxc.network.link = br0 |
|||
# name of network device inside the container, |
|||
# defaults to eth0, you could choose a name freely |
|||
# lxc.network.name = lxcnet0 |
|||
lxc.network.hwaddr = DE:AD:BE:EF:70:10 # your favourite fake MAC |
|||
# the ip may be set to 0.0.0.0/24 or skip this line |
|||
# if you like to use a dhcp client inside the container |
|||
lxc.network.ipv4 = 129.97.134.XXX/24 |
|||
# define a gateway to have access to the internet |
|||
lxc.network.ipv4.gateway = 129.97.134.1 |
|||
= Management Quick Guide = |
|||
To manage containers, use the <tt>lxc-*</tt> tools, which require root privilege. Some examples (replace <tt>caffeine</tt> with the appropriate container name): |
To manage containers, use the <tt>lxc-*</tt> tools, which require root privilege. Some examples (replace <tt>caffeine</tt> with the appropriate container name): |
||
Line 29: | Line 73: | ||
Containers are stored on the host filesystem in /var/lib/lxc (root filesystems are symlinked to the appropriate directory on /vm). |
Containers are stored on the host filesystem in /var/lib/lxc (root filesystems are symlinked to the appropriate directory on /vm). |
||
= VServer = |
|||
[http://linux-vserver.org/ Linux-VServer Homepage] |
|||
vserver $NAME build -m debootstrap --hostname magic --interface $IFACE:$IP/24 -- -d lenny |
|||
To have a vserver autostart, create a file called /etc/vservers/$VSERVER/apps/init/mark with content: |
|||
default |
|||
[[Category:Software]] |
[[Category:Software]] |
Revision as of 15:58, 28 July 2015
As of Fall 2009, we use Linux containers to maintain virtual machines, most notably caffeine, which is hosted on glomag. The various commands to manipulate Linux containers are prefixed with "lxc-"; see their individual manpages for usage.
Creating a new container
Create a new container using `lxc-create`:
# Create new container "containername" with root fs located at /vm/containername lxc-create --dir=/vm/containername -n containername --template download
This will prompt you for distribution, release, and architecture. (Architecture *must* match host machine.)
# List containers lxc-ls
to ensure that your container has been successfully created; it should be listed. You can also list its root directory if you like. To start it in the background and obtain a root shell, do
# Start and attach a root shell lxc-start -d -n containername lxc-attach -n containername
Now you're ready to configure your machine.
Networking
Networking might not be enabled on your container by default. If this is the case (easily checked with `ifconfig`), you'll need to modify its config file, located at /var/lib/lxc/containername/config:
# Network configuration lxc.network.type = veth lxc.network.flags = up # that's the interface defined above in host's interfaces file lxc.network.link = br0 # name of network device inside the container, # defaults to eth0, you could choose a name freely # lxc.network.name = lxcnet0 lxc.network.hwaddr = DE:AD:BE:EF:70:10 # your favourite fake MAC # the ip may be set to 0.0.0.0/24 or skip this line # if you like to use a dhcp client inside the container lxc.network.ipv4 = 129.97.134.XXX/24 # define a gateway to have access to the internet lxc.network.ipv4.gateway = 129.97.134.1
Management Quick Guide
To manage containers, use the lxc-* tools, which require root privilege. Some examples (replace caffeine with the appropriate container name):
# check if caffeine is running lxc-info -n caffeine # start caffeine in the background lxc-start -d -n caffeine # stop caffeine gracefully lxc-halt -n caffeine # stop caffeine forcefully lxc-stop -n caffeine # launch a TTY console for the container lxc-console -n caffeine
To install Linux container support on a recent Debian (squeeze or newer) system:
- Install the lxc and bridge-utils packages.
- Create a bridged network interface (this can be configured in /etc/network/interfaces as though it were a normal Ethernet device, with the additional bridge_ports parameter. This is usually called br0 (can be created manually with brctl). LXC will create a virtual Ethernet device and add it to the bridge when each container starts.
To start caffeine, run the following command as root on glomag:
lxc-start -d -n caffeine
Containers are stored on the host filesystem in /var/lib/lxc (root filesystems are symlinked to the appropriate directory on /vm).