xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v6 12/20] osstest: introduce a FreeBSD build script
Date: Mon, 24 Jul 2017 12:07:51 +0100	[thread overview]
Message-ID: <20170724110759.2638-13-roger.pau@citrix.com> (raw)
In-Reply-To: <20170724110759.2638-1-roger.pau@citrix.com>

In order to generate the FreeBSD installer image and the install
media.

The install sets are the vanilla ones generated by the 'ftp' release
target.  The installer image is handcrafted based on the filesystem
created by the 'bootonly' target, which is then populated with the ssh
host keys, and setup in order to use the serial console. The other
difference from upstream FreeBSD installer images is that the one
built by osstest uses a ramdisk instead of relying on the installer
media to be somehow attached, either on a CD or USB drive. This is
required in order to boot the image from pxelinux (where no CD or USB
is actually attached to the host, and everything is fetched from
tftp).

Due to the nature of the FreeBSD build, the outputs are different from
what osstest expects from a buildjob, more specifically
path_freebsddist points to a folder that contains the several outputs
form this buildjob.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
Changes since v4:
 - Remove some useless comments.
 - Use qw(git) instead of 'git'.
 - Replace unicode nonbreaking space.
 - Remove trail ','.
 - Improve the way to fetch the version number.

Changes since v3:
 - Introduce two helpers to perform the build process.
 - Install packages using target_install_packages.

Changes since v2:
 - Increase build target timeouts.
 - Use sysrc instead echo to set rc.conf options.

Changes since v1:
 - Remove the ts-build-check FreeBSD hack.
 - Use pkg-static instead of pkg.
 - Introduce buildcmd_stamped_logged_root and target_cmd_build_root.
 - Use target_cmd_build_root and buildcmd_stamped_logged_root in the
   ts-freebsd-build script.
 - Fix the script snippets to use <<END.<<'END' in order to avoid
   escaping the shell variables.
 - Set path_freebsddist runvar to point to the folder where the build
   files are stashed.
 - Add a comment at the top of the file describing what runvars are
   consumed/produced by the build script.
---
 ts-freebsd-build | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 239 insertions(+)
 create mode 100755 ts-freebsd-build

diff --git a/ts-freebsd-build b/ts-freebsd-build
new file mode 100755
index 00000000..00885636
--- /dev/null
+++ b/ts-freebsd-build
@@ -0,0 +1,239 @@
+#!/usr/bin/perl -w
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2017 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/>.
+
+# Consumes the following input runvars:
+#
+# revision_freebsd: FreeBSD commit ID to generate the install media from.
+# tree_freebsd: FreeBSD git tree to fetch the source code from.
+#
+# Produces the following output:
+#
+# Compressed install sets: kernel.txz, base.txz
+# Compressed debug symbols for the kernel: kernel-dbg.txz
+# Manifest file (checkums): MANIFEST
+# Installer image: install.img
+#
+# Sets the following runvar:
+#
+# path_freebsddist: points to the folder where the above files are stored.
+# freebsd_buildversion: version of FreeBSD built.
+
+use strict qw(vars);
+use DBI;
+use POSIX;
+
+unshift @INC, qw(.);
+use Osstest;
+use Osstest::TestSupport;
+use Osstest::BuildSupport;
+
+tsreadconfig();
+
+selectbuildhost(\@ARGV);
+builddirsprops();
+
+sub install_deps () {
+    target_install_packages($ho, qw(git));
+}
+
+sub checkout () {
+    prepbuilddirs();
+
+    # Remove the directory as root, there might be files owned by root
+    target_cmd_build_root($ho, 300, $builddir, <<'END');
+# chflags will return error if the directory doesn't exist
+chflags -fR noschg freebsd || true
+rm -rf freebsd
+END
+
+    logm("Checkout the FreeBSD source tree");
+    build_clone($ho, 'freebsd', $builddir, 'freebsd');
+}
+
+sub build_target($$$) {
+    my ($target, $prefix, $time) = @_;
+
+    buildcmd_stamped_logged($time, 'freebsd', $target,
+                            $prefix, <<END, '');
+make $makeflags $target
+END
+}
+
+sub build_release($$$) {
+    my ($target, $prefix, $time) = @_;
+
+    buildcmd_stamped_logged_root($time, 'freebsd', "release-$target",
+                                 $prefix, <<END, '');
+make -C release $target
+END
+}
+
+sub build () {
+    my $authkeys = authorized_keys();
+    my $target = "bootonly";
+    my $prefix = <<END;
+export MAKEOBJDIRPREFIX=$builddir/obj
+export TARGET=$r{arch}
+END
+
+    # Build process as documented in the handbook:
+    # https://www.freebsd.org/doc/handbook/updating-src.html
+
+    logm("Cleaning up previous builds");
+    build_target('cleanworld', $prefix, 300);
+
+    logm("Building world");
+    build_target('buildworld', $prefix, 25200);
+
+    logm("Building kernel");
+    build_target('buildkernel', $prefix, 3600);
+
+    # NB: the steps below need to be done as root or the permissions
+    # of the files won't be properly set (and the target will fail).
+    logm("Creating the install sets");
+    build_release('ftp', $prefix, 3600);
+
+    logm("Populating the installer image");
+    build_release($target, $prefix, 3600);
+
+    logm("Placing ssh host keys");
+    foreach my $file (<$c{OverlayLocal}/etc/ssh/ssh_host_*_key*>) {
+        target_putfile_root($ho, 30, $file,
+                            "$builddir/freebsd/release/$target/etc/ssh/");
+    }
+
+    logm("Configuring the installer image");
+    target_cmd_build_root($ho, 30, $builddir, <<END.<<'END');
+authkeys="$authkeys"
+bauds="$c{Baud}"
+cd freebsd/release/$target
+END
+sysrc -f etc/rc.conf sshd_enable=YES
+
+echo 'PermitRootLogin yes' >> etc/ssh/sshd_config
+mkdir -p root/.ssh
+cat << ENDKEYS > root/.ssh/authorized_keys
+$authkeys
+ENDKEYS
+
+chown root:wheel etc/ssh/ssh_host_*_key*
+chmod 0600 etc/ssh/ssh_host_*_key
+chmod 0644 etc/ssh/ssh_host_*_key.pub
+
+# Setup serial console output for stage1
+printf "%s" "-h -S$bauds" >> boot.config
+cat << ENDBOOT >> boot/loader.conf
+# Serial console configuration
+boot_serial="YES"
+comconsole_speed="$bauds"
+console="comconsole"
+boot_verbose="YES"
+beastie_disable="YES"
+
+# mfs boot parameters
+mfs_load="YES"
+mfs_type="mfs_root"
+mfs_name="/mfsroot"
+vfs.root.mountfrom="ufs:/dev/ufs/FreeBSD_Install"
+ENDBOOT
+
+sysrc -f etc/rc.conf ifconfig_DEFAULT=DHCP
+
+# Remove the local script that launches the installer by default
+rm -rf etc/rc.local
+
+# Create a temporary fstab with the root dir
+echo '/dev/ufs/FreeBSD_Install / ufs rw 1 1' > etc/fstab
+
+# Remove the linked resolv.conf
+rm -rf etc/resolv.conf
+END
+
+    logm("Create the installer");
+    target_cmd_build_root($ho, 900, $builddir, <<END.<<'END');
+target="freebsd/release/$target"
+output="install.img"
+END
+mkdir -p $output.tmp
+
+# Do some pruning
+rm -rf $target/usr/share/man
+rm -rf $target/usr/share/examples
+rm -rf $target/usr/share/doc
+rm -rf $target/usr/share/dtrace
+
+# Create a mfs root image
+makefs -b 10% -B little -o label=FreeBSD_Install $output.tmp/mfsroot $target
+gzip $output.tmp/mfsroot
+
+# Copy boot to the staging dir
+cp -r $target/boot $output.tmp/
+cp $target/boot.config $output.tmp/
+
+# The loader doesn't need any modules in order to boot into the mfsroot.
+# The rest of the modules can be loaded from the mfs root itself.
+rm -f $output.tmp/boot/kernel/*.ko
+
+gzip $output.tmp/boot/kernel/kernel
+
+makefs -B little $output.part $output.tmp
+
+mkimg -s gpt -b $target/boot/pmbr -p efi:=$target/boot/boot1.efifat \
+    -p freebsd-boot:=$target/boot/gptboot -p freebsd-ufs:=$output.part \
+    -p freebsd-swap::1M -o $output
+
+rm $output.part
+rm -rf $output.tmp
+END
+}
+
+sub stash () {
+    my @sets = qw(MANIFEST base.txz kernel.txz);
+    my @symbols = qw(kernel-dbg.txz);
+
+    logm("Stashing FreeBSD build output");
+    foreach my $set (@sets) {
+        built_stash_file($ho, $builddir, $set,
+                         "freebsd/release/ftp/$set", 0);
+    }
+    foreach my $symbol (@symbols) {
+        built_stash_debugfile($ho, $builddir, $symbol,
+                              "freebsd/release/ftp/$symbol", 0);
+    }
+    built_stash_file($ho, $builddir, "install.img", "install.img", 0);
+
+    my $srcversion = target_cmd_output_root($ho, <<END, 30);
+set -e
+cd $builddir/freebsd
+eval `make buildenvvars`
+test -n "\$SRCRELDATE"
+expr "\$SRCRELDATE" / 100000
+END
+    store_runvar("freebsd_buildversion", "$srcversion");
+
+    # Set path_freebsddist to point to the build output folder
+    # in order to make ts-build-check happy.
+    store_runvar("path_freebsddist", "build/");
+}
+
+install_deps();
+checkout();
+build();
+stash();
+
+logm("FreeBSD build successful");
+
-- 
2.11.0 (Apple Git-81)


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

  parent reply	other threads:[~2017-07-24 11:12 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-24 11:07 [PATCH v6 00/20] osstest: initial FreeBSD support Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 01/20] osstest: make built_stash_file store a path_ runvar for each file Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 02/20] osstest: move known_hosts generation to TestSupport Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 03/20] osstest: introduce helper to get per-host tftp prefix Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 04/20] osstest: introduce a helper to calculate the sha256 of a given file Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 05/20] osstest: introduce a helper to setup a host to boot using memdisk Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 06/20] osstest: add executive prefix to resource_shared_mark_ready Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 07/20] osstest: introduce resource_shared_mark_ready Roger Pau Monne
2017-10-27 16:19   ` Ian Jackson
2017-07-24 11:07 ` [PATCH v6 08/20] osstest: add a FreeBSD host install script Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 09/20] osstest: introduce build helpers for FreeBSD Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 10/20] osstest: add prototypes to target_install_packages{_norec} Roger Pau Monne
2017-07-25 13:20   ` Ian Jackson
2017-07-24 11:07 ` [PATCH v6 11/20] osstest: add support for the FreeBSD package manager Roger Pau Monne
2017-07-24 11:07 ` Roger Pau Monne [this message]
2017-07-24 11:07 ` [PATCH v6 13/20] osstest: add support for runtime_IDENT_hostflags Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 14/20] osstest: introduce a script to set the runtime hostflags runvar for FreeBSD jobs Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 15/20] osstest: change the meaning of need_build_host Roger Pau Monne
2017-07-24 15:28   ` Ian Jackson
2017-07-24 11:07 ` [PATCH v6 16/20] osstest: add support for FreeBSD buildjobs to sg-run-job Roger Pau Monne
2017-07-24 15:29   ` Ian Jackson
2017-07-24 11:07 ` [PATCH v6 17/20] osstest: introduce a script to create a FreeBSD flight Roger Pau Monne
2017-07-24 15:38   ` Ian Jackson
2017-07-24 15:45     ` Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 18/20] osstest: hook FreeBSD flight into cr-daily-branch Roger Pau Monne
2017-07-24 15:44   ` Ian Jackson
2017-07-24 16:03     ` Roger Pau Monne
2017-07-24 16:13       ` Ian Jackson
2017-07-25  7:17         ` Roger Pau Monne
2017-07-24 11:07 ` [PATCH v6 19/20] osstest: save/retrieve the last successfully tested FreeBSD build Roger Pau Monne
2017-07-24 15:56   ` Ian Jackson
2017-07-25  7:56     ` Roger Pau Monne
2017-07-25 10:24       ` Ian Jackson
2017-07-25 12:06         ` Roger Pau Monne
2017-07-25 13:21           ` Ian Jackson
2017-07-24 11:07 ` [PATCH v6 20/20] osstest: add anoint dummy script Roger Pau Monne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170724110759.2638-13-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).