diff --git a/libguestfs.test.simple.create-opensuse-guest.sh b/libguestfs.test.simple.create-opensuse-guest.sh index 90c2e2c..5213e5d 100644 --- a/libguestfs.test.simple.create-opensuse-guest.sh +++ b/libguestfs.test.simple.create-opensuse-guest.sh @@ -33,28 +33,44 @@ unset ${!LC_*} cpus=`grep -Ec 'cpu[0-9]' /proc/stat || echo 1` output_diskimage=/dev/shm/$LOGNAME/testcase.img -final_repo=http://download.opensuse.org/distribution/12.3/repo/oss/ -initial_repo=http://download.opensuse.org/distribution/13.1/repo/oss/ +final_repo=http://download.opensuse.org/distribution/13.1/repo/oss/ +initial_repo=http://download.opensuse.org/distribution/12.3/repo/oss/ force=false guest_zypper_in__pattern_name="base" guest_zypper_in__package_list="less vim grub master-boot-code parted nfs-utils" guest_root_password="root" diskname_inside_vm=/dev/sda +case "$0" in + /*) progname="$0" ;; + *) progname="$PWD/$0" ;; +esac + _exit() { echo "Exiting '$0 $*'." exit 1 } + +_unrpm() { + CPIO_OPTS="--extract --unconditional --preserve-modification-time --make-directories" + FILES="$@" + for f in $FILES; do + echo -ne "$f:\t" + rpm2cpio $f | cpio ${CPIO_OPTS} + done +} + until test $# -lt 1 do case "$1" in + --unrpm) shift ; _unrpm "$@" ; exit 0 ;; -n) diskname_inside_vm="$2" ; shift ;; -o) output_diskimage="$2" ; shift ;; -R) initial_repo="$2" ; shift ;; -r) final_repo="$2" ; shift ;; -f) force=true ;; -x) set -x ;; - *) echo "Unknown option '$1'" exit 1 ;; + *) echo "Unknown option '$1'" ; exit 1 ;; esac shift done @@ -82,6 +98,11 @@ then _exit fi fi +zypper --version +cpio --version +guestfish --version +qemu-system-`uname -m` --version + mkdir -vp "${output_diskimage%/*}" td=`mktemp -d --tmpdir=/dev/shm/${LOGNAME}` tf=`mktemp --tmpdir=/dev/shm/${LOGNAME}` @@ -142,7 +163,7 @@ zypper \ --download-only \ ${packages} cd ${dir_root} -find ${dir_cache} -xdev -name "*.rpm" -print0 | sort -z | xargs -0 -n 1 -P ${cpus} unrpm +find ${dir_cache} -xdev -name "*.rpm" -print0 | sort -z | xargs -0 -n 1 -P ${cpus} bash "${progname}" --unrpm mkdir -vp etc/zypp/repos.d grep -w search /etc/resolv.conf >> etc/resolv.conf echo nameserver 169.254.2.3 >> etc/resolv.conf @@ -205,12 +226,31 @@ sh "cp --verbose --sparse=never --remove-destination --target-directory=/boot/gr sh "grub --batch --verbose < /etc/grub.conf" : \ sh "echo BOOTPROTO='dhcp' >> /etc/sysconfig/network/ifcfg-eth0" : \ sh "echo STARTMODE='auto' >> /etc/sysconfig/network/ifcfg-eth0" : \ -sh "echo 'Password for root is ${guest_root_password}' >> /etc/issue" : \ +sh "echo 'Password for User root is: ${guest_root_password}' >> /etc/issue" : \ cat /etc/fstab : \ quit ls -lhsS "${output_diskimage}" -qemu-kvm \ +: ${diskname_inside_vm} +case "${diskname_inside_vm}" in + *vda*) + qemu_drive_options=" + -drive file=${output_diskimage},cache=writeback,id=hd0,if=none \ + -device virtio-blk-pci,drive=hd0 \ + " + ;; + *sda*) + qemu_drive_options=" + -device virtio-scsi-pci,id=scsi \ + -drive file=${output_diskimage},cache=unsafe,format=raw,id=hd0,if=none \ + -device scsi-hd,drive=hd0 \ + " + ;; + *) + echo "${diskname_inside_vm} not handled" + _exit +esac +qemu-system-`uname -m` -enable-kvm \ -global virtio-blk-pci.scsi=off \ -enable-fips \ -machine accel=kvm:tcg \ @@ -218,8 +258,7 @@ qemu-kvm \ -m 500 \ -no-reboot \ -no-hpet \ - -drive file=${output_diskimage},cache=writeback,id=hd0,if=none \ - -device virtio-blk-pci,drive=hd0 \ + ${qemu_drive_options} \ -device virtio-serial-pci \ -serial stdio \ -device sga \