]> git.proxmox.com Git - mirror_lxc.git/blobdiff - templates/lxc-centos.in
confile: rename lxc.devttydir to lxc.tty.dir
[mirror_lxc.git] / templates / lxc-centos.in
index 99faf4b0e481509aace72fc9765d58f9704bce85..a211636dc06e92384d3ecde9c5762241647ca024 100644 (file)
@@ -1,7 +1,7 @@
 #!/bin/bash
 
 #
-# template script for generating centos container for LXC
+# template script for generating CentOS container for LXC
 
 #
 # lxc: linux Container library
@@ -71,7 +71,7 @@ default_path=@LXCPATH@
 lxc_network_type=veth
 lxc_network_link=lxcbr0
 
-# is this centos?
+# is this CentOS?
 # Alow for weird remixes like the Raspberry Pi
 #
 # Use the Mitre standard CPE identifier for the release ID if possible...
@@ -137,8 +137,9 @@ if [ "${CPE_NAME}" != "" -a "${ID}" = "centos" -a "${VERSION_ID}" != "" ]
 then
     centos_host_ver=${VERSION_ID}
     is_centos=true
-elif [ "${CPE_NAME}" != "" -a "${ID}" = "redhat" -a "${VERSION_ID}" != "" ]
+elif [ "${CPE_NAME}" != "" -a "${ID}" = "redhat" -o "${ID}" = "rhel" -a "${VERSION_ID}" != "" ]
 then
+    # RHEL 7+ /etc/os-release ID = 'rhel', which doesn't enter this elif without the added OR statement
     redhat_host_ver=${VERSION_ID}
     is_redhat=true
 elif [ -e /etc/centos-release ]
@@ -160,7 +161,7 @@ force_mknod()
 configure_centos()
 {
 
-    # disable selinux in centos
+    # disable selinux in CentOS
     mkdir -p $rootfs_path/selinux
     echo 0 > $rootfs_path/selinux/enforce
 
@@ -249,7 +250,7 @@ configure_centos()
 DEVICE=eth0
 BOOTPROTO=dhcp
 ONBOOT=yes
-HOSTNAME=${UTSNAME}
+HOSTNAME=${utsname}
 NM_CONTROLLED=no
 TYPE=Ethernet
 MTU=${MTU}
@@ -259,7 +260,7 @@ EOF
     # set the hostname
     cat <<EOF > ${rootfs_path}/etc/sysconfig/network
 NETWORKING=yes
-HOSTNAME=${UTSNAME}
+HOSTNAME=${utsname}
 EOF
 
     # set minimal hosts
@@ -335,7 +336,7 @@ EOF
     # /dev/tty[1-4] will be symlinks to the ptys /dev/lxc/console and
     # /dev/lxc/tty[1-4] so that package updates can overwrite the symlinks.
     # lxc will maintain these links and bind mount ptys over /dev/lxc/*
-    # since lxc.devttydir is specified in the config.
+    # since lxc.tty.dir is specified in the config.
 
     # allow root login on console, tty[1-4], and pts/0 for libvirt
     echo "# LXC (Linux Containers)" >>${rootfs_path}/etc/securetty
@@ -394,7 +395,7 @@ configure_centos_init()
 #  power-status-changed - shutdown on SIGPWR
 #
 start on power-status-changed
-    
+
 exec /sbin/shutdown -h now "SIGPWR received"
 EOF
     fi
@@ -403,7 +404,7 @@ EOF
 download_centos()
 {
 
-    # check the mini centos was not already downloaded
+    # check the mini CentOS was not already downloaded
     INSTALL_ROOT=$cache/partial
     mkdir -p $INSTALL_ROOT
     if [ $? -ne 0 ]; then
@@ -411,8 +412,8 @@ download_centos()
     return 1
     fi
 
-    # download a mini centos into a cache
-    echo "Downloading centos minimal ..."
+    # download a mini CentOS into a cache
+    echo "Downloading CentOS minimal ..."
     YUM0="yum --installroot $INSTALL_ROOT -y --nogpgcheck"
 
     if yum -h | grep -q 'releasever=RELEASEVER'; then
@@ -420,9 +421,12 @@ download_centos()
     else
        YUM="$YUM0"
     fi
-    PKG_LIST="yum initscripts passwd rsyslog vim-minimal openssh-server openssh-clients dhclient chkconfig rootfiles policycoreutils"
+    PKG_LIST="yum initscripts passwd rsyslog vim-minimal openssh-server openssh-clients dhclient chkconfig rootfiles policycoreutils cronie"
 
     # use temporary repository definition
+    # always prefer the repo given by the user
+    # if no repo given, use mirrorlist.centos.org for i386 and x86_64
+    # and http://mirror.centos.org/altarch/ otherwise
     REPO_FILE=$INSTALL_ROOT/etc/yum.repos.d/lxc-centos-temp.repo
     mkdir -p $(dirname $REPO_FILE)
     if [ -n "$repo" ]; then
@@ -431,7 +435,7 @@ download_centos()
 name=local repository
 baseurl="$repo"
 EOF
-else
+    elif [ ${basearch} = 'i386' ] || [ ${basearch} = 'x86_64' ]; then
        cat <<EOF > $REPO_FILE
 [base]
 name=CentOS-$release - Base
@@ -440,6 +444,16 @@ mirrorlist=http://mirrorlist.centos.org/?release=$release&arch=$basearch&repo=os
 [updates]
 name=CentOS-$release - Updates
 mirrorlist=http://mirrorlist.centos.org/?release=$release&arch=$basearch&repo=updates
+EOF
+    else
+       cat <<EOF > $REPO_FILE
+[base]
+name=CentOS-$release - Base
+baseurl=http://mirror.centos.org/altarch/7/os/$basearch/
+
+[updates]
+name=CentOS-$release - Updates
+baseurl=http://mirror.centos.org/altarch/7/updates/$basearch/
 EOF
     fi
 
@@ -450,6 +464,13 @@ EOF
 
     $YUM install $PKG_LIST
 
+    # create symlink for /var/run -> ../run 
+    if [ "$release" = "7" ]; then
+        mv $INSTALL_ROOT/var/run/* $INSTALL_ROOT/run/
+        rmdir $INSTALL_ROOT/var/run
+        ln -sf ../run $INSTALL_ROOT/var/run
+    fi
+
     if [ $? -ne 0 ]; then
         echo "Failed to download the rootfs, aborting."
         return 1
@@ -507,7 +528,7 @@ EOF
 copy_centos()
 {
 
-    # make a local copy of the mini centos
+    # make a local copy of the mini CentOS
     echo -n "Copying rootfs to $rootfs_path ..."
     #cp -a $cache/rootfs-$arch $rootfs_path || return 1
     # i prefer rsync (no reason really)
@@ -541,14 +562,14 @@ install_centos()
     if [ ! -e "$cache/rootfs" ]; then
         download_centos
         if [ $? -ne 0 ]; then
-            echo "Failed to download 'centos base'"
+            echo "Failed to download 'CentOS base'"
             return 1
         fi
     else
         echo "Cache found. Updating..."
         update_centos
         if [ $? -ne 0 ]; then
-            echo "Failed to update 'centos base', continuing with last known good cache"
+            echo "Failed to update 'CentOS base', continuing with last known good cache"
         else
             echo "Update finished"
         fi
@@ -597,13 +618,13 @@ lxc.rootfs = $rootfs_path
         # Seems that \s doesn't work in brackets.
         KEY=$(expr "${LINE}" : '\s*\([^         ]*\)\s*=')
 
-        if [[ "${KEY}" != "lxc.network.hwaddr" ]]
+        if [[ "${KEY}" != "lxc.net.0.hwaddr" ]]
         then
             echo ${LINE} >> $config_path/config
 
-            if [[ "${KEY}" == "lxc.network.link" ]]
+            if [[ "${KEY}" == "lxc.net.0.link" ]]
             then
-                echo "lxc.network.hwaddr = $(create_hwaddr)" >> $config_path/config
+                echo "lxc.net.0.hwaddr = $(create_hwaddr)" >> $config_path/config
             fi
         fi
     done < $config_path/config.def
@@ -626,16 +647,16 @@ lxc.utsname = $utsname
 #lxc.aa_profile = unconfined
 
 # example simple networking setup, uncomment to enable
-#lxc.network.type = $lxc_network_type
-#lxc.network.flags = up
-#lxc.network.link = $lxc_network_link
-#lxc.network.name = eth0
+#lxc.net.0.type = $lxc_network_type
+#lxc.net.0.flags = up
+#lxc.net.0.link = $lxc_network_link
+#lxc.net.0.name = eth0
 # Additional example for veth network type
 #    static MAC address,
-#lxc.network.hwaddr = 00:16:3e:77:52:20
+#lxc.net.0.hwaddr = 00:16:3e:77:52:20
 #    persistent veth device name on host side
 #        Note: This may potentially collide with other containers of same name!
-#lxc.network.veth.pair = v-$name-e0
+#lxc.net.0.veth.pair = v-$name-e0
 
 EOF
 
@@ -662,7 +683,7 @@ clean()
             exit 1
         fi
 
-        echo -n "Purging the download cache for centos-$release..."
+        echo -n "Purging the download cache for CentOS-$release..."
         rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
         exit 0
 
@@ -681,7 +702,7 @@ Mandatory args:
 Optional args:
   -p,--path         path to where the container rootfs will be created, defaults to /var/lib/lxc/name.
   -c,--clean        clean the cache
-  -R,--release      Centos release for the new container. if the host is Centos, then it will defaultto the host's release.
+  -R,--release      CentOS release for the new container. If the host is CentOS, then it will default to the host's release.
      --fqdn         fully qualified domain name (FQDN) for DNS and system naming
      --repo         repository to use (url)
   -a,--arch         Define what arch the container will be [i686,x86_64]
@@ -828,8 +849,8 @@ if [ -z "$release" ]; then
         # This is needed to clean out bullshit like 6workstation and 6server.
         release=$(expr $redhat_host_ver : '\([0-9.]*\)')
     else
-        echo "This is not a CentOS or Redhat host and release is missing, defaulting to 6 use -R|--release to specify release"
-        release=6
+        echo "This is not a CentOS or Red Hat host and release is missing, defaulting to 7, use -R|--release to specify release"
+        release=7
     fi
 fi
 
@@ -869,13 +890,13 @@ fi
 
 install_centos
 if [ $? -ne 0 ]; then
-    echo "failed to install centos"
+    echo "failed to install CentOS"
     exit 1
 fi
 
 configure_centos
 if [ $? -ne 0 ]; then
-    echo "failed to configure centos for a container"
+    echo "failed to configure CentOS for a container"
     exit 1
 fi
 
@@ -916,7 +937,16 @@ then
 else
     if [ ${root_expire_password} = "yes" ]
     then
-        echo "
+        if ( mountpoint -q -- "${rootfs_path}" )
+        then
+            echo "To reset the root password, you can do:
+
+        lxc-start -n ${name}
+        lxc-attach -n ${name} -- passwd
+        lxc-stop -n ${name}
+"
+        else
+           echo "
 The root password is set up as "expired" and will require it to be changed
 at first login, which you should do as soon as possible.  If you lose the
 root password or wish to change it without starting the container, you
@@ -925,5 +955,6 @@ also reset the expired flag):
 
         chroot ${rootfs_path} passwd
 "
+        fi
     fi
 fi