From cbf9250a28f013b37569836a60746337376ae840 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Thu, 19 Mar 2015 08:12:25 +0100 Subject: [PATCH 1/7] Merge branch 'master', remote branch 'origin' From a89b7a5aa5376a4a7998eedbf7379e7408ccf961 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Thu, 19 Mar 2015 08:24:24 +0100 Subject: [PATCH 2/7] added more fedora distros and option for output image location now it is allowed to use also http://... format as a distro name and you can choose another location for vm image because manytimes root partition is very small --- create-guest-qcow2.bash | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/create-guest-qcow2.bash b/create-guest-qcow2.bash index 239d993..74dde02 100755 --- a/create-guest-qcow2.bash +++ b/create-guest-qcow2.bash @@ -41,7 +41,8 @@ IMAGE_HOME="/var/lib/libvirt/images" burl="http://dl.fedoraproject.org/pub" location1="$burl/fedora/linux/releases/20/Fedora/ARCH/os" location2="$burl/fedora/linux/releases/21/Server/ARCH/os" - +location3="$burl/fedora/linux/development/22/ARCH/os" +location4="$burl/fedora/linux/development/rawhide/ARCH/os" # Create a minimal kickstart file and return the temporary file name. # Do remember to delete this temporary file when it is no longer required. @@ -54,7 +55,7 @@ create_ks_file() cat << EOF > $fkstart install text -reboot +shutdown lang en_US.UTF-8 keyboard us network --bootproto dhcp @@ -112,7 +113,8 @@ create_guest() --hvm \ --location=$locn \ --nographics \ - --serial=pty + --serial=pty\ + --noreboot rm $fkst return 0 @@ -120,9 +122,10 @@ create_guest() usage () { - echo -e "Usage: $prog [OPTIONS] \n" - echo " distro: f20 f21" ++ echo -e "Usage: $prog [OPTIONS] [destination directory]\n" ++ echo " distro: f20 f21 f22 fraw or http os source like: http://.../pub/fedora/linux/development/latest-22/x86_64/os/" echo " arch: i386, x86_64" + echo " destination directory: directory, where to store image instead of default one" } printh () @@ -177,7 +180,7 @@ check_options () # check if min no. of arguments are 3 # - if [ "$#" != 3 ]; then + if [ "$#" -lt 3 ]; then printh; exit 255 fi @@ -194,6 +197,8 @@ check_options () name=$1 dist=$2 arch=$3 + destdir=$4 + test -n "$destdir" && IMAGE_HOME="$destdir" dimg="$IMAGE_HOME/$name.qcow2" locn="" @@ -207,7 +212,22 @@ check_options () dist="fedora21" locn=${location2/ARCH/$arch} ;; + + f22) + dist="fedora21" + locn=${location3/ARCH/$arch} + ;; + + fraw) + dist="fedora21" + locn=${location4/ARCH/$arch} + ;; + http*) + locn=${dist/ARCH/$arch} + echo "RAW version: $locn" + dist="fedora21" + ;; *) echo "$0: invalid distribution name" From 6ea6978e0fc9f64142612416f59802a1c7ff6009 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Thu, 19 Mar 2015 09:29:44 +0100 Subject: [PATCH 3/7] added example script for generation images and repo for virt-builder automatically --- auto_create_vm.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 auto_create_vm.sh diff --git a/auto_create_vm.sh b/auto_create_vm.sh new file mode 100755 index 0000000..6ed44c4 --- /dev/null +++ b/auto_create_vm.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +prog=`basename $0` + +function printh() { + echo -e "Usage: $prog " + echo " [customization_script]" + echo " postfix: it create output name in format like fedora21-suffix" + echo " dir: where to create/store images" + echo " customization_script: do customization script on guests [optional]" + +} +if [ "$#" -lt 2 ]; then + printh; + exit 255 +fi + +POSTFIX=$1 +DIR=$2 +test "$3" && CUSTOMIZATION="--script '$3'" +ARCH=x86_64 +TYPE=qcow2 +mkdir -p $DIR + + +function create_parametrized(){ + DIST=$1 + REALDIST=$2 + REVISION=$3 + test "$4" && DISTOVERWRITE=$4 || DISTOVERWRITE=$DIST + DOMAIN=$DIST-$POSTFIX + ./create-guest-qcow2.bash $DOMAIN $REALDIST $ARCH $DIR + sudo virt-sysprep --connect qemu:///system -d $DOMAIN $CUSTOMIZATION + DISCNAME="$DOMAIN.$TYPE" + CDISCNAME="$DISCNAME.xz" + UNSIZE=`stat $DIR/$DISCNAME -c "%s"` + xz --best --block-size=16777216 $DIR/$DISCNAME + COMSIZE=`stat $DIR/$CDISCNAME -c "%s"` + SHASUM=`sha512sum $DIR/$CDISCNAME | cut -d ' ' -f 1` + + cat <> $DIR/index +[$DOMAIN] +name=$DOMAIN +osinfo=$DISTOVERWRITE +arch=$ARCH +file=$CDISCNAME +revision=$REVISION +checksum=$SHASUM +format=$TYPE +size=$UNSIZE +compressed_size=$COMSIZE +EOF +} + +create_parametrized fedora21 f21 1 fedora21 +create_parametrized fedora22 f22 1 fedora21 + +if [ `gpg --list-keys | wc -l` -lt 4 ]; then + echo "!!! your probably does not have generated gpg key, running command: gpg --gen-key" + gpg --gen-key +fi +echo "Signing $DIR/index file" +gpg --clearsign --armor $DIR/index From 0e321b78df210b35eed079a31061dac5844b9e45 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Thu, 19 Mar 2015 09:32:41 +0100 Subject: [PATCH 4/7] removed diff + chars in usage --- create-guest-qcow2.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create-guest-qcow2.bash b/create-guest-qcow2.bash index 74dde02..f3f2dff 100755 --- a/create-guest-qcow2.bash +++ b/create-guest-qcow2.bash @@ -122,8 +122,8 @@ create_guest() usage () { -+ echo -e "Usage: $prog [OPTIONS] [destination directory]\n" -+ echo " distro: f20 f21 f22 fraw or http os source like: http://.../pub/fedora/linux/development/latest-22/x86_64/os/" + echo -e "Usage: $prog [OPTIONS] [destination directory]\n" + echo " distro: f20 f21 f22 fraw or http os source like: http://.../pub/fedora/linux/development/latest-22/x86_64/os/" echo " arch: i386, x86_64" echo " destination directory: directory, where to store image instead of default one" } From ec8838f306953bd18f03dd1463dd5350b1a104b5 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Thu, 19 Mar 2015 10:01:16 +0100 Subject: [PATCH 5/7] added timeout and dir option optional --- auto_create_vm.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/auto_create_vm.sh b/auto_create_vm.sh index 6ed44c4..c1e740a 100755 --- a/auto_create_vm.sh +++ b/auto_create_vm.sh @@ -4,19 +4,19 @@ prog=`basename $0` function printh() { echo -e "Usage: $prog " - echo " [customization_script]" + echo " [dir] [customization_script]" echo " postfix: it create output name in format like fedora21-suffix" - echo " dir: where to create/store images" + echo " dir: where to create/store images [optional]" echo " customization_script: do customization script on guests [optional]" } -if [ "$#" -lt 2 ]; then +if [ "$#" -lt 1 ]; then printh; exit 255 fi POSTFIX=$1 -DIR=$2 +test "$2" && DIR=$2 || DIR=/var/lib/libvirt/images test "$3" && CUSTOMIZATION="--script '$3'" ARCH=x86_64 TYPE=qcow2 @@ -24,12 +24,14 @@ mkdir -p $DIR function create_parametrized(){ +set -x DIST=$1 REALDIST=$2 REVISION=$3 test "$4" && DISTOVERWRITE=$4 || DISTOVERWRITE=$DIST DOMAIN=$DIST-$POSTFIX ./create-guest-qcow2.bash $DOMAIN $REALDIST $ARCH $DIR + sleep 5 sudo virt-sysprep --connect qemu:///system -d $DOMAIN $CUSTOMIZATION DISCNAME="$DOMAIN.$TYPE" CDISCNAME="$DISCNAME.xz" @@ -37,7 +39,6 @@ function create_parametrized(){ xz --best --block-size=16777216 $DIR/$DISCNAME COMSIZE=`stat $DIR/$CDISCNAME -c "%s"` SHASUM=`sha512sum $DIR/$CDISCNAME | cut -d ' ' -f 1` - cat <> $DIR/index [$DOMAIN] name=$DOMAIN @@ -50,6 +51,7 @@ format=$TYPE size=$UNSIZE compressed_size=$COMSIZE EOF +set +x } create_parametrized fedora21 f21 1 fedora21 From ef21fed26a26b1f366e8b550418ee16ae747cffc Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Thu, 19 Mar 2015 10:11:38 +0100 Subject: [PATCH 6/7] added example --- auto_create_vm.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/auto_create_vm.sh b/auto_create_vm.sh index c1e740a..58dbe8b 100755 --- a/auto_create_vm.sh +++ b/auto_create_vm.sh @@ -1,5 +1,7 @@ #!/bin/bash +# example: ./auto_create_vm.sh cockpit ~/build + prog=`basename $0` function printh() { From b88891ef75b42f6b70e389594e8b676419bf2380 Mon Sep 17 00:00:00 2001 From: Jan Scotka Date: Thu, 19 Mar 2015 13:02:52 +0100 Subject: [PATCH 7/7] added new line to created file --- auto_create_vm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/auto_create_vm.sh b/auto_create_vm.sh index 58dbe8b..9ecd977 100755 --- a/auto_create_vm.sh +++ b/auto_create_vm.sh @@ -52,6 +52,7 @@ checksum=$SHASUM format=$TYPE size=$UNSIZE compressed_size=$COMSIZE + EOF set +x }