X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lbuild-initvm.sh;h=7320e65db020046b1317d735f90dfa331d7ca8db;hb=120f503bf8a8858167ea150a65f2bd42de2644a6;hp=50c59b47f4703fd85e50a93ff65b3749d7eb8c95;hpb=3ec21c6f6101d68a2103db9011e735bb4e69ef2d;p=build.git diff --git a/lbuild-initvm.sh b/lbuild-initvm.sh index 50c59b47..7320e65d 100755 --- a/lbuild-initvm.sh +++ b/lbuild-initvm.sh @@ -19,12 +19,21 @@ export PATH=$PATH:/bin:/sbin . build.common +# xxx fixme : we pass $lxc around in functions, +# but in fact then we use lxc_root which is a global.. +# it works, but this really is poor practice +# we should have an lxc_root function instead +function lxcroot () { + lxc=$1; shift + echo /vservers/$lxc +} + # XXX fixme : when creating a 32bits VM we need to call linux32 as appropriate...s -DEFAULT_FCDISTRO=f21 +DEFAULT_FCDISTRO=f22 DEFAULT_PLDISTRO=lxc DEFAULT_PERSONALITY=linux64 -DEFAULT_MEMORY=1024 +DEFAULT_MEMORY=3072 ########## # constant @@ -106,6 +115,9 @@ function fedora_install() { set -x set -e + lxc=$1; shift + lxc_root=$(lxcroot $lxc) + cache=/var/cache/lxc/fedora/$arch/$release mkdir -p $cache @@ -117,7 +129,7 @@ function fedora_install() { fedora_download $cache || { echo "Failed to download 'fedora base'"; return 1; } else echo "Updating cache $cache/rootfs ..." - if ! yum --installroot $cache/rootfs -y --nogpgcheck update ; then + if ! yum --installroot $cache/rootfs --releasever $release -y --nogpgcheck update ; then echo "Failed to update 'fedora base', continuing with last known good cache" else echo "Update finished" @@ -196,7 +208,7 @@ function fedora_download() { # So ideally if we want to be able to build f12 images from f18 we need an rpm that has # this patch undone, like we have in place on our f14 boxes (our f14 boxes need a f18-like rpm) - YUM="yum --installroot=$INSTALL_ROOT --nogpgcheck -y" + YUM="yum --installroot=$INSTALL_ROOT --releasever=$release --nogpgcheck -y" echo "$YUM install $FEDORA_PREINSTALLED" $YUM install $FEDORA_PREINSTALLED || { echo "Failed to download rootfs, aborting." ; return 1; } @@ -212,6 +224,9 @@ function fedora_configure() { set -x set -e + lxc=$1; shift + lxc_root=$(lxcroot $lxc) + # disable selinux in fedora mkdir -p $lxc_root/selinux echo 0 > $lxc_root/selinux/enforce @@ -259,9 +274,9 @@ EOF mknod -m 666 ${dev_path}/ptmx c 5 2 if [ "$(echo $fcdistro | cut -d"f" -f2)" -le "14" ]; then - fedora_configure_init + fedora_configure_init $lxc else - fedora_configure_systemd + fedora_configure_systemd $lxc fi guest_ifcfg=${lxc_root}/etc/sysconfig/network-scripts/ifcfg-$VIF_GUEST @@ -275,6 +290,9 @@ EOF function fedora_configure_init() { set -e set -x + lxc=$1; shift + lxc_root=$(lxcroot $lxc) + sed -i 's|.sbin.start_udev||' ${lxc_root}/etc/rc.sysinit sed -i 's|.sbin.start_udev||' ${lxc_root}/etc/rc.d/rc.sysinit # don't mount devpts, for pete's sake @@ -288,6 +306,9 @@ function fedora_configure_init() { function fedora_configure_systemd() { set -e set -x + lxc=$1; shift + lxc_root=$(lxcroot $lxc) + # so ignore if we can't find /etc/systemd at all [ -d ${lxc_root}/etc/systemd ] || return 0 # otherwise let's proceed @@ -313,6 +334,7 @@ function fedora_configure_yum () { fcdistro=$1; shift pldistro=$1; shift + lxc_root=$(lxcroot $lxc) # rpm --rebuilddb chroot ${lxc_root} $personality rpm --rebuilddb @@ -361,6 +383,8 @@ EOF } ############################## +# apparently ubuntu exposes a mirrors list by country at +# http://mirrors.ubuntu.com/mirrors.txt # need to specify the right mirror for debian variants like ubuntu and the like function debian_mirror () { fcdistro=$1; shift @@ -368,7 +392,8 @@ function debian_mirror () { squeeze|wheezy|jessie) echo http://ftp2.fr.debian.org/debian/ ;; oneiric|precise|quantal|raring|saucy|trusty|utopic|vivid) - echo http://mir1.ovh.net/ubuntu/ubuntu/ ;; +# echo http://mir1.ovh.net/ubuntu/ubuntu/ ;; + echo http://www-ftp.lip6.fr/pub/linux/distributions/Ubuntu/archive/ ;; *) echo unknown distro $fcdistro; exit 1;; esac } @@ -377,10 +402,11 @@ function debian_install () { set -e set -x lxc=$1; shift + lxc_root=$(lxcroot $lxc) mkdir -p $lxc_root arch=$(canonical_arch $personality $fcdistro) mirror=$(debian_mirror $fcdistro) - debootstrap --arch $arch $fcdistro $lxc_root $mirror + debootstrap --no-check-gpg --arch $arch $fcdistro $lxc_root $mirror # just like with fedora we ensure a few packages get installed as well # not started yet #virsh -c lxc:/// lxc-enter-namespace $lxc /usr/bin/$personality /bin/bash -c "apt-get update" @@ -427,15 +453,17 @@ function setup_lxc() { pldistro=$1; shift personality=$1; shift + lxc_root=$(lxcroot $lxc) + # create lxc container pkg_method=$(package_method $fcdistro) case $pkg_method in yum) if [ -z "$IMAGE" ]; then - fedora_install || { echo "failed to install fedora root image"; exit 1 ; } + fedora_install $lxc || { echo "failed to install fedora root image"; exit 1 ; } fi - fedora_configure || { echo "failed to configure fedora for a container"; exit 1 ; } + fedora_configure $lxc || { echo "failed to configure fedora for a container"; exit 1 ; } ;; debootstrap) if [ -z "$IMAGE" ]; then @@ -486,6 +514,7 @@ function setup_lxc() { function write_lxc_xml_publicip () { lxc=$1; shift + lxc_root=$(lxcroot $lxc) cat < $lxc @@ -521,6 +550,7 @@ EOF # grant build guests the ability to do mknods function write_lxc_xml_natip () { lxc=$1; shift + lxc_root=$(lxcroot $lxc) cat < $lxc @@ -594,6 +624,8 @@ function devel_or_test_tools () { pldistro=$1; shift personality=$1; shift + lxc_root=$(lxcroot $lxc) + pkg_method=$(package_method $fcdistro) pkgsfile=$(pl_locateDistroFile $DIRNAME $pldistro $PREINSTALLED) @@ -647,8 +679,10 @@ function devel_or_test_tools () { function post_install () { lxc=$1; shift personality=$1; shift + lxc_root=$(lxcroot $lxc) # setup localtime from the host cp /etc/localtime $lxc_root/etc/localtime + sshd_disable_password_auth $lxc # post install hook [ -n "$NAT_MODE" ] && post_install_natip $lxc $personality || post_install_myplc $lxc $personality # start the VM unless specified otherwise @@ -663,6 +697,14 @@ function post_install () { fi } +# just in case, let's stay on the safe side +function sshd_disable_password_auth () { + lxc=$1; shift + lxc_root=$(lxcroot $lxc) + sed --in-place=.password -e 's,^#\?PasswordAuthentication.*,PasswordAuthentication no,' \ + $lxc_root/etc/ssh/sshd_config +} + function post_install_natip () { set -x @@ -671,6 +713,7 @@ function post_install_natip () { lxc=$1; shift personality=$1; shift + lxc_root=$(lxcroot $lxc) ### From myplc-devel-native.spec # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation @@ -692,6 +735,7 @@ function post_install_myplc () { lxc=$1; shift personality=$1; shift + lxc_root=$(lxcroot $lxc) # be careful to backslash $ in this, otherwise it's the root context that's going to do the evaluation cat << EOF | chroot ${lxc_root} $personality bash -x @@ -817,7 +861,7 @@ function main () { # parse fixed arguments [[ -z "$@" ]] && usage lxc=$1 ; shift - lxc_root=/vservers/$lxc + lxc_root=$(lxcroot $lxc) # rainchecks almost_empty $lxc_root || \ @@ -833,7 +877,6 @@ function main () { rsync -a $IMAGE/ $lxc_root/ fi - # check we've exhausted the arguments [[ -n "$@" ]] && usage