diff --git a/tools/boot/install-boot.sh b/tools/boot/install-boot.sh index d2b3eacfa48f..e5201e050b28 100755 --- a/tools/boot/install-boot.sh +++ b/tools/boot/install-boot.sh @@ -1,133 +1,146 @@ #!/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 } doit() { echo $* eval $* } 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 doit gpart bootcode -b ${gpt0} -p ${gptzfs2} -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 doit 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 doit gpart bootcode -b /tmp/zfsboo1 ${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 sysctl kern.geom.debugflags=0x0 exit 0 } boot_nogeli_mbr_ufs_legacy() { dev=$1 dst=$2 doit gpart bootcode -b ${mbr0} ${dev} s=$(findpart $dev "freebsd-ufs") if [ -z "$s" ] ; then - die "No freebsd-zfs slice found" + die "No freebsd-ufs slice found" fi doit gpart bootcode -p ${mbr2} ${dev}s${s} exit 0 } +boot_nogeli_vtoc8_ufs_ofw() { + dev=$1 + dst=$2 + + # 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=/ # 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 +# VTOC8 +vtoc8=${DESTDIR}/boot/boot1 + # sanity check here eval boot_${geli}_${scheme}_${fs}_${bios} $dev $DESTDIR $opts || echo "Unsupported boot env: ${geli}-${scheme}-${fs}-${bios}" diff --git a/tools/boot/rootgen.sh b/tools/boot/rootgen.sh index b0b4571a76b9..98e726f6a370 100755 --- a/tools/boot/rootgen.sh +++ b/tools/boot/rootgen.sh @@ -1,413 +1,440 @@ #!/bin/sh # $FreeBSD$ # # Builds all the bat-shit crazy combinations we support booting from, # at least for amd64. It assume you have a ~sane kernel in /boot/kernel # and copies that into the ~150MB root images we create (we create the du # size of the kernel + 20MB # # Sad panda sez: this runs as root, but could be userland if someone # creates userland geli and zfs tools. # # This assumes an external prograam install-boot.sh which will install # the appropriate boot files in the appropriate locations. # # These images assume ada0 will be the root image. We should likely # use labels, but we don't. # # ASsumes you've already rebuilt... maybe bad? Also maybe bad: the env # vars should likely be conditionally set to allow better automation. # cpsys() { src=$1 dst=$2 # Copy kernel + boot loader (cd $src ; tar cf - .) | (cd $dst; tar xf -) } mk_nogeli_gpt_ufs_legacy() { src=$1 img=$2 cat > ${src}/etc/fstab < ${src}/etc/fstab < ${src}/etc/fstab < ${mntpt}/boot/loader.conf < ${src}/etc/fstab < ${src}/etc/fstab < $sh # https://wiki.freebsd.org/arm64/QEMU also has # -device virtio-net-device,netdev=net0 # -netdev user,id=net0 } # Amd64 qemu qemu_amd64_legacy() { img=$1 sh=$2 echo "qemu-system-x86_64 --drive file=${img},format=raw ${qser}" > $sh } qemu_amd64_uefi() { img=$1 sh=$2 echo "qemu-system-x86_64 -bios ~/bios/OVMF-X64.fd --drive file=${img},format=raw ${qser}" > $sh } qemu_amd64_both() { img=$1 sh=$2 echo "qemu-system-x86_64 --drive file=${img},format=raw ${qser}" > $sh echo "qemu-system-x86_64 -bios ~/bios/OVMF-X64.fd --drive file=${img},format=raw ${qser}" > $sh } # arm # nothing listed? # i386 qemu_i386_legacy() { img=$1 sh=$2 echo "qemu-system-i386 --drive file=${img},format=raw ${qser}" > $sh } # Not yet supported qemu_i386_uefi() { img=$1 sh=$2 echo "qemu-system-i386 -bios ~/bios/OVMF-X32.fd --drive file=${img},format=raw ${qser}" > $sh } # Needs UEFI to be supported qemu_i386_both() { img=$1 sh=$2 echo "qemu-system-i386 --drive file=${img},format=raw ${qser}" > $sh echo "qemu-system-i386 -bios ~/bios/OVMF-X32.fd --drive file=${img},format=raw ${qser}" > $sh } # mips # qemu-system-mips -kernel /path/to/rootfs/boot/kernel/kernel -nographic -hda /path/to/disk.img -m 2048 # Powerpc -- doesn't work but maybe it would enough for testing -- needs details # powerpc64 # qemu-system-ppc64 -drive file=/path/to/disk.img,format=raw # sparc64 -# 10.3 works, 12-current (which one?) hangs # qemu-system-sparc64 -drive file=/path/to/disk.img,format=raw - # Misc variables SRCTOP=$(make -v SRCTOP) cd ${SRCTOP}/stand OBJDIR=$(make -v .OBJDIR) IMGDIR=${OBJDIR}/boot-images mkdir -p ${IMGDIR} MNTPT=$(mktemp -d /tmp/stand-test.XXXXXX) # Setup the installed tree... DESTDIR=${OBJDIR}/boot-tree rm -rf ${DESTDIR} mkdir -p ${DESTDIR}/boot/defaults mkdir -p ${DESTDIR}/boot/kernel +# XXX boot1 exists only on sparc64 +cp /boot/boot1 ${DESTDIR}/boot +cp /boot/loader ${DESTDIR}/boot cp /boot/kernel/kernel ${DESTDIR}/boot/kernel echo -h -D -S115200 > ${DESTDIR}/boot.config # XXX cp /boot/device.hints ${DESTDIR}/boot/device.hints # Assume we're already built make install DESTDIR=${DESTDIR} MK_MAN=no MK_INSTALL_AS_USER=yes # Copy init, /bin/sh, minimal libraries and testing /etc/rc mkdir -p ${DESTDIR}/sbin ${DESTDIR}/bin \ ${DESTDIR}/lib ${DESTDIR}/libexec \ ${DESTDIR}/etc ${DESTDIR}/dev for f in /sbin/halt /sbin/init /bin/sh $(ldd /bin/sh | awk 'NF == 4 { print $3; }') /libexec/ld-elf.so.1; do cp $f ${DESTDIR}/$f done cat > ${DESTDIR}/etc/rc <