Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Jun 2018 05:55:32 +0000 (UTC)
From:      Allan Jude <allanjude@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r335279 - head/tools/boot
Message-ID:  <201806170555.w5H5tWn8071168@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: allanjude
Date: Sun Jun 17 05:55:31 2018
New Revision: 335279
URL: https://svnweb.freebsd.org/changeset/base/335279

Log:
  rootgen.sh: complete all profiles except GELI+MBR (not supported)
  
  This extends the test suite to generate images for every combination of:
  amd64: mbr/gpt geli/nogeli ufs/zfs legacy/uefi/both
  
  Except for mbr+geli, which is not currently possible.
  
  Reviewed by:	imp (previous version)
  Sponsored by:	Klara Systems
  Differential Revision:	https://reviews.freebsd.org/D15846

Modified:
  head/tools/boot/install-boot.sh
  head/tools/boot/rootgen.sh

Modified: head/tools/boot/install-boot.sh
==============================================================================
--- head/tools/boot/install-boot.sh	Sun Jun 17 05:14:50 2018	(r335278)
+++ head/tools/boot/install-boot.sh	Sun Jun 17 05:55:31 2018	(r335279)
@@ -27,7 +27,7 @@ find-part() {
     gpart show $dev | tail +2 | awk '$4 == "'$part'" { print $3; }'
 }
 
-boot_nogeli_gpt_zfs_legacy() {
+boot_nogeli_gpt_ufs_legacy() {
     dev=$1
     dst=$2
 
@@ -35,20 +35,34 @@ boot_nogeli_gpt_zfs_legacy() {
     if [ -z "$idx" ] ; then
 	die "No freebsd-boot partition found"
     fi
-    doit gpart bootcode -b ${gpt0} -p ${gptzfs2} -i $idx $dev
-    exit 0
+    doit gpart bootcode -b ${gpt0} -p ${gpt2} -i $idx $dev
 }
 
-boot_nogeli_gpt_ufs_legacy() {
+boot_nogeli_gpt_ufs_uefi() {
     dev=$1
     dst=$2
 
+    idx=$(find-part $dev "efi")
+    if [ -z "$idx" ] ; then
+	die "No ESP partition found"
+    fi
+    doit gpart bootcode -p ${efi2} -i $idx $dev
+}
+
+boot_nogeli_gpt_ufs_both() {
+    boot_nogeli_gpt_ufs_legacy $1 $2 $3
+    boot_nogeli_gpt_ufs_uefi $1 $2 $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
-    doit gpart bootcode -b ${gpt0} -p ${gpt2} -i $idx $dev
-    exit 0
+    doit gpart bootcode -b ${gpt0} -p ${gptzfs2} -i $idx $dev
 }
 
 boot_nogeli_gpt_zfs_uefi() {
@@ -57,64 +71,132 @@ boot_nogeli_gpt_zfs_uefi() {
 
     idx=$(find-part $dev "efi")
     if [ -z "$idx" ] ; then
-	die "No efi ESP partition found"
+	die "No ESP partition found"
     fi
     doit gpart bootcode -p ${efi2} -i $idx $dev
-    exit 0
 }
 
 boot_nogeli_gpt_zfs_both() {
+    boot_nogeli_gpt_zfs_legacy $1 $2 $3
+    boot_nogeli_gpt_zfs_uefi $1 $2 $3
+}
+
+boot_nogeli_mbr_ufs_legacy() {
     dev=$1
     dst=$2
 
-    # XXX: Should this be copy/pasted, or should it call both _uefi and _legacy
-    idx=$(find-part $dev "efi")
-    if [ -z "$idx" ] ; then
-	die "No efi ESP partition found"
+    doit gpart bootcode -b ${mbr0} ${dev}
+    s=$(find-part $dev "freebsd")
+    if [ -z "$s" ] ; then
+	die "No freebsd slice found"
     fi
-    doit gpart bootcode -p ${efi2} -i $idx $dev
+    doit gpart bootcode -p ${mbr2} ${dev}s${s}
+}
 
-    idx=$(find-part $dev "freebsd-boot")
-    if [ -z "$idx" ] ; then
-	die "No freebsd-boot partition found"
+boot_nogeli_mbr_ufs_uefi() {
+    dev=$1
+    dst=$2
+
+    s=$(find-part ${dev} "!239")
+    if [ -z "$s" ] ; then
+	die "No ESP slice found"
     fi
-    doit gpart bootcode -b ${gpt0} -p ${gptzfs2} -i $idx $dev
-    exit 0
+    doit gpart bootcode -p ${efi2} -i ${s} ${dev}
 }
 
+boot_nogeli_mbr_ufs_both() {
+    boot_nogeli_mbr_ufs_legacy $1 $2 $3
+    boot_nogeli_mbr_ufs_uefi $1 $2 $3
+}
+
 boot_nogeli_mbr_zfs_legacy() {
     dev=$1
     dst=$2
 
     # search to find the BSD slice
-    s=$(findpart $dev "freebsd-zfs")
+    s=$(find-part $dev "freebsd")
     if [ -z "$s" ] ; then
+	die "No BSD slice found"
+    fi
+    idx=$(find-part ${dev}s${s} "freebsd-zfs")
+    if [ -z "$idx" ] ; 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
+    doit gpart bootcode -b ${dst}/boot/mbr ${dev}
     dd if=${dst}/boot/zfsboot of=/tmp/zfsboot1 count=1
-    doit gpart bootcode -b /tmp/zfsboo1 ${dev}s${s}	# Put boot1 into the start of part
+    doit gpart bootcode -b /tmp/zfsboot1 ${dev}s${s}	# Put boot1 into the start of part
     sysctl kern.geom.debugflags=0x10		# Put boot2 into ZFS boot slot
-    doit dd if=${dst}/boot/zfsboot of=/dev/${dev}s${s} iseek=1 seek=1024
+    doit dd if=${dst}/boot/zfsboot of=/dev/${dev}s${s}a skip=1 seek=1024
     sysctl kern.geom.debugflags=0x0
-
-    exit 0
 }
 
-boot_nogeli_mbr_ufs_legacy() {
+boot_nogeli_mbr_zfs_uefi() {
     dev=$1
     dst=$2
 
-    doit gpart bootcode -b ${mbr0} ${dev}
-    s=$(findpart $dev "freebsd-ufs")
+    s=$(find-part $dev "!239")
     if [ -z "$s" ] ; then
-	die "No freebsd-ufs slice found"
+	die "No ESP slice found"
     fi
-    doit gpart bootcode -p ${mbr2} ${dev}s${s}
-    exit 0
+    doit gpart bootcode -p ${efi2} -i ${s} ${dev}
 }
 
+boot_nogeli_mbr_zfs_both() {
+    boot_nogeli_mbr_zfs_legacy $1 $2 $3
+    boot_nogeli_mbr_zfs_uefi $1 $2 $3
+}
+
+boot_geli_gpt_ufs_legacy() {
+    boot_nogeli_gpt_ufs_legacy $1 $2 $3
+}
+
+boot_geli_gpt_ufs_uefi() {
+    boot_nogeli_gpt_ufs_uefi $1 $2 $3
+}
+
+boot_geli_gpt_ufs_both() {
+    boot_nogeli_gpt_ufs_both $1 $2 $3
+}
+
+boot_geli_gpt_zfs_legacy() {
+    boot_nogeli_gpt_zfs_legacy $1 $2 $3
+}
+
+boot_geli_gpt_zfs_uefi() {
+    boot_nogeli_gpt_zfs_uefi $1 $2 $3
+}
+
+boot_geli_gpt_zfs_both() {
+    boot_nogeli_gpt_zfs_both $1 $2 $3
+}
+
+# GELI+MBR is not a valid configuration
+boot_geli_mbr_ufs_legacy() {
+    exit 1
+}
+
+boot_geli_mbr_ufs_uefi() {
+    exit 1
+}
+
+boot_geli_mbr_ufs_both() {
+    exit 1
+}
+
+boot_geli_mbr_zfs_legacy() {
+    exit 1
+}
+
+boot_geli_mbr_zfs_uefi() {
+    exit 1
+}
+
+boot_geli_mbr_zfs_both() {
+    exit 1
+}
+
 boot_nogeli_vtoc8_ufs_ofw() {
     dev=$1
     dst=$2
@@ -122,7 +204,6 @@ boot_nogeli_vtoc8_ufs_ofw() {
     # For non-native builds, ensure that geom_part(4) supports VTOC8.
     kldload geom_part_vtoc8.ko
     doit gpart bootcode -p ${vtoc8} ${dev}
-    exit 0
 }
 
 DESTDIR=/
@@ -166,11 +247,12 @@ gpt2=${DESTDIR}/boot/gptboot
 gptzfs2=${DESTDIR}/boot/gptzfsboot
 
 # For gpt + EFI we install the ESP
-# XXX This should use newfs or makefs, but it deosn't yet
+# XXX This should use newfs or makefs, but it doesn't yet
+efi1=${DESTDIR}/boot/boot1.efi
 efi2=${DESTDIR}/boot/boot1.efifat
 
-# For MBR, we have lots of choices, but select boot0
-mbr0=${DESTDIR}/boot/boot0
+# For MBR, we have lots of choices, but select mbr, boot0 has issues with UEFI
+mbr0=${DESTDIR}/boot/mbr
 mbr2=${DESTDIR}/boot/boot
 
 # VTOC8

Modified: head/tools/boot/rootgen.sh
==============================================================================
--- head/tools/boot/rootgen.sh	Sun Jun 17 05:14:50 2018	(r335278)
+++ head/tools/boot/rootgen.sh	Sun Jun 17 05:55:31 2018	(r335279)
@@ -51,9 +51,9 @@ mk_nogeli_gpt_ufs_uefi() {
 /dev/ada0p2	/		ufs	rw	1	1
 EOF
 # XXX need to make msdos part for this to work XXXX
-    cp ${src}/boot/boot.efifat ${img}.p1
+    cp ${src}/boot/boot1.efifat ${img}.p1
     makefs -t ffs -B little -s 200m ${img}.p2 ${src}
-    mkimg -s gpt -b ${src}/boot/pmbr \
+    mkimg -s gpt \
 	  -p efi:=${img}.p1 \
 	  -p freebsd-ufs:=${img}.p2 -o ${img}
     rm -f ${src}/etc/fstab
@@ -67,7 +67,7 @@ mk_nogeli_gpt_ufs_both() {
 /dev/ada0p3	/		ufs	rw	1	1
 EOF
     # XXX need to make msdos part for this to work XXXX
-    cp ${src}/boot/boot.efifat ${img}.p1
+    cp ${src}/boot/boot1.efifat ${img}.p1
     makefs -t ffs -B little -s 200m ${img}.p3 ${src}
     # p1 is boot for uefi, p2 is boot for gpt, p3 is /
     mkimg -b ${src}/boot/pmbr -s gpt \
@@ -99,7 +99,6 @@ mk_nogeli_gpt_zfs_legacy() {
     zfs create -po mountpoint=/ ${pool}/ROOT/default
     # NB: The online guides go nuts customizing /var and other mountpoints here, no need
     cpsys ${src} ${mntpt}
-    df
     # need to make a couple of tweaks
     cat > ${mntpt}/boot/loader.conf <<EOF
 zfs_load=YES
@@ -107,7 +106,6 @@ opensolaris_load=YES
 EOF
     cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
     cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
-    ls -las ${mntpt}/boot
     # end tweaks
     zfs umount -f ${pool}/ROOT/default
     zfs set mountpoint=none ${pool}/ROOT/default
@@ -139,7 +137,6 @@ mk_nogeli_gpt_zfs_uefi() {
     zfs create -po mountpoint=/ ${pool}/ROOT/default
     # NB: The online guides go nuts customizing /var and other mountpoints here, no need
     cpsys ${src} ${mntpt}
-    df
     # need to make a couple of tweaks
     cat > ${mntpt}/boot/loader.conf <<EOF
 zfs_load=YES
@@ -147,7 +144,6 @@ opensolaris_load=YES
 EOF
     cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
     cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
-    ls -las ${mntpt}/boot
     # end tweaks
     zfs umount -f ${pool}/ROOT/default
     zfs set mountpoint=none ${pool}/ROOT/default
@@ -180,7 +176,6 @@ mk_nogeli_gpt_zfs_both() {
     zfs create -po mountpoint=/ ${pool}/ROOT/default
     # NB: The online guides go nuts customizing /var and other mountpoints here, no need
     cpsys ${src} ${mntpt}
-    df
     # need to make a couple of tweaks
     cat > ${mntpt}/boot/loader.conf <<EOF
 zfs_load=YES
@@ -188,7 +183,6 @@ opensolaris_load=YES
 EOF
     cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
     cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
-    ls -las ${mntpt}/boot
     # end tweaks
     zfs umount -f ${pool}/ROOT/default
     zfs set mountpoint=none ${pool}/ROOT/default
@@ -208,43 +202,400 @@ mk_nogeli_mbr_ufs_legacy() {
 EOF
     makefs -t ffs -B little -s 200m ${img}.s1a ${src}
     mkimg -s bsd -b ${src}/boot/boot -p freebsd-ufs:=${img}.s1a -o ${img}.s1
-    mkimg -a 1 ${bootmbr} -s mbr -b ${src}/boot/boot0sio -p freebsd:=${img}.s1 -o ${img}
+    mkimg -a 1 -s mbr -b ${src}/boot/boot0sio -p freebsd:=${img}.s1 -o ${img}
     rm -f ${src}/etc/fstab
 }
 
 mk_nogeli_mbr_ufs_uefi() {
+    src=$1
+    img=$2
+
+    cat > ${src}/etc/fstab <<EOF
+/dev/ada0s1a	/		ufs	rw	1	1
+EOF
+    cp ${src}/boot/boot1.efifat ${img}.s1
+    makefs -t ffs -B little -s 200m ${img}.s2a ${src}
+    mkimg -s bsd -p freebsd-ufs:=${img}.s2a -o ${img}.s2
+    mkimg -a 1 -s mbr -p efi:=${img}.s1 -p freebsd:=${img}.s2 -o ${img}
+    rm -f ${src}/etc/fstab
 }
 
 mk_nogeli_mbr_ufs_both() {
+    src=$1
+    img=$2
+
+    cat > ${src}/etc/fstab <<EOF
+/dev/ada0s1a	/		ufs	rw	1	1
+EOF
+    cp ${src}/boot/boot1.efifat ${img}.s1
+    makefs -t ffs -B little -s 200m ${img}.s2a ${src}
+    mkimg -s bsd -b ${src}/boot/boot -p freebsd-ufs:=${img}.s2a -o ${img}.s2
+    mkimg -a 2 -s mbr -b ${src}/boot/mbr -p efi:=${img}.s1 -p freebsd:=${img}.s2 -o ${img}
+    rm -f ${src}/etc/fstab
 }
 
 mk_nogeli_mbr_zfs_legacy() {
+    src=$1
+    img=$2
+    mntpt=$3
+    geli=$4
+    scheme=$5
+    fs=$6
+    bios=$7
+    pool=nogeli-mbr-zfs-legacy
+
+    dd if=/dev/zero of=${img} count=1 seek=$((200 * 1024 * 1024 / 512))
+    md=$(mdconfig -f ${img})
+    gpart create -s mbr ${md}
+    gpart add -t freebsd ${md}
+    gpart set -a active -i 1 ${md}
+    gpart create -s bsd ${md}s1
+    gpart add -t freebsd-zfs ${md}s1
+    # install-boot will make this bootable
+    zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}s1a
+    zpool set bootfs=${pool} ${pool}
+    zfs create -po mountpoint=/ ${pool}/ROOT/default
+    # NB: The online guides go nuts customizing /var and other mountpoints here, no need
+    cpsys ${src} ${mntpt}
+    # need to make a couple of tweaks
+    cat > ${mntpt}/boot/loader.conf <<EOF
+zfs_load=YES
+opensolaris_load=YES
+EOF
+    cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
+    cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
+    # end tweaks
+    zfs umount -f ${pool}/ROOT/default
+    zfs set mountpoint=none ${pool}/ROOT/default
+    zpool set bootfs=${pool}/ROOT/default ${pool}
+    zpool set autoexpand=on ${pool}
+    zpool export ${pool}
+    ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md}
+    mdconfig -d -u ${md}
 }
 
 mk_nogeli_mbr_zfs_uefi() {
+    src=$1
+    img=$2
+    mntpt=$3
+    geli=$4
+    scheme=$5
+    fs=$6
+    bios=$7
+    pool=nogeli-mbr-zfs-uefi
+
+    dd if=/dev/zero of=${img} count=1 seek=$((200 * 1024 * 1024 / 512))
+    md=$(mdconfig -f ${img})
+    gpart create -s mbr ${md}
+    gpart add -t \!239 -s 800k ${md}
+    gpart add -t freebsd ${md}
+    gpart set -a active -i 2 ${md}
+    gpart create -s bsd ${md}s2
+    gpart add -t freebsd-zfs ${md}s2
+    # install-boot will make this bootable
+    zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}s2a
+    zpool set bootfs=${pool} ${pool}
+    zfs create -po mountpoint=/ ${pool}/ROOT/default
+    # NB: The online guides go nuts customizing /var and other mountpoints here, no need
+    cpsys ${src} ${mntpt}
+    # need to make a couple of tweaks
+    cat > ${mntpt}/boot/loader.conf <<EOF
+zfs_load=YES
+opensolaris_load=YES
+EOF
+    cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
+    cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
+    # end tweaks
+    zfs umount -f ${pool}/ROOT/default
+    zfs set mountpoint=none ${pool}/ROOT/default
+    zpool set bootfs=${pool}/ROOT/default ${pool}
+    zpool set autoexpand=on ${pool}
+    zpool export ${pool}
+    ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md}
+    mdconfig -d -u ${md}
 }
 
 mk_nogeli_mbr_zfs_both() {
+    src=$1
+    img=$2
+    mntpt=$3
+    geli=$4
+    scheme=$5
+    fs=$6
+    bios=$7
+    pool=nogeli-mbr-zfs-both
+
+    dd if=/dev/zero of=${img} count=1 seek=$((200 * 1024 * 1024 / 512))
+    md=$(mdconfig -f ${img})
+    gpart create -s mbr ${md}
+    gpart add -t \!239 -s 800k ${md}
+    gpart add -t freebsd ${md}
+    gpart set -a active -i 2 ${md}
+    gpart create -s bsd ${md}s2
+    gpart add -t freebsd-zfs ${md}s2
+    # install-boot will make this bootable
+    zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}s2a
+    zpool set bootfs=${pool} ${pool}
+    zfs create -po mountpoint=/ ${pool}/ROOT/default
+    # NB: The online guides go nuts customizing /var and other mountpoints here, no need
+    cpsys ${src} ${mntpt}
+    # need to make a couple of tweaks
+    cat > ${mntpt}/boot/loader.conf <<EOF
+zfs_load=YES
+opensolaris_load=YES
+EOF
+    cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
+    cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
+    # end tweaks
+    zfs umount -f ${pool}/ROOT/default
+    zfs set mountpoint=none ${pool}/ROOT/default
+    zpool set bootfs=${pool}/ROOT/default ${pool}
+    zpool set autoexpand=on ${pool}
+    zpool export ${pool}
+    ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md}
+    mdconfig -d -u ${md}
 }
 
 mk_geli_gpt_ufs_legacy() {
+    src=$1
+    img=$2
+    mntpt=$3
+    geli=$4
+    scheme=$5
+    fs=$6
+    bios=$7
+
+    dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 ))
+    md=$(mdconfig -f ${img})
+    gpart create -s gpt ${md}
+    gpart add -t freebsd-boot -s 400k -a 4k	${md}	# <= ~540k
+    gpart add -t freebsd-ufs -l root $md
+    # install-boot will make this bootable
+    echo passphrase | geli init -bg -e AES-XTS -i 50000 -J - -l 256 -s 4096 ${md}p2
+    echo passphrase | geli attach -j - ${md}p2
+    newfs /dev/${md}p2.eli
+    mount /dev/${md}p2.eli ${mntpt}
+    cpsys ${src} ${mntpt}
+    # need to make a couple of tweaks
+    cat > ${mntpt}/boot/loader.conf <<EOF
+geom_eli_load=YES
+EOF
+    cat > ${mntpt}/etc/fstab <<EOF
+/dev/ada0p2.eli	/		ufs	rw	1	1
+EOF
+
+    cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko
+    # end tweaks
+    umount -f ${mntpt}
+    geli detach ${md}p2
+    ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md}
+    mdconfig -d -u ${md}
 }
 
 mk_geli_gpt_ufs_uefi() {
+    src=$1
+    img=$2
+    mntpt=$3
+    geli=$4
+    scheme=$5
+    fs=$6
+    bios=$7
+
+    dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 ))
+    md=$(mdconfig -f ${img})
+    gpart create -s gpt ${md}
+    gpart add -t efi -s 800k -a 4k ${md}
+    gpart add -t freebsd-ufs -l root $md
+    # install-boot will make this bootable
+    echo passphrase | geli init -bg -e AES-XTS -i 50000 -J - -l 256 -s 4096 ${md}p2
+    echo passphrase | geli attach -j - ${md}p2
+    newfs /dev/${md}p2.eli
+    mount /dev/${md}p2.eli ${mntpt}
+    cpsys ${src} ${mntpt}
+    # need to make a couple of tweaks
+    cat > ${mntpt}/boot/loader.conf <<EOF
+geom_eli_load=YES
+EOF
+    cat > ${mntpt}/etc/fstab <<EOF
+/dev/ada0p2.eli	/		ufs	rw	1	1
+EOF
+
+    cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko
+    # end tweaks
+    umount -f ${mntpt}
+    geli detach ${md}p2
+    ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md}
+    mdconfig -d -u ${md}
 }
 
 mk_geli_gpt_ufs_both() {
+    src=$1
+    img=$2
+    mntpt=$3
+    geli=$4
+    scheme=$5
+    fs=$6
+    bios=$7
+
+    dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 ))
+    md=$(mdconfig -f ${img})
+    gpart create -s gpt ${md}
+    gpart add -t efi -s 800k -a 4k ${md}
+    gpart add -t freebsd-boot -s 400k -a 4k	${md}	# <= ~540k
+    gpart add -t freebsd-ufs -l root $md
+    # install-boot will make this bootable
+    echo passphrase | geli init -bg -e AES-XTS -i 50000 -J - -l 256 -s 4096 ${md}p3
+    echo passphrase | geli attach -j - ${md}p3
+    newfs /dev/${md}p3.eli
+    mount /dev/${md}p3.eli ${mntpt}
+    cpsys ${src} ${mntpt}
+    # need to make a couple of tweaks
+    cat > ${mntpt}/boot/loader.conf <<EOF
+geom_eli_load=YES
+EOF
+    cat > ${mntpt}/etc/fstab <<EOF
+/dev/ada0p3.eli	/		ufs	rw	1	1
+EOF
+
+    cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko
+    # end tweaks
+    umount -f ${mntpt}
+    geli detach ${md}p3
+    ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md}
+    mdconfig -d -u ${md}
 }
 
 mk_geli_gpt_zfs_legacy() {
+    src=$1
+    img=$2
+    mntpt=$3
+    geli=$4
+    scheme=$5
+    fs=$6
+    bios=$7
+    pool=geli-gpt-zfs-legacy
+
+    dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 ))
+    md=$(mdconfig -f ${img})
+    gpart create -s gpt ${md}
+    gpart add -t freebsd-boot -s 400k -a 4k	${md}	# <= ~540k
+    gpart add -t freebsd-zfs -l root $md
+    # install-boot will make this bootable
+    echo passphrase | geli init -bg -e AES-XTS -i 50000 -J - -l 256 -s 4096 ${md}p2
+    echo passphrase | geli attach -j - ${md}p2
+    zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p2.eli
+    zpool set bootfs=${pool} ${pool}
+    zfs create -po mountpoint=/ ${pool}/ROOT/default
+    # NB: The online guides go nuts customizing /var and other mountpoints here, no need
+    cpsys ${src} ${mntpt}
+    # need to make a couple of tweaks
+    cat > ${mntpt}/boot/loader.conf <<EOF
+zfs_load=YES
+opensolaris_load=YES
+geom_eli_load=YES
+EOF
+    cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
+    cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
+    cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko
+    # end tweaks
+    zfs umount -f ${pool}/ROOT/default
+    zfs set mountpoint=none ${pool}/ROOT/default
+    zpool set bootfs=${pool}/ROOT/default ${pool}
+    zpool set autoexpand=on ${pool}
+    zpool export ${pool}
+    geli detach ${md}p2
+    ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md}
+    mdconfig -d -u ${md}
 }
 
 mk_geli_gpt_zfs_uefi() {
+    src=$1
+    img=$2
+    mntpt=$3
+    geli=$4
+    scheme=$5
+    fs=$6
+    bios=$7
+    pool=geli-gpt-zfs-uefi
+
+    dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 ))
+    md=$(mdconfig -f ${img})
+    gpart create -s gpt ${md}
+    gpart add -t efi -s 800k -a 4k ${md}
+    gpart add -t freebsd-zfs -l root $md
+    # install-boot will make this bootable
+    echo passphrase | geli init -bg -e AES-XTS -i 50000 -J - -l 256 -s 4096 ${md}p2
+    echo passphrase | geli attach -j - ${md}p2
+    zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p2.eli
+    zpool set bootfs=${pool} ${pool}
+    zfs create -po mountpoint=/ ${pool}/ROOT/default
+    # NB: The online guides go nuts customizing /var and other mountpoints here, no need
+    cpsys ${src} ${mntpt}
+    # need to make a couple of tweaks
+    cat > ${mntpt}/boot/loader.conf <<EOF
+zfs_load=YES
+opensolaris_load=YES
+geom_eli_load=YES
+EOF
+    cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
+    cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
+    cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko
+    # end tweaks
+    zfs umount -f ${pool}/ROOT/default
+    zfs set mountpoint=none ${pool}/ROOT/default
+    zpool set bootfs=${pool}/ROOT/default ${pool}
+    zpool set autoexpand=on ${pool}
+    zpool export ${pool}
+    geli detach ${md}p2
+    ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md}
+    mdconfig -d -u ${md}
 }
 
 mk_geli_gpt_zfs_both() {
+    src=$1
+    img=$2
+    mntpt=$3
+    geli=$4
+    scheme=$5
+    fs=$6
+    bios=$7
+    pool=geli-gpt-zfs-both
+
+    dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 ))
+    md=$(mdconfig -f ${img})
+    gpart create -s gpt ${md}
+    gpart add -t efi -s 800k -a 4k ${md}
+    gpart add -t freebsd-boot -s 400k -a 4k	${md}	# <= ~540k
+    gpart add -t freebsd-zfs -l root $md
+    # install-boot will make this bootable
+    echo passphrase | geli init -bg -e AES-XTS -i 50000 -J - -l 256 -s 4096 ${md}p3
+    echo passphrase | geli attach -j - ${md}p3
+    zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p3.eli
+    zpool set bootfs=${pool} ${pool}
+    zfs create -po mountpoint=/ ${pool}/ROOT/default
+    # NB: The online guides go nuts customizing /var and other mountpoints here, no need
+    cpsys ${src} ${mntpt}
+    # need to make a couple of tweaks
+    cat > ${mntpt}/boot/loader.conf <<EOF
+zfs_load=YES
+opensolaris_load=YES
+geom_eli_load=YES
+EOF
+    cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko
+    cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko
+    cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko
+    # end tweaks
+    zfs umount -f ${pool}/ROOT/default
+    zfs set mountpoint=none ${pool}/ROOT/default
+    zpool set bootfs=${pool}/ROOT/default ${pool}
+    zpool set autoexpand=on ${pool}
+    zpool export ${pool}
+    geli detach ${md}p3
+    ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md}
+    mdconfig -d -u ${md}
 }
 
+# GELI+MBR is not a valid configuration
 mk_geli_mbr_ufs_legacy() {
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806170555.w5H5tWn8071168>