Merge lp:~gary/ubuntu/precise/lxc/bug-951150 into lp:ubuntu/precise/lxc

Proposed by Gary Poster
Status: Merged
Merge reported by: Stéphane Graber
Merged at revision: not available
Proposed branch: lp:~gary/ubuntu/precise/lxc/bug-951150
Merge into: lp:ubuntu/precise/lxc
Diff against target: 140 lines (+50/-20)
2 files modified
debian/changelog (+8/-0)
debian/local/lxc-start-ephemeral (+42/-20)
To merge this branch: bzr merge lp:~gary/ubuntu/precise/lxc/bug-951150
Reviewer Review Type Date Requested Status
Ubuntu branches Pending
Review via email: mp+97021@code.launchpad.net

Description of the change

In lxc-start-ephemeral, convert all bind mounted directories in the ephemeral's fstab to also be ephemeral. This means that, in the common case, all of the instance will be ephemeral.

-b continues to bind mount a directory directly, so it can be used to provide a location to persistently store results if desired. Its implementation has been changed to also use fstab, which simplifies cleanup and is arguably more robust in some circumstances.

Thank you

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :

Also, "sudo lxc-wait -n $LXC_NAME -s RUNNING" moved down into the lxc-console code path. lxc-wait cannot be run in parallel (bug 951181) so it is problematic. It is only necessary for the lxc-console path, so we moved it there, removing the problem from the "-- [COMMAND [ARGS...]]" path.

79. By Gary Poster

use a true tempfs instead of an overlayfs for the upper ephemeral dir

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2012-03-08 21:23:56 +0000
3+++ debian/changelog 2012-03-12 14:06:22 +0000
4@@ -1,3 +1,11 @@
5+lxc (0.7.5-3ubuntu35) precise; urgency=low
6+
7+ * lxc-start-ephemeral: make fstab bind mounts also ephemeral; simplify
8+ the implementation of the (non-ephemeral) -b bind option by using
9+ fstab. (LP: #951150)
10+
11+ -- Gary Poster (Gerbrand Poster IV) <gary.poster@canonical.com> Mon, 12 Mar 2012 09:52:24 -0400
12+
13 lxc (0.7.5-3ubuntu34) precise; urgency=low
14
15 [Benji York]
16
17=== modified file 'debian/local/lxc-start-ephemeral'
18--- debian/local/lxc-start-ephemeral 2012-03-08 21:23:43 +0000
19+++ debian/local/lxc-start-ephemeral 2012-03-12 14:06:22 +0000
20@@ -31,16 +31,12 @@
21 longoptions='help,orig:,bdir:,user:,ssh-key:'
22
23 LXC_RUNNING=0
24-LXC_BIND_MOUNTED=0
25 LXC_MOUNTED=0
26
27 cleanup() {
28 if [ $LXC_RUNNING -eq 1 ]; then
29 sudo lxc-stop -n $LXC_NAME
30 fi
31- if [ $LXC_BIND_MOUNTED -eq 1 ]; then
32- sudo umount $LXC_DIR/rootfs$LXC_BIND
33- fi
34 if [ $LXC_MOUNTED -eq 1 ]; then
35 sudo umount $LXC_DIR
36 sudo umount $OVERLAY_DIR
37@@ -50,7 +46,7 @@
38 exit 1
39 }
40
41-trap cleanup SIGTERM SIGINT SIGQUIT
42+trap cleanup SIGTERM SIGINT SIGQUIT
43
44 getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
45 if [ $? != 0 ]; then
46@@ -118,27 +114,57 @@
47 LXC_NAME=`basename $LXC_DIR`
48 sudo mount -t overlayfs -oupperdir=$OVERLAY_DIR,lowerdir=/var/lib/lxc/$LXC_BASE none $LXC_DIR
49 LXC_MOUNTED=1
50+
51+# Update the ephemeral lxc's configuration to reflect the new container name.
52+sudo sed -i -e "s/$LXC_BASE/$LXC_NAME/" $LXC_DIR/fstab $LXC_DIR/config $LXC_DIR/rootfs/etc/hostname $LXC_DIR/rootfs/etc/hosts
53+
54+# Update the fstab to have all bind mounts be ephemeral.
55+sudo mv $LXC_DIR/fstab $LXC_DIR/fstab.old
56+while read line; do
57+ # Pull out the second field of the current line of fstab info
58+ path=`echo -n $line | awk '{print $2}'`
59+ # If LXC_BIND is not set, or the mount destination of this line is not
60+ # LXC_BIND...
61+ if [ -z "$LXC_BIND" -o "`readlink -f $path`" != "`readlink -f $LXC_DIR/rootfs$LXC_BIND`" ];
62+ then
63+ # ...then we should write some form of this line.
64+ # If this line is a bind...
65+ if [ `echo -n $line | awk '{print $4}'` == "bind" ]; then
66+ # ...we should rewrite it as an overlay.
67+ source=`echo -n $line | awk '{print $1}'`
68+ upperdir=$LXC_DIR/ephemeralbind$source
69+ sudo mkdir -p $upperdir
70+ sudo chown `sudo stat -c '%U.%G' $source` $upperdir
71+ echo "none $path overlayfs upperdir=$upperdir,lowerdir=$source 0 0";
72+ else
73+ # Otherwise, we can pass it through unchanged.
74+ echo $line;
75+ fi
76+ fi
77+done < $LXC_DIR/fstab.old > $LXC_DIR/fstab
78+sudo rm -f $LXC_DIR/fstab.old
79+
80+# If LXC_BIND is defined, add it to fstab.
81 if [ -n "$LXC_BIND" ]; then
82 sudo mkdir -p $LXC_DIR/rootfs$LXC_BIND
83- sudo mount --bind $LXC_BIND $LXC_DIR/rootfs$LXC_BIND
84- LXC_BIND_MOUNTED=1
85+ echo "$LXC_BIND $LXC_DIR/rootfs$LXC_BIND none bind 0 0" >> $LXC_DIR/fstab
86 fi
87-sudo sed -i -e "s/$LXC_BASE/$LXC_NAME/" $LXC_DIR/fstab $LXC_DIR/config $LXC_DIR/rootfs/etc/hostname $LXC_DIR/rootfs/etc/hosts
88
89 # update the ephemeral container's MAC address (lifted from lxc-clone)
90 c=$LXC_DIR/config
91 # change hwaddrs
92-mv ${c} ${c}.old
93+sudo mv ${c} ${c}.old
94 (
95 while read line; do
96- if [ "${line:0:18}" = "lxc.network.hwaddr" ]; then
97- echo "lxc.network.hwaddr= 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')"
98- else
99- echo $line
100- fi
101+ if [ "${line:0:18}" = "lxc.network.hwaddr" ]; then
102+ hwaddr=$(sudo openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')
103+ echo "lxc.network.hwaddr=00:16:3e:$hwaddr"
104+ else
105+ echo $line
106+ fi
107 done
108 ) < ${c}.old > ${c}
109-rm -f ${c}.old
110+sudo rm -f ${c}.old
111
112 # precise is now the worst - its dhclient *uses*
113 # /var/lib/dhcp3/dhclient.eth0.leases but ships without that
114@@ -153,7 +179,6 @@
115 echo "Starting up the container..."
116 sudo lxc-start -n $LXC_NAME -d
117 LXC_RUNNING=1
118-sudo lxc-wait -n $LXC_NAME -s RUNNING
119
120 if [ $# -gt 0 ]; then
121 # when lxc-attach support arrives in the kernel, we can switch to
122@@ -190,6 +215,7 @@
123 cat $LEASES2 >&2
124 fi
125 else
126+ sudo lxc-wait -n $LXC_NAME -s RUNNING
127 echo "$LXC_NAME is running"
128 echo "You connect with the command:"
129 echo " sudo lxc-console -n $LXC_NAME"
130@@ -199,10 +225,6 @@
131 echo "Stopping lxc" >&2
132 sudo lxc-stop -n $LXC_NAME
133 sleep 2
134-if [ -n "$LXC_BIND" ]; then
135- echo "umounting bind" >&2
136- sudo umount $LXC_DIR/rootfs$LXC_BIND
137-fi
138 # echo "umounting lxc_dir $LXC_DIR" >&2
139 sudo umount $LXC_DIR
140 # echo "umounting overlay" >&2

Subscribers

People subscribed via source and target branches

to all changes: