From owner-svn-src-all@freebsd.org Fri Dec 15 06:34:13 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 28F0EE9D02C; Fri, 15 Dec 2017 06:34:13 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0041169D1E; Fri, 15 Dec 2017 06:34:12 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBF6YC8n023908; Fri, 15 Dec 2017 06:34:12 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBF6YCIw023907; Fri, 15 Dec 2017 06:34:12 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201712150634.vBF6YCIw023907@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Fri, 15 Dec 2017 06:34:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326873 - head/tools/boot X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/tools/boot X-SVN-Commit-Revision: 326873 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Dec 2017 06:34:13 -0000 Author: imp Date: Fri Dec 15 06:34:11 2017 New Revision: 326873 URL: https://svnweb.freebsd.org/changeset/base/326873 Log: Script that knows how to put boot blocks onto a device. Eventually, this will be installed into /usr/sbin, but for now it's just used for the boot loader regression script. It's still a bit green, and likely will get edge cases wrong still. It's also x86 centric at the moment, but will be enhanced shortly for u-boot, CHRP PowerPC and other methods. Sponsored by: Netflix Added: head/tools/boot/install-boot.sh (contents, props changed) Added: head/tools/boot/install-boot.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/boot/install-boot.sh Fri Dec 15 06:34:11 2017 (r326873) @@ -0,0 +1,128 @@ +#!/bin/sh + +# $FreeBSD$ + +# +# Installs/updates the necessary boot blocks for the desired boot environment +# +# Lightly tested.. Intended to be installed, but until it matures, it will just +# be a boot tool for regression testing. + +# insert code here to guess what you have -- yikes! + +die() { + echo $* + exit 1 +} + +find-part() { + dev=$1 + part=$2 + + gpart show $dev | tail +2 | awk '$4 == "'$part'" { print $3; }' +} + +boot_nogeli_gpt_zfs_legacy() { + dev=$1 + dst=$2 + + idx=$(find-part $dev "freebsd-boot") + if [ -z "$idx" ] ; then + die "No freebsd-boot partition found" + fi + gpart bootcode -b ${gpt0} -p ${gpt2} -i $idx $dev + exit 0 +} + +boot_nogeli_gpt_ufs_legacy() { + dev=$1 + dst=$2 + + idx=$(find-part $dev "freebsd-boot") + if [ -z "$idx" ] ; then + die "No freebsd-boot partition found" + fi + gpart bootcode -b ${gpt0} -p ${gpt2} -i $idx $dev + exit 0 +} + +boot_nogeli_mbr_zfs_legacy() { + dev=$1 + dst=$2 + + # search to find the BSD slice + s=$(findpart $dev "freebsd-zfs") + if [ -z "$s" ] ; then + die "No freebsd-zfs slice found" + fi + # search to find the freebsd-zfs partition within the slice + # Or just assume it is 'a' because it has to be since it fails otherwise + dd if=${dst}/boot/zfsboot of=/tmp/zfsboot1 count=1 + gpart bootcode -b /tmp/zfsboo1 ${dev}s${s} # Put boot1 into the start of part + sysctl kern.geom.debugflags=0x10 + dd if=${dst}/boot/zfsboot iseek=1 seek=1024 # Put boot2 into ZFS boot slot + sysctl kern.geom.debugflags=0x0 + + exit 0 +} + +boot_nogeli_mbr_ufs_legacy() { + dev=$1 + dst=$2 + + gpart bootcode -b ${mbr0} ${dev} + s=$(findpart $dev "freebsd-ufs") + if [ -z "$s" ] ; then + die "No freebsd-zfs slice found" + fi + gpart bootcode -p ${mbr2} ${dev}s${s} + exit 0 +} + +DESTDIR=/ + +# Note: we really don't support geli boot in this script yet. +geli=nogeli + +while getopts "b:d:f:g:o:s:" opt; do + case "$opt" in + b) + bios=${OPTARG} + ;; + d) + DESTDIR=${OPTARG} + ;; + f) + fs=${OPTARG} + ;; + g) + case ${OPTARG} in + [Yy][Ee][Ss]|geli) geli=geli ;; + *) geli=nogeli ;; + esac + ;; + o) + opts=${OPTARG} + ;; + s) + scheme=${OPTARG} + ;; + esac +done + +shift $((OPTIND-1)) +dev=$1 + +# For gpt, we need to install pmbr as the primary boot loader +# it knows about +gpt0=${DESTDIR}/boot/pmbr +gpt2=${DESTDIR}/boot/gptboot +gptzfs2=${DESTDIR}/boot/gptzfsboot + +# For MBR, we have lots of choices, but select boot0 +mbr0=${DESTDIR}/boot/boot0 +mbr2=${DESTDIR}/boot/boot + +# sanity check here + +eval boot_${geli}_${scheme}_${fs}_${bios} $dev $DESTDIR $opts || echo "Unsupported boot env: ${geli}-${scheme}-${fs}-${bios}"