2013-09-24 15:15:55 +02:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
: ${ARCH=i386}
|
|
|
|
: ${OBJ=../obj.${ARCH}}
|
|
|
|
: ${CROSS_TOOLS=${OBJ}/"tooldir.`uname -s`-`uname -r`-`uname -m`"/bin}
|
|
|
|
: ${CROSS_PREFIX=${CROSS_TOOLS}/i586-elf32-minix-}
|
|
|
|
: ${JOBS=1}
|
|
|
|
: ${DESTDIR=${OBJ}/destdir.$ARCH}
|
|
|
|
: ${FSTAB=${DESTDIR}/etc/fstab}
|
|
|
|
: ${BUILDVARS=}
|
|
|
|
: ${BUILDSH=build.sh}
|
2014-06-10 17:05:29 +02:00
|
|
|
: ${CREATE_IMAGE_ONLY=0}
|
2013-09-24 15:15:55 +02:00
|
|
|
|
2013-11-05 15:43:44 +01:00
|
|
|
# Where the kernel & boot modules will be
|
|
|
|
MODDIR=${DESTDIR}/multiboot
|
|
|
|
|
2013-09-24 15:15:55 +02:00
|
|
|
#
|
|
|
|
# Directory where to store temporary file system images
|
|
|
|
#
|
|
|
|
: ${IMG_DIR=${OBJ}/img}
|
2013-11-05 15:43:44 +01:00
|
|
|
|
|
|
|
CDFILES=${IMG_DIR}/cd
|
2013-09-24 15:15:55 +02:00
|
|
|
|
|
|
|
if [ ! -f ${BUILDSH} ]
|
2013-10-03 18:26:21 +02:00
|
|
|
then
|
|
|
|
echo "Please invoke me from the root source dir, where ${BUILDSH} is."
|
2013-09-24 15:15:55 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-10-03 18:26:21 +02:00
|
|
|
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:${PATH}
|
2013-09-24 15:15:55 +02:00
|
|
|
|
2013-11-05 15:43:44 +01:00
|
|
|
while getopts "i" c
|
|
|
|
do
|
|
|
|
case "$c" in
|
|
|
|
i) : ${IMG=minix_x86.iso}
|
|
|
|
ISOMODE=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
: ${IMG=minix_x86.img}
|
2014-06-28 18:23:56 +02:00
|
|
|
: ${RC=minix_x86.rc}
|
2013-09-24 15:15:55 +02:00
|
|
|
|
2014-06-10 17:05:29 +02:00
|
|
|
#
|
|
|
|
# Are we going to build the minix sources?
|
|
|
|
#
|
|
|
|
|
|
|
|
if [ ${CREATE_IMAGE_ONLY} -eq 1 ]
|
|
|
|
then
|
|
|
|
if [ ! -d ${DESTDIR} ]
|
|
|
|
then
|
|
|
|
echo "Minix source code does'nt appear to have been built."
|
|
|
|
echo "Please try with \$CREATE_IMAGE_ONLY set to 0."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-11-07 08:33:39 +01:00
|
|
|
#
|
|
|
|
# Artifacts from this script are stored in the IMG_DIR
|
|
|
|
#
|
2013-10-03 18:26:21 +02:00
|
|
|
rm -rf ${IMG_DIR} ${IMG}
|
|
|
|
mkdir -p ${IMG_DIR} ${CDFILES}
|
2013-11-07 08:33:39 +01:00
|
|
|
|
2014-06-10 17:05:29 +02:00
|
|
|
if [ ${CREATE_IMAGE_ONLY} -eq 0 ]
|
|
|
|
then
|
|
|
|
echo "Going to build Minix source code..."
|
|
|
|
#
|
|
|
|
# Remove the generated files to allow us call build.sh without '-V SLOPPY_FLIST=yes'.
|
|
|
|
#
|
|
|
|
rm -f ${FSTAB}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Now start the build.
|
|
|
|
#
|
|
|
|
export CPPFLAGS=${FLAG}
|
|
|
|
sh ${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u distribution
|
2013-11-25 14:47:22 +01:00
|
|
|
|
2014-06-10 17:05:29 +02:00
|
|
|
fi
|
2013-09-24 15:15:55 +02:00
|
|
|
|
2013-10-03 18:26:21 +02:00
|
|
|
if [ "x${ISOMODE}" = "x1" ]
|
|
|
|
then
|
|
|
|
cp ${DESTDIR}/usr/mdec/boot_monitor ${CDFILES}/boot
|
|
|
|
cp ${MODDIR}/* ${CDFILES}/
|
2013-11-05 15:43:44 +01:00
|
|
|
. ./releasetools/release.functions
|
|
|
|
cd_root_changes # uses $CDFILES and writes $CDFILES/boot.cfg
|
2013-11-07 08:33:39 +01:00
|
|
|
# start the image off with the iso image; reduce root size to reserve
|
2013-10-03 18:26:21 +02:00
|
|
|
${CROSS_TOOLS}/nbwriteisofs -s0x0 -l MINIX -B ${DESTDIR}/usr/mdec/bootxx_cd9660 -n ${CDFILES} ${IMG}
|
2014-02-22 22:32:12 +01:00
|
|
|
ISO_SIZE=$((`${CROSS_TOOLS}/nbstat -f %z ${IMG}` / 512))
|
2013-10-03 18:26:21 +02:00
|
|
|
else
|
|
|
|
# just make an empty iso partition
|
2013-11-05 15:43:44 +01:00
|
|
|
ISO_SIZE=8
|
|
|
|
fi
|
|
|
|
|
2013-09-24 15:15:55 +02:00
|
|
|
#
|
|
|
|
# create a fstab entry in /etc this is normally done during the
|
|
|
|
# setup phase on x86
|
|
|
|
#
|
|
|
|
cat >${FSTAB} <<END_FSTAB
|
|
|
|
/dev/c0d0p2 /usr mfs rw 0 2
|
2013-11-05 15:43:44 +01:00
|
|
|
/dev/c0d0p3 /home mfs rw 0 2
|
2013-11-22 13:54:02 +01:00
|
|
|
none /sys devman rw,rslabel=devman 0 0
|
2013-09-24 15:15:55 +02:00
|
|
|
END_FSTAB
|
|
|
|
|
|
|
|
rm -f ${DESTDIR}/SETS.*
|
|
|
|
|
|
|
|
${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${DESTDIR} ${DESTDIR}/etc/master.passwd
|
|
|
|
|
2013-10-03 18:26:21 +02:00
|
|
|
#
|
2013-09-24 15:15:55 +02:00
|
|
|
# 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.
|
2013-11-05 15:43:44 +01:00
|
|
|
# After that we do some magic processing to add device nodes (also missing from METALOG)
|
2013-09-24 15:15:55 +02:00
|
|
|
# and convert the METALOG into a proto file that can be used by mkfs.mfs
|
|
|
|
#
|
|
|
|
echo "creating the file systems"
|
|
|
|
|
|
|
|
#
|
2013-11-05 15:43:44 +01:00
|
|
|
# read METALOG and use mtree to convert the user and group names into uid and gids
|
|
|
|
# FIX put "input somewhere clean"
|
2013-09-24 15:15:55 +02:00
|
|
|
#
|
2013-10-03 18:26:21 +02:00
|
|
|
cat ${DESTDIR}/METALOG.sanitised | ${CROSS_TOOLS}/nbmtree -N ${DESTDIR}/etc -C -K device > ${IMG_DIR}/input
|
2013-09-24 15:15:55 +02:00
|
|
|
|
2014-06-28 18:23:56 +02:00
|
|
|
# add rc (if any)
|
|
|
|
if [ -f ${RC} ]; then
|
|
|
|
cp ${RC} ${DESTDIR}/usr/etc/rc.local
|
|
|
|
echo "./usr/etc/rc.local type=file uid=0 gid=0 mode=0644" >> ${IMG_DIR}/input
|
|
|
|
fi
|
|
|
|
|
2013-09-24 15:15:55 +02:00
|
|
|
# add fstab
|
|
|
|
echo "./etc/fstab type=file uid=0 gid=0 mode=0755 size=747 time=1365060731.000000000" >> ${IMG_DIR}/input
|
|
|
|
|
|
|
|
# fill root.img (skipping /usr entries while keeping the /usr directory)
|
2013-10-03 18:26:21 +02:00
|
|
|
cat ${IMG_DIR}/input | grep -v "^./usr/" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR} -o ${IMG_DIR}/root.proto
|
2013-09-24 15:15:55 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# Create proto files for /usr and /home using toproto.
|
|
|
|
#
|
|
|
|
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
|
|
|
|
|
2013-10-03 18:26:21 +02:00
|
|
|
#
|
2013-11-07 08:33:39 +01:00
|
|
|
# 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 alignment reasons, prefer sizes which are multiples of 4096 bytes
|
|
|
|
#
|
|
|
|
: ${ROOT_SIZE=$(( 64*(2**20) / 512))}
|
|
|
|
: ${HOME_SIZE=$(( 128*(2**20) / 512))}
|
|
|
|
: ${USR_SIZE=$(( 1536*(2**20) / 512))}
|
|
|
|
|
2013-10-03 18:26:21 +02:00
|
|
|
if [ "x${ISOMODE}" = "x1" ]
|
2013-11-07 08:33:39 +01:00
|
|
|
then
|
|
|
|
# In iso mode, make all FSes fit (i.e. as small as possible), but
|
|
|
|
# leave some space on /
|
|
|
|
ROOTSIZEARG="-x 5"
|
|
|
|
else
|
|
|
|
# In hd image mode, FSes have fixed sizes
|
2013-11-05 15:43:44 +01:00
|
|
|
ROOTSIZEARG="-b $((${ROOT_SIZE} / 8))"
|
|
|
|
USRSIZEARG="-b $((${USR_SIZE} / 8))"
|
|
|
|
HOMESIZEARG="-b $((${HOME_SIZE} / 8))"
|
|
|
|
fi
|
|
|
|
|
2013-09-24 15:15:55 +02:00
|
|
|
echo "Writing Minix filesystem images"
|
2013-11-05 15:43:44 +01:00
|
|
|
|
2013-10-03 18:26:21 +02:00
|
|
|
#
|
2013-11-05 15:43:44 +01:00
|
|
|
# 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.
|
2013-10-03 18:26:21 +02:00
|
|
|
#
|
|
|
|
ROOT_START=${ISO_SIZE}
|
2013-11-07 08:33:39 +01:00
|
|
|
|
|
|
|
echo " - ROOT"
|
2013-10-03 18:26:21 +02:00
|
|
|
ROOT_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $ROOTSIZEARG -I $(($ROOT_START*512)) ${IMG} ${IMG_DIR}/root.proto`/512))
|
|
|
|
USR_START=$((${ROOT_START} + ${ROOT_SIZE}))
|
2013-11-07 08:33:39 +01:00
|
|
|
echo " - USR"
|
2013-10-03 18:26:21 +02:00
|
|
|
USR_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $USRSIZEARG -I $(($USR_START*512)) ${IMG} ${IMG_DIR}/usr.proto`/512))
|
|
|
|
HOME_START=$((${USR_START} + $USR_SIZE))
|
2013-11-07 08:33:39 +01:00
|
|
|
echo " - HOME"
|
2013-10-03 18:26:21 +02:00
|
|
|
HOME_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $HOMESIZEARG -I $(($HOME_START*512)) ${IMG} ${IMG_DIR}/home.proto`/512))
|
2013-09-24 15:15:55 +02:00
|
|
|
|
2013-11-07 08:33:39 +01:00
|
|
|
${CROSS_TOOLS}/nbpartition -m ${IMG} 0 81:${ISO_SIZE} 81:${ROOT_SIZE} 81:${USR_SIZE} 81:${HOME_SIZE}
|
2013-09-24 15:15:55 +02:00
|
|
|
|
2013-10-03 18:26:21 +02:00
|
|
|
mods="`( cd ${MODDIR}; echo mod* | tr ' ' ',' )`"
|
|
|
|
if [ "x${ISOMODE}" = "x1" ]
|
|
|
|
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}"
|
2013-11-05 15:43:44 +01:00
|
|
|
fi
|