Comment 0 for bug 1042431

Revision history for this message
Dan Kegel (dank) wrote :

As discussed in the thread "lxc template for RHEL?"
http://sourceforge.net/mailarchive/message.php?msg_id=29730103
lxc-start-ephemeral only knows how to tweak the hostname for ubuntu and debian,
and needs to be taught about where rhel and centos put hostname, something like this:

--- lxc-start-ephemeral.orig 2012-08-27 12:19:03.935513119 -0700
+++ lxc-start-ephemeral 2012-08-27 12:19:54.471514479 -0700
@@ -154,7 +154,19 @@
     LXC_MOUNTED=1

     # Update the ephemeral lxc's configuration to reflect the new
container name.
- 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
+ # Check all the places known distros keep hostnames.
+ # FIXME: should we sanity check the hostname to make sure it contains no bad chars?
+ for file in $LXC_DIR/fstab $LXC_DIR/config \
+ $LXC_DIR/rootfs/etc/hostname \
+ $LXC_DIR/rootfs/etc/hosts \
+ $LXC_DIR/rootfs/etc/sysconfig/network \
+ $LXC_DIR/rootfs/etc/sysconfig/network-scripts/ifcfg-eth0
+ do
+ if test -f "$file"
+ then
+ sudo sed -i -e "s/$LXC_BASE/$LXC_NAME/" $file
+ fi
+ done

     # Update the fstab to have all bind mounts be ephemeral.
     sudo cp $LXC_DIR/fstab $LXC_DIR/fstab.old

This affects 12.04 and the ppa for lxc, so probably also 12.10 alpha 3.