[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC 2/4] osstest: add support for installing bare metal FreeBSD



This is done using mfsBSD, which can be booted from pxelinux and
contains a script to automatically install FreeBSD using ZFS on root.
After the install the host is set to boot from the local disk.

Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx>
Cc: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 ts-freebsd-host-install |  150 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 150 insertions(+), 0 deletions(-)
 create mode 100755 ts-freebsd-host-install

diff --git a/ts-freebsd-host-install b/ts-freebsd-host-install
new file mode 100755
index 0000000..1a702df
--- /dev/null
+++ b/ts-freebsd-host-install
@@ -0,0 +1,150 @@
+#!/usr/bin/perl -w
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2009-2014 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 POSIX;
+
+use Osstest;
+use Osstest::TestSupport;
+use Osstest::Logtailer;
+
+tsreadconfig();
+
+our ($whhost) = @ARGV;
+$whhost ||= 'host';
+our $ho= selecthost($whhost);
+exit 0 if $ho->{Flags}{'no-reinstall'};
+exit 0 if $ho->{SharedReady};
+
+our %timeout= qw(ReadPreseed  350
+                 Sshd        2400);
+
+# TODO: all this should be runvars
+our $version = '10.0-RELEASE';
+our $ftp = 'ftp.freebsd.org';
+
+# TODO: this has to be set on a per-host basis.
+# It should probably come from $ho?
+our $disk = 'da0';
+our $nic = 'bce0';
+
+sub install () {
+    my $authkeys= authorized_keys();
+
+    power_state($ho, 0);
+
+    setup_pxeboot_firstboot();
+
+    logm('Booting into mfsBSD');
+
+    sleep(power_cycle_time($ho));
+
+    power_state($ho, 1);
+
+    logm('Waiting for host to boot');
+    await_tcp(get_timeout($ho,'boot',$timeout{Sshd}), 22, $ho);
+
+    logm('Setting host to boot from local disk on next boot');
+    setup_pxeboot_local($ho);
+
+    logm('Setting up ssh keys for remote access');
+    target_cmd_root_with_password($ho, <<END, 900, "root");
+        mkdir -p ~/.ssh
+        cat <<ENDKEYS >~/.ssh/authorized_keys
+$authkeys
+ENDKEYS
+END
+
+    logm('Install of base system using ZFS on root');
+    target_cmd_root($ho, <<END,2400);
+            gpart destroy -F $disk
+            zfsinstall -d $disk -u 
ftp://$ftp/pub/FreeBSD/releases/$r{arch}/$version -s 4g
+END
+
+    logm('Setting up ssh and keys for the installed system');
+    target_cmd_root($ho, <<END, 900);
+            echo 'sshd_enable="YES"' >> /mnt/etc/rc.conf
+            echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config
+            mkdir -p /mnt/root/.ssh
+            cat <<ENDKEYS >/mnt/root/.ssh/authorized_keys
+$authkeys
+ENDKEYS
+END
+
+    logm('Setting up serial console');
+    target_cmd_root($ho, <<END, 900);
+            echo "-Dh" >> /mnt/boot.config
+            cat <<ENDB >>/mnt/boot/loader.conf
+boot_multicons="YES"
+boot_serial="YES"
+comconsole_speed="$c{Baud}"
+console="comconsole,vidconsole"
+boot_verbose="YES"
+ENDB
+END
+
+    logm('Setting up network');
+    target_cmd_root($ho, <<END, 900);
+            echo 'cloned_interfaces="bridge0"' >> /mnt/etc/rc.conf
+            echo 'ifconfig_bridge0="addm $nic up"' >> /mnt/etc/rc.conf
+            echo 'ifconfig_$nic="DHCP"' >> /mnt/etc/rc.conf
+END
+
+    logm('Setting up miscellaneous settings');
+    target_cmd_root($ho, <<END, 900);
+            cp /mnt/usr/share/zoneinfo/Europe/London /mnt/etc/localtime
+            echo 'sendmail_enable="NONE"' >> /mnt/etc/rc.conf
+END
+
+    logm('Rebooting into the installed system');
+    target_reboot($ho);
+
+    # Remove the known hosts file, since the keys will be regenerated after
+    # rebooting into the installed system
+    unlink "tmp/t.known_hosts_$flight.$job";
+
+    logm('Adding osstest user');
+    target_cmd_root($ho, 'pw useradd osstest -m', 900);
+    target_cmd_root($ho, <<END, 900);
+            mkdir -p /home/osstest/.ssh
+            cat <<ENDKEYS >/home/osstest/.ssh/authorized_keys
+$authkeys
+ENDKEYS
+END
+
+    logm('OK: install completed');
+}
+
+sub setup_pxeboot_firstboot() {
+    my $mfs= 
'freebsd/'.$version.'/'.$r{arch}.'/'.'mfsbsd-'.$version.'-'.$r{arch}.'.img';
+
+    logm('Using mfsBSD image: ' . $mfs);
+
+    setup_pxeboot($ho, <<END);
+serial 0 $c{Baud}
+timeout 5
+label overwrite
+       menu label ^Overwrite
+       menu default
+       kernel memdisk
+       append initrd=$mfs
+default overwrite
+END
+}
+
+install();
-- 
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.