2 # LXC specific functions
4 ################################################################
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 or 3 as
10 # published by the Free Software Foundation.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program (see the file COPYING); if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 ################################################################
25 LXCID="obsbuild:${BUILD_ROOT##*/}"
28 vm_verify_options_lxc() {
35 LXCDIR="`lxc-config lxc.lxcpath`/$LXCID"
36 LXCROOTFS="$LXCDIR/rootfs"
37 LXCHOOK="$LXCDIR/pre-mount.hook"
38 LXCCONF="$BUILD_ROOT/.build.lxc.conf"
40 cat $BUILD_DIR/lxc.conf > "$LXCCONF"
41 cat >> "$LXCCONF" <<-EOF
42 lxc.rootfs = $LXCROOTFS
43 lxc.hook.pre-mount = $LXCHOOK
45 # XXX: do this always instead of leaking the hosts' one?
46 echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
47 lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
49 cat > "$LXCHOOK" <<-EOF
51 mount --bind "$BUILD_ROOT" "$LXCROOTFS"
54 case "$(lxc-create --version)" in
56 lxc-create -n "$LXCID" -f "$LXCCONF" -t none || cleanup_and_exit 1
57 lxc-start -n "$LXCID" -F "$vm_init_script"
60 lxc-create -n "$LXCID" -f "$LXCCONF" || cleanup_and_exit 1
61 lxc-start -n "$LXCID" "$vm_init_script"
65 test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
66 cleanup_and_exit "$BUILDSTATUS"
71 lxc-stop -n "$LXCID" || true
78 vm_attach_root_lxc() {
82 vm_attach_swap_lxc() {
86 vm_detach_root_lxc() {
90 vm_detach_swap_lxc() {
95 if test $$ -ne 1 && test $$ -ne 2 ; then
97 lxc-destroy -n "$LXCID"