From: InformatiQ <rha...@informatiq.org>

*Enable [-A|--arch] option which allows for specifying the fedora conatiner 
architecture (i386|i686|x86_64)
 * can create ix86 under an x86_64 host but not the other way around
 * i386 and i686 are the same


Signed-off-by: InformatiQ <rha...@informatiq.org>
---
 templates/lxc-fedora.in |   38 +++++++++++++++++++++++++++-----------
 1 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/templates/lxc-fedora.in b/templates/lxc-fedora.in
index 3f50895..4377ef9 100644
--- a/templates/lxc-fedora.in
+++ b/templates/lxc-fedora.in
@@ -26,8 +26,6 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 #Configurations
-arch=$(arch)
-cache_base=/var/cache/lxc/fedora/$arch
 default_path=/var/lib/lxc
 root_password=rooter
 lxc_network_type=veth
@@ -36,9 +34,6 @@ lxc_network_link=virbr0
 # is this fedora?
 [ -f /etc/fedora-release ] && is_fedora=true
 
-if [ "$arch" = "i686" ]; then
-    arch=i386
-fi
 
 configure_fedora()
 {
@@ -125,7 +120,7 @@ download_fedora()
 
     # download a mini fedora into a cache
     echo "Downloading fedora minimal ..."
-    YUM="yum --installroot $INSTALL_ROOT -y --nogpgcheck"
+    YUM="$SETARCH yum --installroot $INSTALL_ROOT -y --nogpgcheck"
     PKG_LIST="yum initscripts passwd rsyslog vim-minimal dhclient chkconfig 
rootfiles policycoreutils"
     
MIRRORLIST_URL="http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$release&arch=$arch";
 
@@ -153,8 +148,8 @@ download_fedora()
     fi
 
     mkdir -p $INSTALL_ROOT/var/lib/rpm
-    rpm --root $INSTALL_ROOT  --initdb
-    rpm --root $INSTALL_ROOT -ivh 
$INSTALL_ROOT/fedora-release-$release.noarch.rpm
+    $SETARCH rpm --root $INSTALL_ROOT  --initdb
+    $SETARCH rpm --root $INSTALL_ROOT -ivh 
$INSTALL_ROOT/fedora-release-$release.noarch.rpm
     $YUM install $PKG_LIST
 
     if [ $? -ne 0 ]; then
@@ -182,7 +177,7 @@ copy_fedora()
 
 update_fedora()
 {
-    YUM="yum --installroot $cache/rootfs -y --nogpgcheck"
+    YUM="$SETARCH yum --installroot $cache/rootfs -y --nogpgcheck"
     $YUM update
 }
 
@@ -310,13 +305,13 @@ Optional args:
   -p,--path         path to where the container rootfs will be created, 
defaults to /var/lib/lxc. The container config will go under /var/lib/lxc in 
that case
   -c,--clean        clean the cache
   -R,--release      Fedora release for the new container. if the host is 
Fedora, then it will defaultto the host's release.
-  -A,--arch         NOT USED YET. Define what arch the container will be 
[i686,x86_64]
+  -A,--arch         Define what arch the container will be [i686,x86_64]
   -h,--help         print this help
 EOF
     return 0
 }
 
-options=$(getopt -o hp:n:cR: -l help,path:,name:,clean,release: -- "$@")
+options=$(getopt -o hp:n:cR:A: -l help,path:,name:,clean,release:,arch: -- 
"$@")
 if [ $? -ne 0 ]; then
     usage $(basename $0)
     exit 1
@@ -331,11 +326,32 @@ do
        -n|--name)      name=$2; shift 2;;
        -c|--clean)     clean=$2; shift 2;;
         -R|--release)   release=$2; shift 2;;
+        -A|--arch)      user_arch=$2; shift 2;;
        --)             shift 1; break ;;
         *)              break ;;
     esac
 done
 
+if [ -z $user_arch ]; then 
+    arch=$(arch)
+else
+    case "$user_arch" in
+        i686|i386)    arch="i386";;
+        x86_64)       arch="x86_64"; [ -n "$(arch|grep -E -e 'i.86')" ] && 
echo "cannot create x86_64 container in a ix86 host" && exit 1;; 
+        *)            echo "arch can be i686,i386 or x86_64 only"; exit 1;;
+    esac
+fi
+
+if [ "$arch" = "i686" ]; then
+    arch=i386
+fi
+if [ "$(arch)" = "$arch" ]; then
+    SETARCH=""
+else
+    SETARCH="setarch $arch"
+fi
+cache_base=/var/cache/lxc/fedora/$arch
+
 if [ ! -z "$clean" -a -z "$path" ]; then
     clean || exit 1
     exit 0
-- 
1.7.7.6


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Lxc-users mailing list
Lxc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-users

Reply via email to