]> xenbits.xensource.com Git - people/dariof/osstest.git/commitdiff
ts-freebsd-install: add FreeBSD PVHVM installer
authorRoger Pau Monne <roger.pau@citrix.com>
Thu, 21 Nov 2013 11:48:14 +0000 (12:48 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 21 Nov 2013 18:26:32 +0000 (18:26 +0000)
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
ts-freebsd-install [new file with mode: 0644]

diff --git a/ts-freebsd-install b/ts-freebsd-install
new file mode 100644 (file)
index 0000000..4e32b6c
--- /dev/null
@@ -0,0 +1,109 @@
+#!/usr/bin/perl -w
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2009-2013 Citrix Inc.
+# 
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+# 
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use strict qw(vars);
+use DBI;
+use Osstest;
+use Osstest::TestSupport;
+
+tsreadconfig();
+
+our ($whhost,$gn) = @ARGV;
+$whhost ||= 'host';
+$gn ||= 'freebsd';
+
+our $ho= selecthost($whhost);
+
+our $ram_mb=   1024;
+our $disk_mb= 20480;
+
+our $guesthost= "$gn.guest.osstest";
+our $gho;
+
+our $xl= toolstack()->{Command};
+
+our $freebsd_qcow2= '/root/freebsd.qcow2';
+our $freebsd_raw= '/root/freebsd.raw';
+
+our $freebsd_mount= '/root/freebsd_root';
+
+our $freebsd_version= "10.0-BETA3";
+
+# Folder where the FreeBSD VM images are stored inside of the host
+#
+# The naming convention of the stored images is:
+# FreeBSD-$freebsd_version-$arch.qcow2.xz
+# ie: FreeBSD-10.0-BETA3-amd64.qcow2.xz
+our $freebsd_vm_repo= '/var/images';
+
+sub prep () {
+    my $authkeys= authorized_keys();
+
+    target_install_packages_norec($ho, qw(lvm2 wget qemu-utils xz-utils kpartx));
+
+    $gho= prepareguest($ho, $gn, $guesthost, 22,
+                       $disk_mb + 1,
+                       100);
+
+    more_prepareguest_hvm($ho, $gho, $ram_mb, $disk_mb, NoCdromImage => 1);
+
+    my $freebsd_img = $freebsd_vm_repo . "/" . "FreeBSD-" . $freebsd_version . "-";
+    # Use amd64 as default arch
+    $freebsd_img .= defined($r{"$gho->{Guest}_arch"}) ? $r{"$gho->{Guest}_arch"} : 'amd64';
+    $freebsd_img .= ".qcow2.xz";
+
+    target_cmd_root($ho, "umount $gho->{Lvdev} ||:");
+
+    target_cmd_root($ho, <<END, 900);
+            xz -dkc $freebsd_img > $freebsd_qcow2
+            qemu-img convert -f qcow2 $freebsd_qcow2 -O raw $freebsd_raw
+            rm -rf $freebsd_qcow2
+            dd if=$freebsd_raw of=$gho->{Lvdev} bs=1M
+            rm -rf $freebsd_raw
+
+            kpartx -a $gho->{Lvdev}
+            mkdir -p $freebsd_mount
+            mount -t ufs -o ufstype=ufs2,rw /dev/mapper/$gho->{Vg}-$gho->{Name}--disk3 $freebsd_mount
+
+            mkdir -p $freebsd_mount/root/.ssh
+            cat <<'ENDKEYS' >$freebsd_mount/root/.ssh/authorized_keys
+$authkeys
+ENDKEYS
+
+            echo 'sshd_enable="YES"' >> $freebsd_mount/etc/rc.conf
+            echo 'ifconfig_xn0="DHCP"' >> $freebsd_mount/etc/rc.conf
+            echo 'PermitRootLogin yes' >> $freebsd_mount/etc/ssh/sshd_config
+
+            sed -i '/^ttyu0/s/off/on/' $freebsd_mount/etc/ttys
+
+            cp $freebsd_mount/usr/share/zoneinfo/Europe/London $freebsd_mount/etc/localtime
+
+            cat <<'ENDKEYS' >$freebsd_mount/boot/loader.conf
+boot_multicons="YES"
+boot_serial="YES"
+comconsole_speed="115200"
+console="comconsole,vidconsole"
+ENDKEYS
+
+            umount $freebsd_mount
+            rm -rf $freebsd_mount
+            kpartx -d $gho->{Lvdev}
+END
+
+}
+
+prep();