X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lbuild-initvm.sh;h=857daab4d7e16a88e08d0f6fdbf7ffde3f31b4dd;hb=c997a4666d28a7d8a17fef4cc4a3b526ef969ed9;hp=f37f419be029df6b9c15e403ae07970e9e622702;hpb=7dd49f795015387df7b7e85a33b2216bbe326d29;p=build.git diff --git a/lbuild-initvm.sh b/lbuild-initvm.sh index f37f419b..857daab4 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=f20 +DEFAULT_FCDISTRO=f23 DEFAULT_PLDISTRO=lxc DEFAULT_PERSONALITY=linux64 -DEFAULT_MEMORY=512 +DEFAULT_MEMORY=3072 ########## # constant @@ -72,9 +81,12 @@ EOF function package_method () { fcdistro=$1; shift case $fcdistro in - f[0-9]*|centos[0-9]*|sl[0-9]*) echo yum ;; - squeeze|wheezy|jessie|oneiric|precise|quantal|raring|saucy|trusty) echo debootstrap ;; - *) echo Unknown distro $fcdistro ;; + f[0-9]*|centos[0-9]*|sl[0-9]*) + echo yum ;; + wheezy|jessie|precise|trusty|utopic|vivid|wily) + echo debootstrap ;; + *) + echo Unknown distro $fcdistro ;; esac } @@ -106,6 +118,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 +132,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" @@ -165,10 +180,13 @@ function fedora_download() { MIRROR_URL=$FEDORA_MIRROR_BASE/releases/$release/Everything/$arch/os RELEASE_URL1="$MIRROR_URL/Packages/fedora-release-$release-1.noarch.rpm" # with fedora18 the rpms are scattered by first name - RELEASE_URL2="$MIRROR_URL/Packages/f/fedora-release-$release-1.noarch.rpm" + # first try the second version of fedora-release first + RELEASE_URL2="$MIRROR_URL/Packages/f/fedora-release-$release-2.noarch.rpm" + RELEASE_URL3="$MIRROR_URL/Packages/f/fedora-release-$release-1.noarch.rpm" + RELEASE_TARGET=$INSTALL_ROOT/fedora-release-$release.noarch.rpm found="" - for attempt in $RELEASE_URL1 $RELEASE_URL2; do + for attempt in $RELEASE_URL1 $RELEASE_URL2 $RELEASE_URL3; do if curl -f $attempt -o $RELEASE_TARGET ; then echo "Retrieved $attempt" found=true @@ -193,7 +211,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; } @@ -209,6 +227,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 @@ -256,13 +277,13 @@ 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 - ( [ -n "$BUILD_MODE" ] && write_guest_ifcfg_build || write_guest_ifcfg_test ) > $guest_ifcfg + ( [ -n "$NAT_MODE" ] && write_guest_ifcfg_natip || write_guest_ifcfg_publicip ) > $guest_ifcfg [ -z "$IMAGE" ] && fedora_configure_yum $lxc $fcdistro $pldistro @@ -272,6 +293,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 @@ -285,18 +309,17 @@ 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 ln -sf /lib/systemd/system/multi-user.target ${lxc_root}/etc/systemd/system/default.target touch ${lxc_root}/etc/fstab ln -sf /dev/null ${lxc_root}/etc/systemd/system/udev.service -# Thierry - Feb 2013 -# this was intended for f16 initially, in order to enable getty that otherwise would not start -# having a getty running is helpful only if ssh won't start though, and we see a correlation between -# VM's that refuse to lxc-stop and VM's that run crazy getty's +# Thierry - Feb 2013 relying on getty is looking for trouble # so, turning getty off for now instead -# #dependency on a device unit fails it specially that we disabled udev # sed -i 's/After=dev-%i.device/After=/' ${lxc_root}/lib/systemd/system/getty\@.service ln -sf /dev/null ${lxc_root}/etc/systemd/system/"getty@.service" rm -f ${lxc_root}/etc/systemd/system/getty.target.wants/*service || : @@ -314,6 +337,7 @@ function fedora_configure_yum () { fcdistro=$1; shift pldistro=$1; shift + lxc_root=$(lxcroot $lxc) # rpm --rebuilddb chroot ${lxc_root} $personality rpm --rebuilddb @@ -338,7 +362,7 @@ gpgcheck=1 gpgkey=$FEDORA_MIRROR_KEYS/RPM-GPG-KEY-fedora-$release-primary EOF - # for using vtest-init-lxc.sh as a general-purpose lxc creation wrapper + # for using this script as a general-purpose lxc creation wrapper # just mention 'none' as the repo url if [ -n "$REPO_URL" ] ; then if [ ! -d $lxc_root/etc/yum.repos.d ] ; then @@ -362,14 +386,17 @@ 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 case $fcdistro in - squeeze|wheezy|jessie) + wheezy|jessie) echo http://ftp2.fr.debian.org/debian/ ;; - oneiric|precise|quantal|raring|saucy|trusty) - echo http://mir1.ovh.net/ubuntu/ubuntu/ ;; + precise|trusty|utopic|vivid|wily) +# 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 } @@ -378,10 +405,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" @@ -397,17 +425,17 @@ EOF function debian_configure () { guest_interfaces=${lxc_root}/etc/network/interfaces - ( [ -n "$BUILD_MODE" ] && write_guest_interfaces_build || write_guest_interfaces_test ) > $guest_interfaces + ( [ -n "$NAT_MODE" ] && write_guest_interfaces_natip || write_guest_interfaces_publicip ) > $guest_interfaces } -function write_guest_interfaces_build () { +function write_guest_interfaces_natip () { cat < $lxc_root/etc/hosts # grant ssh access from host to guest @@ -466,7 +503,7 @@ function setup_lxc() { # don't keep the input xml, this can be retrieved at all times with virsh dumpxml config_xml=/tmp/$lxc.xml - ( [ -n "$BUILD_MODE" ] && write_lxc_xml_build $lxc || write_lxc_xml_test $lxc ) > $config_xml + ( [ -n "$NAT_MODE" ] && write_lxc_xml_natip $lxc || write_lxc_xml_publicip $lxc ) > $config_xml # define lxc container for libvirt virsh -c lxc:/// define $config_xml @@ -474,8 +511,18 @@ function setup_lxc() { return 0 } -function write_lxc_xml_test () { +# this part does not belong in a domain any more +# but goes in a network object of its own existence +# +# host-bridge +# +# +# +# + +function write_lxc_xml_publicip () { lxc=$1; shift + lxc_root=$(lxcroot $lxc) cat < $lxc @@ -504,17 +551,14 @@ function write_lxc_xml_test () { - - host-bridge - - - EOF } -function write_lxc_xml_build () { +# grant build guests the ability to do mknods +function write_lxc_xml_natip () { lxc=$1; shift + lxc_root=$(lxcroot $lxc) cat < $lxc @@ -525,6 +569,9 @@ function write_lxc_xml_build () { + + + 1 @@ -547,7 +594,7 @@ EOF } # this one is dhcp-based -function write_guest_ifcfg_build () { +function write_guest_ifcfg_natip () { cat <