1082c6764SWarner Losh#!/bin/sh 2082c6764SWarner Losh 3082c6764SWarner Losh# $FreeBSD$ 4082c6764SWarner Losh 5082c6764SWarner Losh# 6082c6764SWarner Losh# Builds all the bat-shit crazy combinations we support booting from, 7082c6764SWarner Losh# at least for amd64. It assume you have a ~sane kernel in /boot/kernel 8082c6764SWarner Losh# and copies that into the ~150MB root images we create (we create the du 9082c6764SWarner Losh# size of the kernel + 20MB 10082c6764SWarner Losh# 11082c6764SWarner Losh# Sad panda sez: this runs as root, but could be userland if someone 12082c6764SWarner Losh# creates userland geli and zfs tools. 13082c6764SWarner Losh# 14082c6764SWarner Losh# This assumes an external prograam install-boot.sh which will install 15082c6764SWarner Losh# the appropriate boot files in the appropriate locations. 16082c6764SWarner Losh# 17082c6764SWarner Losh# These images assume ada0 will be the root image. We should likely 18082c6764SWarner Losh# use labels, but we don't. 19082c6764SWarner Losh# 20082c6764SWarner Losh# ASsumes you've already rebuilt... maybe bad? Also maybe bad: the env 21082c6764SWarner Losh# vars should likely be conditionally set to allow better automation. 22082c6764SWarner Losh# 23082c6764SWarner Losh 24082c6764SWarner Loshcpsys() { 25082c6764SWarner Losh src=$1 26082c6764SWarner Losh dst=$2 27082c6764SWarner Losh 28082c6764SWarner Losh # Copy kernel + boot loader 29082c6764SWarner Losh (cd $src ; tar cf - .) | (cd $dst; tar xf -) 30082c6764SWarner Losh} 31082c6764SWarner Losh 32082c6764SWarner Loshmk_nogeli_gpt_ufs_legacy() { 33082c6764SWarner Losh src=$1 34082c6764SWarner Losh img=$2 35082c6764SWarner Losh 36082c6764SWarner Losh rm -f ${img} ${img}.p2 37082c6764SWarner Losh makefs -t ffs -B little -s 200m ${img}.p2 ${src} 38082c6764SWarner Losh mkimg -s gpt -b ${src}/boot/pmbr \ 39082c6764SWarner Losh -p freebsd-boot:=${src}/boot/gptboot \ 40082c6764SWarner Losh -p freebsd-ufs:=${img}.p2 -o ${img} 41082c6764SWarner Losh} 42082c6764SWarner Losh 43082c6764SWarner Loshmk_nogeli_gpt_ufs_uefi() { 44082c6764SWarner Losh src=$1 45082c6764SWarner Losh img=$2 46082c6764SWarner Losh 47082c6764SWarner Losh rm -f ${img} ${img}.p2 48082c6764SWarner Losh makefs -t ffs -B little -s 200m ${img}.p2 ${src} 49082c6764SWarner Losh mkimg -s gpt -b ${src}/boot/pmbr \ 50082c6764SWarner Losh -p freebsd-boot:=${src}/boot/gptboot \ 51082c6764SWarner Losh -p freebsd-ufs:=${img}.p2 -o ${img} 52082c6764SWarner Losh} 53082c6764SWarner Losh 54082c6764SWarner Loshmk_nogeli_gpt_ufs_both() { 55082c6764SWarner Losh src=$1 56082c6764SWarner Losh img=$2 57082c6764SWarner Losh 58082c6764SWarner Losh makefs -t ffs -B little -s 200m ${img}.p3 ${src} 59082c6764SWarner Losh # p1 is boot for uefi, p2 is boot for gpt, p3 is / 60082c6764SWarner Losh mkimg -b ${src}/boot/pmbr -s gpt \ 61082c6764SWarner Losh -p efi:=${src}/boot/boot1.efifat \ 62082c6764SWarner Losh -p freebsd-boot:=${src}/boot/gptboot \ 63082c6764SWarner Losh -p freebsd-ufs:=${img}.p3 \ 64082c6764SWarner Losh -o ${img} 65082c6764SWarner Losh} 66082c6764SWarner Losh 67082c6764SWarner Loshmk_nogeli_gpt_zfs_legacy() { 68082c6764SWarner Losh src=$1 69082c6764SWarner Losh img=$2 70082c6764SWarner Losh mntpt=$3 71082c6764SWarner Losh geli=$4 72082c6764SWarner Losh scheme=$5 73082c6764SWarner Losh fs=$6 74082c6764SWarner Losh bios=$7 75082c6764SWarner Losh pool=nogeli-gpt-zfs-legacy 76082c6764SWarner Losh 77082c6764SWarner Losh rm -f ${img} 78082c6764SWarner Losh dd if=/dev/zero of=${img} count=1 seek=$((200 * 1024 * 1024 / 512)) 79082c6764SWarner Losh md=$(mdconfig -f ${img}) 80082c6764SWarner Losh gpart create -s gpt ${md} 81082c6764SWarner Losh gpart add -t freebsd-boot -s 400k -a 4k ${md} # <= ~540k 82082c6764SWarner Losh gpart add -t freebsd-zfs -l root $md 83082c6764SWarner Losh # install-boot will make this bootable 84082c6764SWarner Losh zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p2 85082c6764SWarner Losh zpool set bootfs=${pool} ${pool} 86082c6764SWarner Losh zfs create -o mountpoint=/ ${pool}/ROOT 87082c6764SWarner Losh # NB: The online guides go nuts customizing /var and other mountpoints here, no need 88082c6764SWarner Losh cpsys ${src} ${mntpt} 89082c6764SWarner Losh df 90082c6764SWarner Losh # need to make a couple of tweaks 91082c6764SWarner Losh cat > ${mntpt}/boot/loader.conf <<EOF 92082c6764SWarner Loshzfs_load=YES 93082c6764SWarner Loshopensolaris_load=YES 94082c6764SWarner LoshEOF 95082c6764SWarner Losh cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko 96082c6764SWarner Losh cp /boot/kernel/opensolaris.ko ${mntpt}/boot/kernel/opensolaris.ko 9716457354SWarner Losh ls -las ${mntpt}/boot 98082c6764SWarner Losh # end tweaks 99082c6764SWarner Losh zfs umount -f ${pool}/ROOT 100082c6764SWarner Losh zfs set mountpoint=none ${pool}/ROOT 101082c6764SWarner Losh zpool set bootfs=${pool}/ROOT ${pool} 102082c6764SWarner Losh zpool set autoexpand=on ${pool} 103082c6764SWarner Losh zpool export ${pool} 104082c6764SWarner Losh ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 105082c6764SWarner Losh mdconfig -d -u ${md} 106082c6764SWarner Losh} 107082c6764SWarner Losh 108082c6764SWarner Loshmk_nogeli_gpt_zfs_uefi() { 109082c6764SWarner Losh} 110082c6764SWarner Losh 111082c6764SWarner Loshmk_nogeli_gpt_zfs_both() { 112082c6764SWarner Losh} 113082c6764SWarner Losh 114082c6764SWarner Loshmk_nogeli_mbr_ufs_legacy() { 115082c6764SWarner Losh} 116082c6764SWarner Losh 117082c6764SWarner Loshmk_nogeli_mbr_ufs_uefi() { 118082c6764SWarner Losh} 119082c6764SWarner Losh 120082c6764SWarner Loshmk_nogeli_mbr_ufs_both() { 121082c6764SWarner Losh} 122082c6764SWarner Losh 123082c6764SWarner Loshmk_nogeli_mbr_zfs_legacy() { 124082c6764SWarner Losh} 125082c6764SWarner Losh 126082c6764SWarner Loshmk_nogeli_mbr_zfs_uefi() { 127082c6764SWarner Losh} 128082c6764SWarner Losh 129082c6764SWarner Loshmk_nogeli_mbr_zfs_both() { 130082c6764SWarner Losh} 131082c6764SWarner Losh 132082c6764SWarner Loshmk_geli_gpt_ufs_legacy() { 133082c6764SWarner Losh} 134082c6764SWarner Losh 135082c6764SWarner Loshmk_geli_gpt_ufs_uefi() { 136082c6764SWarner Losh} 137082c6764SWarner Losh 138082c6764SWarner Loshmk_geli_gpt_ufs_both() { 139082c6764SWarner Losh} 140082c6764SWarner Losh 141082c6764SWarner Loshmk_geli_gpt_zfs_legacy() { 142082c6764SWarner Losh} 143082c6764SWarner Losh 144082c6764SWarner Loshmk_geli_gpt_zfs_uefi() { 145082c6764SWarner Losh} 146082c6764SWarner Losh 147082c6764SWarner Loshmk_geli_gpt_zfs_both() { 148082c6764SWarner Losh} 149082c6764SWarner Losh 150082c6764SWarner Loshmk_geli_mbr_ufs_legacy() { 151082c6764SWarner Losh} 152082c6764SWarner Losh 153082c6764SWarner Loshmk_geli_mbr_ufs_uefi() { 154082c6764SWarner Losh} 155082c6764SWarner Losh 156082c6764SWarner Loshmk_geli_mbr_ufs_both() { 157082c6764SWarner Losh} 158082c6764SWarner Losh 159082c6764SWarner Loshmk_geli_mbr_zfs_legacy() { 160082c6764SWarner Losh} 161082c6764SWarner Losh 162082c6764SWarner Loshmk_geli_mbr_zfs_uefi() { 163082c6764SWarner Losh} 164082c6764SWarner Losh 165082c6764SWarner Loshmk_geli_mbr_zfs_both() { 166082c6764SWarner Losh} 167082c6764SWarner Losh 168082c6764SWarner Losh# iso 169082c6764SWarner Losh# pxeldr 170082c6764SWarner Losh# u-boot 171082c6764SWarner Losh 172082c6764SWarner Losh# Misc variables 173082c6764SWarner LoshSRCTOP=$(make -v SRCTOP) 174082c6764SWarner Loshcd ${SRCTOP}/stand 175082c6764SWarner LoshOBJDIR=$(make -v .OBJDIR) 176082c6764SWarner LoshIMGDIR=${OBJDIR}/boot-images 177082c6764SWarner Loshmkdir -p ${IMGDIR} 178082c6764SWarner LoshMNTPT=$(mktemp -d /tmp/stand-test.XXXXXX) 179082c6764SWarner Losh 180082c6764SWarner Losh# Setup the installed tree... 181082c6764SWarner LoshDESTDIR=${OBJDIR}/boot-tree 182082c6764SWarner Loshrm -rf ${DESTDIR} 183082c6764SWarner Loshmkdir -p ${DESTDIR}/boot/defaults 184082c6764SWarner Loshmkdir -p ${DESTDIR}/boot/kernel 185082c6764SWarner Loshcp /boot/kernel/kernel ${DESTDIR}/boot/kernel 186*328884aeSWarner Loshecho -h -D -S115200 > ${DESTDIR}/boot.config 187082c6764SWarner Losh# XXX 188082c6764SWarner Loshcp /boot/device.hints ${DESTDIR}/boot/device.hints 189082c6764SWarner Losh# Assume we're already built 190082c6764SWarner Loshmake install DESTDIR=${DESTDIR} MK_MAN=no MK_INSTALL_AS_USER=yes 191082c6764SWarner Losh# Copy init, /bin/sh and minimal libraries 192082c6764SWarner Loshmkdir -p ${DESTDIR}/sbin ${DESTDIR}/bin ${DESTDIR}/lib ${DESTDIR}/libexec 193082c6764SWarner Loshfor f in /sbin/init /bin/sh $(ldd /bin/sh | awk 'NF == 4 { print $3; }') /libexec/ld-elf.so.1; do 194082c6764SWarner Losh cp $f ${DESTDIR}/$f 195082c6764SWarner Loshdone 196082c6764SWarner Loshmkdir ${DESTDIR}/dev 197082c6764SWarner Losh 198082c6764SWarner Losh# OK. Let the games begin 199082c6764SWarner Losh 200082c6764SWarner Loshfor geli in nogeli geli; do 201082c6764SWarner Losh for scheme in gpt mbr; do 202082c6764SWarner Losh for fs in ufs zfs; do 203082c6764SWarner Losh for bios in legacy uefi both; do 204082c6764SWarner Losh # Create sparse file and mount newly created filesystem(s) on it 205082c6764SWarner Losh img=${IMGDIR}/${geli}-${scheme}-${fs}-${bios}.img 206082c6764SWarner Losh echo "vvvvvvvvvvvvvvvvvvvvvv Creating $img vvvvvvvvvvvvvvvvvvvvvvv" 207082c6764SWarner Losh eval mk_${geli}_${scheme}_${fs}_${bios} ${DESTDIR} ${img} ${MNTPT} ${geli} ${scheme} ${fs} ${bios} 208082c6764SWarner Losh echo "^^^^^^^^^^^^^^^^^^^^^^ Creating $img ^^^^^^^^^^^^^^^^^^^^^^^" 209082c6764SWarner Losh done 210082c6764SWarner Losh done 211082c6764SWarner Losh done 212082c6764SWarner Loshdone 213082c6764SWarner Losh 214082c6764SWarner Loshrmdir ${MNTPT} 215