ROOTMB=64
ROOTSECTS="`expr $ROOTMB '*' 1024 '*' 2`"
BOOTXXSECTS=32
-USRKBFILE=/.usrkb
-if [ ! -f "$USRKBFILE" ]
-then echo "Are you really running from CD?"
- echo "No $USRKBFILE file."
- exit 1
-fi
-USRKB="`cat /.usrkb`"
+USRKB="`du -sxk /usr | awk '{ print $1 }'`"
TOTALMB="`expr 3 + $USRKB / 1024 + $ROOTMB`"
-ROOTFILES="`cat /.rootfiles`"
-USRFILES="`cat /.usrfiles`"
+ROOTFILES="`find -x / | wc -l`"
+USRFILES="`find -x /usr | wc -l`"
+
+# /usr/install isn't copied onto the new system; compensate
+INSTALLDIR=/usr/install
+if [ -d $INSTALLDIR ]
+then $USRFILES=$(($USRFILES - `find -x $INSTALLDIR | wc -l`))
+ $USRKB=$(($USRKB - `du -sxk $INSTALLDIR | awk '{ print $1 }'`))
+fi
if [ -z "$FSTYPE" ]
then FSTYPE=mfs
fi
-if [ "$TOTALMB" -lt 1 ]
-then
- echo "Are you really running from CD?"
- echo "Something wrong with size estimate on CD."
- exit 1
-fi
-
-if [ "$ROOTFILES" -lt 1 ]
-then
- echo "Are you really running from CD?"
- echo "Something wrong with root files count on CD."
- exit 1
-fi
-
-if [ "$USRFILES" -lt 1 ]
-then
- echo "Are you really running from CD?"
- echo "Something wrong with usr files count on CD."
- exit 1
-fi
-
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
chmod o-w /mnt/usr
cp /mnt/etc/motd.install /mnt/etc/motd
+
# Fix /var/log
rm /mnt/var/log
ln -s /usr/log /mnt/var/log
# XXX we have to use "-f" here, because installboot worries about BPB, which
# we don't have...
installboot_nbsd -f /dev/$primary /usr/mdec/bootxx_minixfs3 >/dev/null || exit
-cp /mnt/etc/boot.cfg.default /mnt/boot.cfg
+# give the install the boot loader
+cp /usr/mdec/boot_monitor /mnt/
+minixdir=/mnt/boot/minix_default
+if [ ! -f $minixdir/kernel ]
+then rm -rf $minixdir
+ cp -r /mnt/multiboot $minixdir
+fi
+if [ ! -e /mnt/boot/minix_latest ]
+then ln -sf minix_default /mnt/boot/minix_latest
+fi
chroot /mnt update_bootcfg
# Save name of CD drive
: ${BUILDVARS=}
: ${BUILDSH=build.sh}
+# Where the kernel & boot modules will be
+MODDIR=${DESTDIR}/multiboot
+
#
# Directory where to store temporary file system images
#
: ${IMG_DIR=${OBJ}/img}
-: ${IMG=minix_x86.img}
+
+CDFILES=${IMG_DIR}/cd
if [ ! -f ${BUILDSH} ]
then echo "Please invoke me from the root source dir, where ${BUILDSH} is."
#
# Artifacts from this script are stored in the IMG_DIR
#
-mkdir -p $IMG_DIR
+rm -rf $IMG_DIR $IMG
+mkdir -p $IMG_DIR $CDFILES
+
+while getopts "i" c
+do
+ case "$c" in
+ i) : ${IMG=minix_x86.iso}
+ ISOMODE=1
+ ;;
+ esac
+done
+
+: ${IMG=minix_x86.img}
#
# Call build.sh using a sloppy file list so we don't need to remove the installed /etc/fstag
export CPPFLAGS=${FLAG}
sh ${BUILDSH} -V SLOPPY_FLIST=yes -V MKBINUTILS=yes -V MKGCCCMDS=yes -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u distribution
-#
+if [ "$ISOMODE" ]
+then cp ${DESTDIR}/usr/mdec/boot_monitor $CDFILES/boot
+ cp ${MODDIR}/* $CDFILES/
+ . ./releasetools/release.functions
+ cd_root_changes # uses $CDFILES and writes $CDFILES/boot.cfg
+ ${CROSS_TOOLS}/nbwriteisofs -s0x0 -l MINIX -B ${DESTDIR}/usr/mdec/bootxx_cd9660 -n $CDFILES ${IMG_DIR}/iso.img
+ ISO_SIZE=$((`stat -c %s ${IMG_DIR}/iso.img` / 512))
+else # just make an empty iso partition
+ ISO_SIZE=8
+fi
+
# This script creates a bootable image and should at some point in the future
# be replaced by makefs.
#
# All sized are written in 512 byte blocks
#
# we create a disk image of about 2 gig's
-# for alignement reasons, prefer sizes which are multiples of 4096 bytes
+# for alignment reasons, prefer sizes which are multiples of 4096 bytes
#
-: ${IMG_SIZE=$(( 2*(2**30) / 512))}
: ${ROOT_SIZE=$(( 64*(2**20) / 512))}
: ${HOME_SIZE=$(( 128*(2**20) / 512))}
: ${USR_SIZE=$((1536*(2**20) / 512))}
# setup phase on x86
#
cat >${FSTAB} <<END_FSTAB
-/dev/c0d0p1 /home mfs rw 0 2
/dev/c0d0p2 /usr mfs rw 0 2
+/dev/c0d0p3 /home mfs rw 0 2
END_FSTAB
rm -f ${DESTDIR}/SETS.*
# Now given the sizes above use DD to create separate files representing
# the partitions we are going to use.
#
+dd if=/dev/zero of=${IMG_DIR}/iso.img bs=512 count=1 seek=$(($ISO_SIZE -1)) 2>/dev/null
dd if=/dev/zero of=${IMG_DIR}/root.img bs=512 count=1 seek=$(($ROOT_SIZE -1)) 2>/dev/null
dd if=/dev/zero of=${IMG_DIR}/home.img bs=512 count=1 seek=$(($HOME_SIZE -1)) 2>/dev/null
dd if=/dev/zero of=${IMG_DIR}/usr.img bs=512 count=1 seek=$(($USR_SIZE -1)) 2>/dev/null
-# Create the empty image where we later will but the partitions in
-dd if=/dev/zero of=${IMG} bs=512 count=1 seek=$(($IMG_SIZE -1))
-
-#
-# Do some math to determine the start addresses of the partitions.
-# Ensure the start of the partitions are always aligned, the end will
-# always be as we assume the sizes are multiples of 4096 bytes, which
-# is always true as soon as you have an integer multiple of 1MB.
-#
-ROOT_START=8
-HOME_START=$(($ROOT_START + $ROOT_SIZE))
-USR_START=$(($HOME_START + $HOME_SIZE))
-
-set -x
-${CROSS_TOOLS}/nbpartition -m ${IMG} ${ROOT_START} 81:${ROOT_SIZE} 81:${HOME_SIZE} 81:${USR_SIZE}
-set +x
-
# make the different file system. this part is *also* hacky. We first convert
# the METALOG.sanitised using mtree into a input METALOG containing uids and
# gids.
-# Afther that we do some magic processing to add device nodes (also missing from METALOG)
+# After that we do some magic processing to add device nodes (also missing from METALOG)
# and convert the METALOG into a proto file that can be used by mkfs.mfs
#
echo "creating the file systems"
#
-# read METALOG and use mtree to conver the user and group names into uid and gids
-# FIX put "input somwhere clean"
+# read METALOG and use mtree to convert the user and group names into uid and gids
+# FIX put "input somewhere clean"
#
cat ${DESTDIR}/METALOG.sanitised | ${CROSS_TOOLS}/nbmtree -N ${DESTDIR}/etc -C > ${IMG_DIR}/input
cat ${IMG_DIR}/input | grep "^\./usr/\|^. " | sed "s,\./usr,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/usr -o ${IMG_DIR}/usr.proto
cat ${IMG_DIR}/input | grep "^\./home/\|^. " | sed "s,\./home,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/home -o ${IMG_DIR}/home.proto
+# If in ISO mode, fit the FSes
+if [ "$ISOMODE" ]
+then ROOTSIZEARG="-x 5" # give root fs a little breathing room on the CD
+else # give args with the right sizes
+ ROOTSIZEARG="-b $((${ROOT_SIZE} / 8))"
+ USRSIZEARG="-b $((${USR_SIZE} / 8))"
+ HOMESIZEARG="-b $((${HOME_SIZE} / 8))"
+fi
+
#
# Generate /root, /usr and /home partition images.
#
echo "Writing Minix filesystem images"
echo " - ROOT"
-${CROSS_TOOLS}/nbmkfs.mfs -b $((${ROOT_SIZE} / 8)) ${IMG_DIR}/root.img ${IMG_DIR}/root.proto
+${CROSS_TOOLS}/nbmkfs.mfs $ROOTSIZEARG ${IMG_DIR}/root.img ${IMG_DIR}/root.proto
echo " - USR"
-${CROSS_TOOLS}/nbmkfs.mfs -b $((${USR_SIZE} / 8)) ${IMG_DIR}/usr.img ${IMG_DIR}/usr.proto
+${CROSS_TOOLS}/nbmkfs.mfs $USRSIZEARG ${IMG_DIR}/usr.img ${IMG_DIR}/usr.proto
echo " - HOME"
-${CROSS_TOOLS}/nbmkfs.mfs -b $((${HOME_SIZE} / 8)) ${IMG_DIR}/home.img ${IMG_DIR}/home.proto
+${CROSS_TOOLS}/nbmkfs.mfs $HOMESIZEARG ${IMG_DIR}/home.img ${IMG_DIR}/home.proto
+
+# Set the sizes based on what was just generated - should change nothing if sizes
+# were specified
+echo "$ROOT_SIZE $USR_SIZE $HOME_SIZE"
+ROOT_SIZE=$((`stat -c %s ${IMG_DIR}/root.img` / 512))
+USR_SIZE=$((`stat -c %s ${IMG_DIR}/usr.img` / 512))
+HOME_SIZE=$((`stat -c %s ${IMG_DIR}/home.img` / 512))
+echo "$ROOT_SIZE $USR_SIZE $HOME_SIZE"
+
+# Do some math to determine the start addresses of the partitions.
+# Ensure the start of the partitions are always aligned, the end will
+# always be as we assume the sizes are multiples of 4096 bytes, which
+# is always true as soon as you have an integer multiple of 1MB.
+#
+ISO_START=0
+ROOT_START=$(($ISO_START + $ISO_SIZE))
+USR_START=$(($ROOT_START + $ROOT_SIZE))
+HOME_START=$(($USR_START + $USR_SIZE))
#
# Merge the partitions into a single image.
#
echo "Merging file systems"
+dd if=${IMG_DIR}/iso.img of=${IMG} seek=$ISO_START conv=notrunc
dd if=${IMG_DIR}/root.img of=${IMG} seek=$ROOT_START conv=notrunc
-dd if=${IMG_DIR}/home.img of=${IMG} seek=$HOME_START conv=notrunc
dd if=${IMG_DIR}/usr.img of=${IMG} seek=$USR_START conv=notrunc
+dd if=${IMG_DIR}/home.img of=${IMG} seek=$HOME_START conv=notrunc
+
+${CROSS_TOOLS}/nbpartition -m ${IMG} ${ISO_START} 81:${ISO_SIZE} 81:${ROOT_SIZE} 81:${USR_SIZE} 81:${HOME_SIZE}
-moddir=${DESTDIR}/boot/minix/.temp/
-mods="`( cd $moddir; echo mod* | tr ' ' ',' )`"
-echo "To boot this image on kvm:"
-echo "cd $moddir && kvm -serial stdio -kernel kernel -append \"console=tty00 rootdevname=c0d0p0\" -initrd \"$mods\" -hda `pwd`/$IMG"
+mods="`( cd $MODDIR; echo mod* | tr ' ' ',' )`"
+if [ "$ISOMODE" ]
+then echo "CD image at `pwd`/$IMG"
+else echo "To boot this image on kvm:"
+ echo "cd $MODDIR && kvm -serial stdio -kernel kernel -append \"console=tty00 rootdevname=c0d0p1\" -initrd \"$mods\" -hda `pwd`/$IMG"
+fi