</term>
<listitem>
<para>
- 'backingstore' is one of 'none', 'lvm', or 'btrfs'. The
+ 'backingstore' is one of 'none', 'dir', 'lvm', or 'btrfs'. The
default is 'none', meaning that the container root filesystem
will be a directory under <filename>@LXCPATH@/container/rootfs</filename>.
+ 'dir' has the same meaning as 'none', but also allows the optional
+ <replaceable>--dir ROOTFS</replaceable> to be specified, meaning
+ that the container rootfs should be placed under the specified path,
+ rather than the default.
The option 'btrfs' need not be specified as it will be used
automatically if the <filename>@LXCPATH@</filename> filesystem is found to
be btrfs. If backingstore is 'lvm', then an lvm block device will be
echo >&2
echo "where FS_OPTIONS is one of:" >&2
echo " -B none" >&2
+ echo " -B dir [--dir rootfs_dir]" >&2
echo " -B lvm [--lvname LV_NAME] [--vgname VG_NAME] [--fstype FS_TYPE]" >&2
echo " [--fssize FS_SIZE]" >&2
echo " -B btrfs" >&2
echo " -B BACKING_STORE alter the container backing store (default: none)" >&2
echo " --lvname LV_NAME specify the LVM logical volume name" >&2
echo " (default: container name)" >&2
+ echo " --dir ROOTFS_DIR specify path for custom rootfs directory location" >&2
echo " --vgname VG_NAME specify the LVM volume group name (default: lxc)" >&2
echo " --fstype FS_TYPE specify the filesystem type (default: ext4)" >&2
echo " --fssize FS_SIZE specify the filesystem size (default: 500M)" >&2
}
shortoptions='hn:f:t:B:'
-longoptions='help,name:,config:,template:,backingstore:,fstype:,lvname:,vgname:,fssize:'
+longoptions='help,name:,config:,template:,backingstore:,fstype:,dir:,lvname:,vgname:,fssize:'
lxc_path=@LXCPATH@
bindir=@BINDIR@
templatedir=@LXCTEMPLATEDIR@
fstype=ext4
fssize=500M
vgname=lxc
+custom_rootfs=""
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
if [ $? != 0 ]; then
backingstore=$1
shift
;;
+ --dir)
+ shift
+ custom_rootfs=$1
+ shift
+ ;;
--lvname)
shift
lvname=$1
exit 1
fi
+if [ -n "$custom_rootfs" -a "$backingstore" != "dir" ]; then
+ echo "--dir is only valid with -B dir"
+fi
+
case "$backingstore" in
- lvm|none|btrfs|_unset) :;;
- *) echo "$(basename $0): '$backingstore' is not known (try 'none', 'lvm', 'btrfs')" >&2
+ dir|lvm|none|btrfs|_unset) :;;
+ *) echo "$(basename $0): '$backingstore' is not known (try 'none', 'dir', 'lvm', 'btrfs')" >&2
usage
exit 1
;;
cp $lxc_config $lxc_path/$lxc_name/config
fi
+if [ -n "$custom_rootfs" ]; then
+ if grep -q "lxc.rootfs" $lxc_path/$lxc_name/config ; then
+ echo "configuration file already specifies a lxc.rootfs"
+ exit 1
+ fi
+ echo "lxc.rootfs = $custom_rootfs" >> $lxc_path/$lxc_name/config
+fi
+
# Create the fs as needed
if [ $backingstore = "lvm" ]; then
[ -d "$rootfs" ] || mkdir $rootfs
# else, ignore it. We'll support deletion of others later.
rootdev=`grep lxc.rootfs $lxc_path/$lxc_name/config 2>/dev/null | sed -e 's/^[^/]*/\//'`
if [ -n "$rootdev" ]; then
- if [ -b "$rootdev" ]; then
+ if [ -b "$rootdev" -o -h "$rootdev" ]; then
lvdisplay $rootdev > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "removing backing store: $rootdev"
fi
fi
fi
+
# recursively remove the container to remove old container configuration
rm -rf --one-file-system --preserve-root $lxc_path/$lxc_name
{
mkdir -p $config_path
+ grep -q "^lxc.rootfs" $config_path/config 2>/dev/null || echo "lxc.rootfs = $rootfs_path" >> $config_path/config
cat <<EOF >> $config_path/config
lxc.utsname = $name
lxc.tty = 4
lxc.pts = 1024
-lxc.rootfs = $rootfs_path
lxc.mount = $config_path/fstab
# When using LXC with apparmor, uncomment the next line to run unconfined:
exit 1
fi
+# check for 'lxc.rootfs' passed in through default config by lxc-create
+if grep -q '^lxc.rootfs' $path/config 2>/dev/null ; then
+ rootfs_path=`grep 'lxc.rootfs =' $path/config | awk -F= '{ print $2 }'`
+fi
+
install_altlinux
if [ $? -ne 0 ]; then
echo "failed to install altlinux"
# write container configuration files
function copy_configuration {
mkdir -p "${config_path}"
+ grep -q "^lxc.rootfs" "${config_path}/config" 2>/dev/null || echo "lxc.rootfs=${rootfs_path}" >> "${config_path}/config"
cat > "${config_path}/config" << EOF
lxc.utsname=${name}
lxc.tty=4
lxc.pts=1024
-lxc.rootfs=${rootfs_path}
lxc.mount=${config_path}/fstab
# When using LXC with apparmor, uncomment the next line to run unconfined:
fi
rootfs_path="${path}/rootfs"
+# check for 'lxc.rootfs' passed in through default config by lxc-create
+if grep -q '^lxc.rootfs' $path/config 2>/dev/null ; then
+ rootfs_path=`grep 'lxc.rootfs =' $path/config | awk -F= '{ print $2 }'`
+fi
config_path="${default_path}/${name}"
revert()
rootfs=$2
name=$3
+grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config
lxc.utsname = $name
lxc.tty = 1
lxc.pts = 1
-lxc.rootfs = $rootfs
+EOF
+
+if [ -d "$rootfs/lib" ]; then
+cat <<EOF >> $path/config
+lxc.mount.entry=/lib $rootfs/lib none ro,bind 0 0
+lxc.mount.entry=/usr/lib $rootfs/usr/lib none ro,bind 0 0
+EOF
+fi
# When using LXC with apparmor, uncomment the next line to run unconfined:
#lxc.aa_profile = unconfined
exit 1
fi
-rootfs=$path/rootfs
+# detect rootfs
+config="$path/config"
+if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
+ rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
+else
+ rootfs=$path/rootfs
+fi
install_busybox $rootfs $name
if [ $? -ne 0 ]; then
rootfs=$2
hostname=$3
+ grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config
lxc.tty = 4
lxc.pts = 1024
-lxc.rootfs = $rootfs
lxc.utsname = $hostname
# When using LXC with apparmor, uncomment the next line to run unconfined:
exit 1
fi
-rootfs=$path/rootfs
+# detect rootfs
+config="$path/config"
+if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
+ rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
+else
+ rootfs=$path/rootfs
+fi
+
install_debian $rootfs
if [ $? -ne 0 ]; then
{
mkdir -p $config_path
+ grep -q "^lxc.rootfs" $config_path/config 2>/dev/null || echo "lxc.rootfs = $rootfs_path" >> $config_path/config
cat <<EOF >> $config_path/config
lxc.utsname = $name
lxc.tty = 4
lxc.pts = 1024
-lxc.rootfs = $rootfs_path
lxc.mount = $config_path/fstab
# When using LXC with apparmor, uncomment the next line to run unconfined:
rootfs=$2
name=$3
+ grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config
lxc.tty = 4
lxc.pts = 1024
-lxc.rootfs = $rootfs
lxc.cgroup.devices.deny = a
# When using LXC with apparmor, uncomment the next line to run unconfined:
exit 1
fi
-rootfs=$path/rootfs
+# detect rootfs
+config="$path/config"
+if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
+ rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
+else
+ rootfs=$path/rootfs
+fi
install_debian $rootfs
if [ $? -ne 0 ]; then
rootfs=$2
name=$3
+ grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config
lxc.utsname = $name
lxc.tty = 4
lxc.pts = 1024
-lxc.rootfs = $rootfs
lxc.mount = $path/fstab
# When using LXC with apparmor, uncomment the next line to run unconfined:
exit 1
fi
-rootfs=$path/rootfs
+# detect rootfs
+config="$path/config"
+if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
+ rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
+else
+ rootfs=$path/rootfs
+fi
install_opensuse $rootfs
if [ $? -ne 0 ]; then
rootfs=$2
name=$3
+ grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config
lxc.utsname = $name
lxc.pts = 1024
-lxc.rootfs = $rootfs
# When using LXC with apparmor, uncomment the next line to run unconfined:
#lxc.aa_profile = unconfined
exit 1
fi
-rootfs=$path/rootfs
+# detect rootfs
+config="$path/config"
+if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
+ rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
+else
+ rootfs=$path/rootfs
+fi
install_sshd $rootfs
if [ $? -ne 0 ]; then
EOF
fi
+ grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config
lxc.utsname = $name
lxc.tty = 4
lxc.pts = 1024
-lxc.rootfs = $rootfs
lxc.mount = $path/fstab
lxc.arch = $arch
lxc.cap.drop = sys_module mac_admin
exit 1
fi
-rootfs=$path/rootfs
+# detect rootfs
+config="$path/config"
+if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
+ rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
+else
+ rootfs=$path/rootfs
+fi
type ubuntu-cloudimg-query
type wget
EOF
fi
+ grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
cat <<EOF >> $path/config
lxc.utsname = $name
lxc.devttydir =$ttydir
lxc.tty = 4
lxc.pts = 1024
-lxc.rootfs = $rootfs
lxc.mount = $path/fstab
lxc.arch = $arch
lxc.cap.drop = sys_module mac_admin mac_override
exit 1
fi
-rootfs=$path/rootfs
+# detect rootfs
+config="$path/config"
+if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
+ rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
+else
+ rootfs=$path/rootfs
+fi
install_ubuntu $rootfs $release $flushcache
if [ $? -ne 0 ]; then