1#!/bin/bash 2set -e 3 4: ${ARCH=i386} 5: ${OBJ=../obj.${ARCH}} 6: ${CROSS_TOOLS=${OBJ}/"tooldir.`uname -s`-`uname -r`-`uname -m`"/bin} 7: ${CROSS_PREFIX=${CROSS_TOOLS}/i586-elf32-minix-} 8: ${JOBS=1} 9: ${DESTDIR=${OBJ}/destdir.$ARCH} 10: ${FSTAB=${DESTDIR}/etc/fstab} 11: ${BUILDVARS=} 12: ${BUILDSH=build.sh} 13 14# Where the kernel & boot modules will be 15MODDIR=${DESTDIR}/multiboot 16 17# 18# Directory where to store temporary file system images 19# 20: ${IMG_DIR=${OBJ}/img} 21 22CDFILES=${IMG_DIR}/cd 23 24if [ ! -f ${BUILDSH} ] 25then 26 echo "Please invoke me from the root source dir, where ${BUILDSH} is." 27 exit 1 28fi 29 30export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:${PATH} 31 32while getopts "i" c 33do 34 case "$c" in 35 i) : ${IMG=minix_x86.iso} 36 ISOMODE=1 37 ;; 38 esac 39done 40 41: ${IMG=minix_x86.img} 42 43# 44# Artifacts from this script are stored in the IMG_DIR 45# 46rm -rf ${IMG_DIR} ${IMG} 47mkdir -p ${IMG_DIR} ${CDFILES} 48 49# 50# Remove the generated files to allow us call build.sh without '-V SLOPPY_FLIST=yes'. 51# 52rm -f ${FSTAB} 53 54# 55# Now start the build. 56# 57export CPPFLAGS=${FLAG} 58sh ${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u distribution 59 60if [ "x${ISOMODE}" = "x1" ] 61then 62 cp ${DESTDIR}/usr/mdec/boot_monitor ${CDFILES}/boot 63 cp ${MODDIR}/* ${CDFILES}/ 64 . ./releasetools/release.functions 65 cd_root_changes # uses $CDFILES and writes $CDFILES/boot.cfg 66 # start the image off with the iso image; reduce root size to reserve 67 ${CROSS_TOOLS}/nbwriteisofs -s0x0 -l MINIX -B ${DESTDIR}/usr/mdec/bootxx_cd9660 -n ${CDFILES} ${IMG} 68 ISO_SIZE=$((`${CROSS_TOOLS}/nbstat -f %z ${IMG}` / 512)) 69else 70 # just make an empty iso partition 71 ISO_SIZE=8 72fi 73 74# 75# create a fstab entry in /etc this is normally done during the 76# setup phase on x86 77# 78cat >${FSTAB} <<END_FSTAB 79/dev/c0d0p2 /usr mfs rw 0 2 80/dev/c0d0p3 /home mfs rw 0 2 81none /sys devman rw,rslabel=devman 0 0 82END_FSTAB 83 84rm -f ${DESTDIR}/SETS.* 85 86${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${DESTDIR} ${DESTDIR}/etc/master.passwd 87 88# 89# make the different file system. this part is *also* hacky. We first convert 90# the METALOG.sanitised using mtree into a input METALOG containing uids and 91# gids. 92# After that we do some magic processing to add device nodes (also missing from METALOG) 93# and convert the METALOG into a proto file that can be used by mkfs.mfs 94# 95echo "creating the file systems" 96 97# 98# read METALOG and use mtree to convert the user and group names into uid and gids 99# FIX put "input somewhere clean" 100# 101cat ${DESTDIR}/METALOG.sanitised | ${CROSS_TOOLS}/nbmtree -N ${DESTDIR}/etc -C -K device > ${IMG_DIR}/input 102 103# add fstab 104echo "./etc/fstab type=file uid=0 gid=0 mode=0755 size=747 time=1365060731.000000000" >> ${IMG_DIR}/input 105 106# fill root.img (skipping /usr entries while keeping the /usr directory) 107cat ${IMG_DIR}/input | grep -v "^./usr/" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR} -o ${IMG_DIR}/root.proto 108 109# 110# Create proto files for /usr and /home using toproto. 111# 112cat ${IMG_DIR}/input | grep "^\./usr/\|^. " | sed "s,\./usr,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/usr -o ${IMG_DIR}/usr.proto 113cat ${IMG_DIR}/input | grep "^\./home/\|^. " | sed "s,\./home,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/home -o ${IMG_DIR}/home.proto 114 115# 116# This script creates a bootable image and should at some point in the future 117# be replaced by makefs. 118# 119# All sized are written in 512 byte blocks 120# 121# we create a disk image of about 2 gig's 122# for alignment reasons, prefer sizes which are multiples of 4096 bytes 123# 124: ${ROOT_SIZE=$(( 64*(2**20) / 512))} 125: ${HOME_SIZE=$(( 128*(2**20) / 512))} 126: ${USR_SIZE=$(( 1536*(2**20) / 512))} 127 128if [ "x${ISOMODE}" = "x1" ] 129then 130 # In iso mode, make all FSes fit (i.e. as small as possible), but 131 # leave some space on / 132 ROOTSIZEARG="-x 5" 133else 134 # In hd image mode, FSes have fixed sizes 135 ROOTSIZEARG="-b $((${ROOT_SIZE} / 8))" 136 USRSIZEARG="-b $((${USR_SIZE} / 8))" 137 HOMESIZEARG="-b $((${HOME_SIZE} / 8))" 138fi 139 140echo "Writing Minix filesystem images" 141 142# 143# Do some math to determine the start addresses of the partitions. 144# Ensure the start of the partitions are always aligned, the end will 145# always be as we assume the sizes are multiples of 4096 bytes, which 146# is always true as soon as you have an integer multiple of 1MB. 147# 148ROOT_START=${ISO_SIZE} 149 150echo " - ROOT" 151ROOT_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $ROOTSIZEARG -I $(($ROOT_START*512)) ${IMG} ${IMG_DIR}/root.proto`/512)) 152USR_START=$((${ROOT_START} + ${ROOT_SIZE})) 153echo " - USR" 154USR_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $USRSIZEARG -I $(($USR_START*512)) ${IMG} ${IMG_DIR}/usr.proto`/512)) 155HOME_START=$((${USR_START} + $USR_SIZE)) 156echo " - HOME" 157HOME_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $HOMESIZEARG -I $(($HOME_START*512)) ${IMG} ${IMG_DIR}/home.proto`/512)) 158 159${CROSS_TOOLS}/nbpartition -m ${IMG} 0 81:${ISO_SIZE} 81:${ROOT_SIZE} 81:${USR_SIZE} 81:${HOME_SIZE} 160 161mods="`( cd ${MODDIR}; echo mod* | tr ' ' ',' )`" 162if [ "x${ISOMODE}" = "x1" ] 163then 164 echo "CD image at `pwd`/${IMG}" 165else 166 echo "To boot this image on kvm:" 167 echo "cd ${MODDIR} && kvm -serial stdio -kernel kernel -append \"console=tty00 rootdevname=c0d0p1\" -initrd \"${mods}\" -hda `pwd`/${IMG}" 168fi 169