Commit Graph

109 Commits

Author SHA1 Message Date
Serge Hallyn
f6d3e3e470 Implement userid mappings (enable user namespaces)
The 3.8 kernel now supporst uid mappings, so I believe it's appropriate
to proceed with this patchset.
The container config supports new entries of the form:
 lxc.id_map = U 100000 0 10000
 lxc.id_map = G 100000 0 10000
meaning map 'virtual' uids (in the container) 0-10000 to uids
100000-110000 on the host, and same for gids.  So long as there are
mappings specified in the container config, then CONFIG_NEWUSER will
be used when the container is cloned.  This means that container
setup is no longer done with root privilege on the host, only root
privilege in the container.  Therefore cgroup setup is moved from the
init task to the monitor task.

To use this patchset, you currently need to either use the raring
kernel at ppa:serge-hallyn/usern-natty, or build your own kernel
from either git://kernel.ubuntu.com/serge/quantal-userns.git.
(Alternatively you can use Eric's tree at the latest userns-always-map-*
branch at
git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace.git
but you will likely want to at least enable tmpfs mounts in user namespaces)

You also need to chown the files in the container rootfs into the
mapped range.  There is a utility at
https://code.launchpad.net/~serge-hallyn/+junk/nsexec to do this.
uidmapshift does the chowning, while the container-userns-convert
script nicely wraps that program.  So I simply

	sudo lxc-create -t ubuntu -n r1
	sudo container-userns-convert r1 200000

will create a container which is shifted so uid 0 in the container
is uid 200000 on the host.

TODO: when doing setuid(0), need to only do that if 0 is one of the
ids we map to.  Similarly, when dropping capabilities, need to only
not do that if 0 is one of the ids we map to.  However, the question
of what to do for 'weird' containers in private user namespaces is
one I'm punting for later.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-15 12:09:33 -05:00
Michael H. Warfield
f7bee6c6f3 MAKEDEV call, add autodev hooks, add environment variables for hook scripts.
Ok...  Here's the patch again.  Since Serge is removing the loglevel
structure member, this patch no longer references that element.

From the original description:

1) Removes run_makedev() and the call to it from conf.c per discussion.

2) Adds an lxc.hook.autodev hook.

Note: This hook is very close (one routine level abstracted) from where
the run_makedev was called.  Anyone really rrreeeaaalllyyy needing
MAKEDEV can add it in with a small shim script to do whatever they want
under whatever distro they're using, so no functionality is lost there.

3) Added a number of environment variables for all the hook scripts to
reference to assist in execution.  Things like LXC_ROOTFS_MOUNT could be
very useful but others were added as well.  Room for more if anyone has
an itch.  All in one spot in lxc_start.c.

4) clearenv and putenv( "container=lxc" ) calls were moved to just after
the "start" hook in the container just prior to actually firing up the
container so we could use environment variables prior to that and have
them flushed them before firing up init.  Nice side effect is that you
can define environment variables and then call lxc-start and have them
show up in those hooks scripts.

5) I actually DID update the man page for lxc.conf!  I guess I lied when
I said I wouldn't get that done.

[... and ...]

I added the rcfile to the lxc_conf structure as suggested and moved the
setenv bundle from lxc-start.c over to start.c just prior to calling
run_lxc_hooks for the pre-start hook.

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-01-14 14:04:09 -06:00
Dwight Engen
768487891f document lxc-console escape sequence and argument
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-08 12:05:43 -05:00
Dwight Engen
596a818d4b separate console device from console log
lxc-start -c makes the named file/device the container's console, but using
this with a regular file in order to get a log of the console output does
not work very well if you also want to login on the console. This change
implements an additional option (-L) to simply log the console's output to
a file.

Both options can be used separately or together. For example to get a usable
console and log: lxc-start -n name -c /dev/tty8 -L console.log

The console state is cleaned up more when lxc_delete_console is called, and
some of the clean up paths in lxc_create_console were fixed.

The lxc_priv and lxc_unpriv macros were modified to make use of gcc's local
label feature so they can be expanded more than once in the same function.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-02 18:08:12 -05:00
Stéphane Graber
6a85cf9124 Install legacy scripts when built without python.
Re-introduce the old lxc-ls script and manpage under a new legacy
sub-directory.

Those will be installed in place of their python equivalent when LXC
is built without --enable-python.

Any other script ported to python should be added to those lists.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-12-04 14:01:30 -05:00
Stéphane Graber
4e7186c535 Rewrite lxc-ls in python
This rewrite is mostly compatible with the shell version.
--active and -1 still work and behave as they used to.

This adds --running, --stopped and --frozen as state filters.

A new "fancy" view is also implemented (can be used with --fancy) and
will show containers in a column-based interface with the following fields:
 - name
 - state
 - ipv4
 - ipv6
 - pid of init

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2012-12-04 14:00:56 -05:00
Stéphane Graber
f79d43bbe7 Remove all trailing whitespaces.
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-26 12:08:13 -05:00
Stéphane Graber
ad493d03fe lxc.conf.sgml.in: Fix typo
Fix a typo in the previous lxc.conf.sgml.in change.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-26 11:45:28 -05:00
Serge Hallyn
c6883f383e Add lxc.autodev
Add a container config option to mount and populate /dev in a container.

We might want to add options to specify a max size for /dev other than
the default 100k, and to specify other devices to create.  And maybe
someone can think of a better name than autodev.

Changelog: Don't error out if we couldn't mknod a /dev/ttyN.
Changelog: Describe the option in lxc.conf manpage.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-26 10:02:47 -06:00
Natanael Copa
3114c98242 lxc-start: add option -p, --pidfile=FILE
Add option to create a pidfile for lxc-start. This is helpful for
init scripts and process monitors when running as daemon.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-15 10:50:56 -05:00
Stéphane Graber
24b292c917 lxc-create: Support passing a full path to -t
In some cases it may be useful to pass a full path to an executable
template script directly to lxc-create.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 16:41:14 -05:00
Stéphane Graber
7822022c4c Detect which name to use for docbook2x-man
docbook2x-man doesn't have the same name on Debian based systems as
on RedHat based systems, add some magic to configure.ac to detect and
substitute the proper name in Makefile.am

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 15:38:50 -05:00
Peter Simons
aa8d013ec5 Update documentation to Docbook 4.5
The package 'docbook-tools' [1] required to format Docbook 3.0 into man pages
has been obsoleted a long time ago and can no longer be downloaded from its
former homepage. Recent versions of that package -- now called 'docbook2X' --,
cannot deal with that old markup format anymore (and don't support the '-w all'
command line switch either). To remedy these issues, all SGML files have been
updated to Docbook 4.5 so that recent versions of docbook2man can process them.

[1] http://sources.redhat.com/docbook-tools/
[2] http://docbook2x.sourceforge.net/

Signed-off-by: Peter Simons <simons@cryp.to>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 15:20:39 -05:00
Dwight Engen
434445ee1e Reinstate README file in rootfs directory
Change 5fd8314f removed the README file explaining why the
rootfs directory has to exist. Doing so broke the build on
Fedora 17 since this directory will not be created by make
install and thus the spec file cannot find it.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:47:51 -05:00
Stéphane Graber
f282a2f4b8 Revert "Update documentation to Docbook 4.5"
This reverts commit 9a84044bc97098821cce2721ea40a1368f17a091.

The changes made the branch to fail to build on Ubuntu/Debian, so
reverting the commits and re-opening the pull request.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:18:32 -05:00
Stéphane Graber
efa99b3226 Revert "Convert remaining file to new docbook format"
This reverts commit 8587ac4b855b7b66931a37742c45cd2c8c624658.

The changes made the branch to fail to build on Ubuntu/Debian, so
reverting the commits and re-opening the pull request.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:18:32 -05:00
Stéphane Graber
e03243397d Convert remaining file to new docbook format 2012-11-12 13:18:32 -05:00
Peter Simons
75d0acd48f Update documentation to Docbook 4.5
The package 'docbook-tools' [1] required to format Docbook 3.0 into man pages
has been obsoleted a long time ago and can no longer be downloaded from its
former homepage. Recent versions of that package -- now called 'docbook2X' --,
cannot deal with that old markup format anymore (and don't support the '-w all'
command line switch either). To remedy these issues, all SGML files have been
updated to Docbook 4.5 so that recent versions of docbook2man can process them.

[1] http://sources.redhat.com/docbook-tools/
[2] http://docbook2x.sourceforge.net/

Signed-off-by: Peter Simons <simons@cryp.to>
2012-11-12 13:18:32 -05:00
Dwight Engen
037ba55cbe fix minor spelling error
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
2012-11-12 13:18:32 -05:00
Serge Hallyn
767d4c6743 premount hook is implemented in git
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:54 -05:00
Serge Hallyn
472c97e976 document lxc.hooks in lxc.conf manpage
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:54 -05:00
Stéphane Graber
72d0e1cb2f Merge the liblxc API work by Serge Hallyn.
This turns liblxc into a public library implementing a container structure.
The container structure is meant to cover most LXC commands and can easily be
used to write bindings in other programming languages.

More information on the new functions can be found in src/lxc/lxccontainer.h
Test programs using the API can also be found in src/tests/

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:16:16 -05:00
Christian Seiler
7a0b0b5672 lxc-attach: Add -R option to remount /sys and /proc when only partially attaching
When attaching to only some namespaces of the container but not the mount
namespace, the contents of /sys and /proc of the host system do not properly
reflect the context of the container's pid and/or network namespaces, and
possibly others.

The introduced -R option adds the possibility to additionally unshare the
mount namespace (when it is not being attached) and remount /sys and /proc
in order for those filesystems to properly reflect the container's context
even when only attaching to some of the namespaces.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Cc: Daniel Lezcano <daniel.lezcano@free.fr>
2012-11-12 13:16:16 -05:00
Christian Seiler
e13eeea2db lxc-attach: Add -s option to select namespaces to attach to
This patch allows the user to select any list of namespaces (network, pid,
mount, uts, ipc, user) that lxc-attach should use when attaching to the
container; all other namespaces will not be attached to.

This allows the user to for example attach to just the network namespace and
use the host's (and not the container's) network tools to reconfigure the
network of the container.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Cc: Daniel Lezcano <daniel.lezcano@free.fr>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
2012-11-12 13:15:17 -05:00
Serge Hallyn
1881820ae4 lxc-create: Make location of container rootfs configurable
Make 'dir' an explicit backing store type, which accepts '--dir rootfs'
as an option to specify a custom location for the container rootfs.  Also
update lxc-destroy to now remove the rootfs separately, as removing
@LXCPATH@/$name may not hit it.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:13:52 -05:00
Jan Kiszka
74a2b5864f Add network-down script
Analogously to lxc.network.script.up, add the ability to register a down
script. It is called before the guest network is finally destroyed,
allowing to clean up resources that are not reset/destroyed
automatically. Parameters of the down script are identical to the up
script except for the execution context "down".

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 12:04:30 -05:00
Jan Kiszka
b486346aa2 lxc-wait: Add timeout option
Allow to specify a timeout for waiting on state changes via lxc-wait.
Helpful for scripts that need to handle errors or excessive delays in
state changing procedures.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 12:03:23 -05:00
Dwight Engen
c12e775237 Allow short -h and -n options to lxc-ps
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
2012-10-25 10:35:53 +02:00
Dwight Engen
b4578c5b38 lxc-doc-synopsis-args
I was getting raw nroff ".SH DESCRIPTION" in my man pages. This fixes
the synopsis cmd args so that doesn't happen. Added replaceable to a few
arguments.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
2012-10-25 10:32:37 +02:00
Serge Hallyn
72be4f89b0 Add lxc-shutdown script
It optionally waits (an optional timeout # of seconds) for the container to
be STOPPED.  If given -r, it reboots the container (and exits immediately).
I decided to add the timeout after all because it's harder to finagle into
an upstart post-stop script than a full bash script.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-07-31 16:04:33 +02:00
Daniel Baumann
5548f2182e Change ipv4 addresses in the configuration examples
Use non-routed, private IPv4 address in documentation examples
(Closes: #571525).

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-07-31 16:01:22 +02:00
David Ward
7ef0141356 refresh lxc-ls
Add an '--active' option that lists active containers by searching
cgroups. (Otherwise, the directories in /var/lib/lxc are listed.)
Modify the cgroup search to only use hierarchies that contain one
or more subsystems. When searching, if a hierarchy contains the
'ns' subsystem, do not append '/lxc' to the parent cgroup.

Add a '--help' option that prints the command syntax.

Print error messages and help information to stderr.

Update the documentation.

Signed-off-by: David Ward <david.ward@ll.mit.edu>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-05-04 00:50:15 +02:00
David Ward
f10e7166ab lxc-cgroup: use correct terminology
lxc-cgroup gets or sets the value of a state object (such as
'cpuset.cpus'), not the value of a subsystem (which would be
just 'cpuset').

Signed-off-by: David Ward <david.ward@ll.mit.edu>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-05-04 00:50:15 +02:00
Serge Hallyn
1305dd24af Update manpages to reflect some updated options.
(which reminds me a lxc-clone manpage still needs to be written)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-03-19 00:31:40 +01:00
Daniel Lezcano
baf977694a fix lxc-attach.sgml.in spurious variable list
Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
2012-03-02 00:02:42 +01:00
Christian Seiler
49ee6cdcbf Add man page for lxc-attach
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-02-23 09:57:14 +01:00
Greg Kurz
d73ef6ec75 lxc: add Bugs section to lxc-monitor(1)
This lxc-monitor limitation deserves some lines in the manpage, until
something is done to allow several monitors to run concurrently.

Signed-off-by: Greg Kurz <gkurz@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-01-05 23:34:46 +01:00
Matthijs Kooijman
be58c6b5b4 .gateway options
Man for the gateway option.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-08-30 23:50:23 +02:00
Daniel Lezcano
c797dcc3d0 lxc-ps : update the man page for passing the options
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-08-11 17:54:57 +02:00
Daniel Lezcano
dff21ef019 explicitly do not use the console
If the keyword 'none' is specified for the console name, lxc will ignore creating a console.
That allows to have a rootfs but without a console.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-08-09 16:51:01 +02:00
Serge Hallyn
e2b4064f94 consolidate ubuntu templates
Consolidate lucid, maverick, natty, and oneiric templates into one 'ubuntu'
template.

Add support for specifying architecture.

Add support for '--trim|-x' option, which removes services like the lucid
template used to.  This creates smaller, faster-booting containers, but they
will not be safe with certain upgrades, like mountall or udev.  When -x is
not specified for lucid or maverick container, then install lxcguest from
the ubuntu-virt ppa, since it does not exist in the official archives, and
the container is not safe to boot without lxcguest.

Add support for '--bindhome <user>' option, which will cause /home/<user>
to be bind-mounted into the container, and create the user with his
original password, shell, and group memberships in the container.

changelog:
  june 23:
    lxc-ubuntu template: set lxc.arch in config
    install lxcguest when NOT trimming the container
    lxc-ubuntu: always install lxcguest in postprocess

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-06-25 15:17:47 +02:00
Cedric Le Goater
dfafa5a513 lxc-execute: document the '--' option
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-05-05 12:07:51 +02:00
Rob Landley
a3e80ccc74 fix lxc-checkpoint and lxc-restart sgml labels
The patch fixes two build breaks in the sgml files:

lxc-checkpoint.sgml.in
Element Title in namespace '' encountered in refsect1, but no template
matches.

lxc-restart.sgml:58: parser error : AttValue: " or ' expected
      <arg
choice=req><option>--name=<replaceable>NAME</replaceable></option></a


Signed-off-by: Rob Landley <rlandley@parallels.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-02-17 10:07:44 +01:00
Daniel Lezcano
955f4ce683 update configuration wrt to the broadcast address
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-02-06 21:30:18 +01:00
Daniel Lezcano
829dd9183c lxc-start can output the console to a file
Add the ability to specify a file to output the console.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-02-01 14:49:40 +01:00
Serge Hallyn
27b39fd49d Update ubuntu templates
Rename 'ubuntu' template to 'lucid'

Add new maverick and natty templates, which do much less tweaking
of the environment.  These should only be used on a kernel which
supports sysfs tagging for /sys/class/net, as udev will be running
in the container.

The natty template needed to slightly change the installed packages
for dhclient to be correclty installed.

Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-01-22 21:59:40 +01:00
Daniel Lezcano
6ecad93f96 update the man page with the net script hook
Update the man page wrt the hook script added for the host side
network configuration.

Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
2010-10-26 18:14:47 +02:00
Daniel Lezcano
49d3e78dce update the lxc.conf man page
Update the man page regarding the image or block device
supported as a rootfs.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-10-05 10:28:31 +02:00
Daniel Lezcano
cccc74b514 configure container architecture
When a container is installed with 32bits binaries while we are
running on a 64bits host, inside the container we are seen as
64bits arch. That leads to some problems for the package updates
because the scripts will download 64bits packages instead of 32bits.

This patch defines a configuration variable to set the architecture
of the container.

lxc.arch = i686 | x86 | x86_64 | amd64

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-09-13 15:36:20 +02:00
Daniel Lezcano
765a4e0783 add lxc.console documentation
Add missing documenation about the console output.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-06-17 14:04:15 +02:00