[Lxc-users] lxc template for RHEL?
Dan Kegel
dank at kegel.com
Mon Aug 27 19:27:47 UTC 2012
On Sat, Aug 25, 2012 at 10:24 PM, Fajar A. Nugraha <list at fajar.net> wrote:
> Please re-download lxc-centos.in and try again. You need to remove the
> cache first (rm -rf /var/cache/lxc/centos/x86_64/6/rootfs) so that it
> will be recreated.
Hmm. Is UTSNAME supposed to be defined on entry to the template?
It isn't here, leading to /etc/sysconfig/network and
/etc/sysconfig/network-scripts/ifcfg-eth0
containing bad
HOSTNAME=
lines. (The fedora template has same problem.)
I worked around this with:
--- lxc-centos.in 2012-08-27 10:45:56.301880000 -0700
+++ /usr/lib/lxc/templates/lxc-centos 2012-08-27 12:12:30.271501887 -0700
@@ -52,7 +52,7 @@
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
-HOSTNAME=${UTSNAME}
+HOSTNAME=${name}
NM_CONTROLLED=no
TYPE=Ethernet
MTU=${MTU}
@@ -61,7 +61,7 @@
# set the hostname
cat <<EOF > ${rootfs_path}/etc/sysconfig/network
NETWORKING=yes
-HOSTNAME=${UTSNAME}
+HOSTNAME=${name}
EOF
# set minimal hosts
The next problem is a bug in lxc-start-ephemeral, which complains
sed: can't read
/var/lib/lxc/demo_centos6-temp-j4G0FcH/rootfs/etc/hostname: No such
file or directory
The error comes from the line
# 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
I worked around this with
--- 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
Thanks,
Dan
More information about the lxc-users
mailing list