[Lxc-users] [PATCH 2/9] lxc-clone: update any hwaddrs

Serge Hallyn serge at hallyn.com
Thu Apr 26 05:09:34 UTC 2012


From: Serge Hallyn <serge.hallyn at ubuntu.com>

Since we are creating a new container it should not share a macaddr with
the original container.

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 src/lxc/lxc-clone.in |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/lxc/lxc-clone.in b/src/lxc/lxc-clone.in
index 386be30..228fd0d 100644
--- a/src/lxc/lxc-clone.in
+++ b/src/lxc/lxc-clone.in
@@ -263,6 +263,20 @@ if [ -f $rootfs/etc/dhcp/dhclient.conf ]; then
     sed -i "s/send host-name.*$/send host-name \"$hostname\";/" $rootfs/etc/dhcp/dhclient.conf
 fi
 
+c=$lxc_path/$lxc_new/config
+# change hwaddrs
+mv ${c} ${c}.old
+(
+while read line; do
+	if [ "${line:0:18}" = "lxc.network.hwaddr" ]; then
+		echo "lxc.network.hwaddr= 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')"
+	else
+		echo $line
+	fi
+done
+) < ${c}.old > ${c}
+rm -f ${c}.old
+
 # set the hostname
 cat <<EOF > $rootfs/etc/hostname
 $hostname
-- 
1.7.9.5





More information about the lxc-users mailing list