1#!/usr/bin/env bash 2set -e 3 4# 5# This script creates a bootable image and should at some point in the future 6# be replaced by the proper NetBSD infrastructure. 7# 8# Supported command line switches: 9# -i build iso image instead of qemu imaeg 10# -b bitcode build, increase partition sizes as necessary 11# 12 13: ${ARCH=i386} 14: ${OBJ=../obj.${ARCH}} 15: ${TOOLCHAIN_TRIPLET=i586-elf32-minix-} 16: ${BUILDSH=build.sh} 17 18: ${SETS="minix-base minix-comp minix-games minix-man minix-tests tests"} 19: ${IMG=minix_x86.img} 20 21if [ ! -f ${BUILDSH} ] 22then 23 echo "Please invoke me from the root source dir, where ${BUILDSH} is." 24 exit 1 25fi 26 27# we create a disk image of about 2 gig's 28# for alignment reasons, prefer sizes which are multiples of 4096 bytes 29: ${BOOTXX_SECS=32} 30: ${ROOT_SIZE=$(( 128*(2**20) - ${BOOTXX_SECS} * 512 ))} 31: ${HOME_SIZE=$(( 128*(2**20) ))} 32: ${USR_SIZE=$(( 1792*(2**20) ))} 33 34# set up disk creation environment 35. releasetools/image.defaults 36. releasetools/image.functions 37 38# all sizes are written in 512 byte blocks 39ROOTSIZEARG="-b $((${ROOT_SIZE} / 512 / 8))" 40USRSIZEARG="-b $((${USR_SIZE} / 512 / 8))" 41HOMESIZEARG="-b $((${HOME_SIZE} / 512 / 8))" 42 43# where the kernel & boot modules will be 44MODDIR=${DESTDIR}/boot/minix/.temp 45 46echo "Building work directory..." 47build_workdir "$SETS" 48 49echo "Adding extra files..." 50 51# create a fstab entry in /etc 52cat >${ROOT_DIR}/etc/fstab <<END_FSTAB 53/dev/c0d0p1 /usr mfs rw 0 2 54/dev/c0d0p2 /home mfs rw 0 2 55none /sys devman rw,rslabel=devman 0 0 56none /dev/pts ptyfs rw,rslabel=ptyfs 0 0 57END_FSTAB 58add_file_spec "etc/fstab" extra.fstab 59 60cp ${DESTDIR}/usr/mdec/boot_monitor ${ROOT_DIR}/boot_monitor 61add_file_spec "boot_monitor" extra.boot 62 63add_link_spec "boot/minix_latest" "minix_default" extra.kernel 64workdir_add_kernel minix_default 65workdir_add_kernel minix/$RELEASE_VERSION 66 67# add boot.cfg 68cat >${ROOT_DIR}/boot.cfg <<END_BOOT_CFG 69clear=1 70timeout=5 71default=2 72menu=Start MINIX 3:load_mods /boot/minix_default/mod*; multiboot /boot/minix_default/kernel rootdevname=c0d0p0 73menu=Start latest MINIX 3:load_mods /boot/minix_latest/mod*; multiboot /boot/minix_latest/kernel rootdevname=c0d0p0 74menu=Start latest MINIX 3 in single user mode:load_mods /boot/minix_latest/mod*; multiboot /boot/minix_latest/kernel rootdevname=c0d0p0 bootopts=-s 75menu=Start MINIX 3 ALIX:load_mods /boot/minix_default/mod*;multiboot /boot/minix_default/kernel rootdevname=c0d0p0 console=tty00 consdev=com0 ata_no_dma=1 76menu=Edit menu option:edit 77menu=Drop to boot prompt:prompt 78default=2 79menu=Start MINIX 3 ($RELEASE_VERSION):load_mods /boot/minix/$RELEASE_VERSION/mod*; multiboot /boot/minix/$RELEASE_VERSION/kernel rootdevname=c0d0p0 80END_BOOT_CFG 81add_file_spec "boot.cfg" extra.boot 82 83echo "Bundling packages..." 84bundle_packages "$BUNDLE_PACKAGES" 85 86echo "Creating specification files..." 87create_input_spec 88create_protos "usr home" 89 90# Clean image 91if [ -f ${IMG} ] # IMG might be a block device 92then 93 rm -f ${IMG} 94fi 95 96# 97# Generate /root, /usr and /home partition images. 98# 99echo "Writing disk image..." 100ROOT_START=${BOOTXX_SECS} 101echo " * ROOT" 102_ROOT_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${ROOTSIZEARG} -I $((${ROOT_START}*512)) ${IMG} ${WORK_DIR}/proto.root) 103_ROOT_SIZE=$(($_ROOT_SIZE / 512)) 104USR_START=$((${ROOT_START} + ${_ROOT_SIZE})) 105echo " * USR" 106_USR_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${USRSIZEARG} -I $((${USR_START}*512)) ${IMG} ${WORK_DIR}/proto.usr) 107_USR_SIZE=$(($_USR_SIZE / 512)) 108HOME_START=$((${USR_START} + ${_USR_SIZE})) 109echo " * HOME" 110_HOME_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${HOMESIZEARG} -I $((${HOME_START}*512)) ${IMG} ${WORK_DIR}/proto.home) 111_HOME_SIZE=$(($_HOME_SIZE / 512)) 112 113# 114# Write the partition table using the natively compiled 115# minix partition utility 116# 117${CROSS_TOOLS}/nbpartition -m ${IMG} ${BOOTXX_SECS} 81:${_ROOT_SIZE} 81:${_USR_SIZE} 81:${_HOME_SIZE} 118${CROSS_TOOLS}/nbinstallboot -f -m ${ARCH} ${IMG} ${DESTDIR}/usr/mdec/bootxx_minixfs3 119 120 121mods="`( cd ${MODDIR}; echo mod* | tr ' ' ',' )`" 122echo "Disk image at `pwd`/${IMG}" 123echo "To boot this image on kvm:" 124echo "cd ${MODDIR} && qemu-system-i386 --enable-kvm -m 256 -kernel kernel -append \"rootdevname=c0d0p0\" -initrd \"${mods}\" -hda `pwd`/${IMG}" 125