Scripts for generating boot-to-ramdisk images are now available. These can be used for example to boot from PXE or from a USB stick, as the ramdisk are self-contained and do not rely on any block devices after being loaded into RAM. The image generation framework has also been slightly cleaned up in order to better accomodate tarball sets bundling in images. Change-Id: I65a176832bd0d6954b430fa8305f90af0bd606c1
445 lines
12 KiB
Plaintext
445 lines
12 KiB
Plaintext
|
|
#
|
|
# spec file handling
|
|
#
|
|
|
|
#
|
|
# Add a directory to a spec file
|
|
#
|
|
# $1 : directory to add
|
|
# $2 : spec file
|
|
add_dir_spec()
|
|
{
|
|
echo "./$1 type=dir uid=0 gid=0 mode=0755" >> ${WORK_DIR}/$2
|
|
}
|
|
|
|
#
|
|
# Add a file to a spec file
|
|
#
|
|
# $1 : file to add
|
|
# $2 : spec file
|
|
add_file_spec()
|
|
{
|
|
echo "./$1 type=file uid=0 gid=0 mode=0755 size=$(wc -c < ${ROOT_DIR}/${1})" >> ${WORK_DIR}/$2
|
|
}
|
|
|
|
#
|
|
# Add a symbolic link to a spec file
|
|
#
|
|
# $1 : symlink to add
|
|
# $2 : link to
|
|
# $3 : spec file
|
|
add_link_spec()
|
|
{
|
|
echo "./$1 type=link uid=0 gid=0 mode=0755 link=$2" >> ${WORK_DIR}/$3
|
|
}
|
|
|
|
#
|
|
# workdir handling
|
|
#
|
|
|
|
#
|
|
# Create the workdir (a directory where Minix is built using sets)
|
|
# spec files are put in WORK_DIR, the file system created in ROOT_DIR
|
|
#
|
|
# $1 : sets to extract
|
|
build_workdir()
|
|
{
|
|
# Extract sets
|
|
mkdir -p ${ROOT_DIR}
|
|
for set in $1; do
|
|
if [ ! -e ${SETS_DIR}/${set}.tgz ]; then
|
|
echo "Missing ${SETS_DIR}/${set}.tgz, aborting"
|
|
echo "Are the release sets tarballs created?"
|
|
exit 1
|
|
fi
|
|
echo " * Extracting $set..."
|
|
(cd ${ROOT_DIR}; ${CROSS_TOOLS}/nbpax -rnz -f ${SETS_DIR}/${set}.tgz .)
|
|
done
|
|
|
|
# add rc (if any)
|
|
if [ -f ${RC} ]; then
|
|
cp ${RC} ${ROOT_DIR}/usr/etc/rc.local
|
|
fi
|
|
|
|
# Build login/password files
|
|
${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${ROOT_DIR} ${ROOT_DIR}/etc/master.passwd
|
|
|
|
# Build specifications files
|
|
cp ${ROOT_DIR}/etc/mtree/set* ${WORK_DIR}
|
|
${ROOT_DIR}/usr/bin/MAKEDEV -s -m all >> ${WORK_DIR}/extra.dev
|
|
|
|
if [ ${BUNDLE_SETS} -eq 1 ]
|
|
then
|
|
echo " * Bundling sets..."
|
|
workdir_add_sets
|
|
fi
|
|
}
|
|
|
|
#
|
|
# Add tarball sets to the workdir (for installation CD)
|
|
#
|
|
workdir_add_sets()
|
|
{
|
|
# Add sets to the root
|
|
mkdir -p ${ROOT_DIR}/usr/${ARCH}/binary/sets;
|
|
add_dir_spec "usr/${ARCH}" extra.sets
|
|
add_dir_spec "usr/${ARCH}/binary" extra.sets
|
|
add_dir_spec "usr/${ARCH}/binary/sets" extra.sets
|
|
|
|
add_link_spec "${ARCH}" "usr/${ARCH}" extra.sets
|
|
|
|
DEST_SETS_DIR="usr/${ARCH}/binary/sets"
|
|
for set in ${SETS_DIR}/*.tgz; do
|
|
# Copy set itself
|
|
cp ${set} ${ROOT_DIR}/${DEST_SETS_DIR}
|
|
add_file_spec "${DEST_SETS_DIR}/$(basename ${set})" extra.sets
|
|
|
|
# Add file count
|
|
COUNT_SRC=$(echo $(basename ${set}) | sed -e "s/\(.*\)\.tgz/\set.\1/")
|
|
COUNT_NAME=$(echo $(basename ${set}) | sed -e "s/\.tgz/\.count/")
|
|
if [ -e "${DESTDIR}/etc/mtree/${COUNT_SRC}" ]
|
|
then
|
|
wc -l < ${DESTDIR}/etc/mtree/${COUNT_SRC} > ${ROOT_DIR}/${DEST_SETS_DIR}/${COUNT_NAME}
|
|
else
|
|
# Can't find mtree file, set bogus number
|
|
echo 1 > ${ROOT_DIR}/${DEST_SETS_DIR}/${COUNT_NAME}
|
|
fi
|
|
add_file_spec "${DEST_SETS_DIR}/${COUNT_NAME}" extra.sets
|
|
|
|
# Add file sizes
|
|
SIZE_NAME=$(echo $(basename ${set}) | sed -e "s/\.tgz/\.size/")
|
|
${CROSS_TOOLS}/nbpax -zvf ${set} . |grep -v 'bytes written in 1 secs [(]' | ${CROSS_TOOLS}/nbawk '{s+=$5} END{print s}' > ${ROOT_DIR}/${DEST_SETS_DIR}/${SIZE_NAME}
|
|
add_file_spec "${DEST_SETS_DIR}/${SIZE_NAME}" extra.sets
|
|
done
|
|
|
|
# Add checksums
|
|
cp ${SETS_DIR}/MD5 ${ROOT_DIR}/${DEST_SETS_DIR}
|
|
add_file_spec "${DEST_SETS_DIR}/MD5" extra.sets
|
|
cp ${SETS_DIR}/SHA512 ${ROOT_DIR}/${DEST_SETS_DIR}
|
|
add_file_spec "${DEST_SETS_DIR}/SHA512" extra.sets
|
|
}
|
|
|
|
#
|
|
# Add HDD files to the workdir
|
|
#
|
|
workdir_add_hdd_files()
|
|
{
|
|
# create a fstab entry in /etc
|
|
cat >${ROOT_DIR}/etc/fstab <<END_FSTAB
|
|
/dev/c0d0p1 /usr mfs rw 0 2
|
|
/dev/c0d0p2 /home mfs rw 0 2
|
|
none /sys devman rw,rslabel=devman 0 0
|
|
none /dev/pts ptyfs rw,rslabel=ptyfs 0 0
|
|
END_FSTAB
|
|
add_file_spec "etc/fstab" extra.fstab
|
|
|
|
# Add boot monitor
|
|
cp ${DESTDIR}/usr/mdec/boot_monitor ${ROOT_DIR}/boot_monitor
|
|
add_file_spec "boot_monitor" extra.boot
|
|
}
|
|
|
|
#
|
|
# Add CD boot files to the workdir
|
|
#
|
|
workdir_add_cd_files()
|
|
{
|
|
# create a fstab entry in /etc
|
|
cat >${ROOT_DIR}/etc/fstab <<END_FSTAB
|
|
none /sys devman rw,rslabel=devman 0 0
|
|
none /dev/pts ptyfs rw,rslabel=ptyfs 0 0
|
|
END_FSTAB
|
|
add_file_spec "etc/fstab" extra.fstab
|
|
|
|
# Add boot monitor
|
|
cp ${DESTDIR}/usr/mdec/boot_monitor ${ROOT_DIR}/minixboot
|
|
add_file_spec "minixboot" extra.cdfiles
|
|
|
|
# Add README
|
|
cp releasetools/release/cd/README.TXT ${ROOT_DIR}/README.TXT
|
|
add_file_spec "README.TXT" extra.cdfiles
|
|
}
|
|
|
|
#
|
|
# Add ramdisk files to the workdir
|
|
#
|
|
workdir_add_ramdisk_files()
|
|
{
|
|
# create a fstab entry in /etc
|
|
cat >${ROOT_DIR}/etc/fstab <<END_FSTAB
|
|
none /sys devman rw,rslabel=devman 0 0
|
|
none /dev/pts ptyfs rw,rslabel=ptyfs 0 0
|
|
END_FSTAB
|
|
add_file_spec "etc/fstab" extra.fstab
|
|
|
|
# add early boot rc script
|
|
cp minix/drivers/storage/ramdisk/rc ${ROOT_DIR}/etc/rc.ramdisk
|
|
add_file_spec "etc/rc.ramdisk" extra.fstab
|
|
|
|
# Add README
|
|
cp releasetools/release/cd/README.TXT ${ROOT_DIR}/README.TXT
|
|
add_file_spec "README.TXT" extra.cdfiles
|
|
}
|
|
|
|
#
|
|
# Extract kernel to designated directory
|
|
#
|
|
# $1: Directory where to extract
|
|
workdir_add_kernel()
|
|
{
|
|
(cd ${ROOT_DIR}; ${CROSS_TOOLS}/nbpax -rnz -f ${SETS_DIR}/minix-kernel.tgz .)
|
|
|
|
# Move kernel files to the correct directory
|
|
if [ ! -d ${ROOT_DIR}/boot/$1 ]
|
|
then
|
|
mkdir -p ${ROOT_DIR}/boot/$1
|
|
add_dir_spec "boot/$1" extra.kernel
|
|
fi
|
|
|
|
mv ${ROOT_DIR}/boot/minix/.temp/* ${ROOT_DIR}/boot/$1
|
|
rm -rf ${ROOT_DIR}/boot/minix/.temp
|
|
for i in $(cd ${ROOT_DIR}/boot/$1 && echo *)
|
|
do
|
|
add_file_spec "boot/$1/$i" extra.kernel
|
|
done
|
|
}
|
|
|
|
#
|
|
# Read METALOG and use mtree to convert the user and group names into uid and gids.
|
|
# Used as the reference mtree for building file systems.
|
|
#
|
|
create_input_spec()
|
|
{
|
|
cat ${WORK_DIR}/set* ${WORK_DIR}/extra* | ${CROSS_TOOLS}/nbmtree -N ${ROOT_DIR}/etc -C -K device > ${WORK_DIR}/input
|
|
|
|
if [ ${ASR_HACK} -eq 1 ]
|
|
then
|
|
# Hacky workaround for ASR-randomized service binaries since they don't get nicely packaged in a tarball
|
|
# add any generated ASR-randomized service binaries
|
|
# TODO: apply stricter file permissions for both these and the base /service binaries, against local attacks
|
|
(cd ${DESTDIR} && find ./usr/service/asr -type f | sed 's/$/ type=file uid=0 gid=0 mode=0755/') >> ${WORK_DIR}/input
|
|
cp -r ${DESTDIR}/usr/service/asr ${ROOT_DIR}/usr/service
|
|
fi
|
|
}
|
|
|
|
#
|
|
# Split mtree into partitions and create proto files for nbmkfs.mfs
|
|
#
|
|
# $1 : partitions to create (example: usr home)
|
|
create_protos()
|
|
{
|
|
# build filter
|
|
FILTER_COMMAND="cat ${WORK_DIR}/input"
|
|
for i in $1
|
|
do
|
|
FILTER_COMMAND="$FILTER_COMMAND | grep -v \"^./$i/\" "
|
|
done
|
|
|
|
# fill root.img (skipping entries inside partitions while keeping partition mount points)
|
|
eval $FILTER_COMMAND | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR} -o ${WORK_DIR}/proto.root
|
|
|
|
# create proto files for partitions using toproto
|
|
for i in $1
|
|
do
|
|
cat ${WORK_DIR}/input | grep "^\./$i/\|^. " | sed "s,\./$i,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR}/$i -o ${WORK_DIR}/proto.$i
|
|
done
|
|
}
|
|
|
|
#
|
|
# Create ramdisk image from root directory
|
|
#
|
|
# $1 : size of ramdisk (optional)
|
|
create_ramdisk_image()
|
|
{
|
|
PATH=$(cd ${CROSS_TOOLS}; pwd):$PATH
|
|
if [ -z $1 ]
|
|
then
|
|
RAMSIZE="-x 5"
|
|
else
|
|
RAMSIZE="-b $(( $1 / 512 / 8))"
|
|
fi
|
|
|
|
# Build image
|
|
_RAMDISKSIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${RAMSIZE} -I 0 ${WORK_DIR}/imgrd.mfs ${WORK_DIR}/proto.root)
|
|
(cd ${WORK_DIR}; ${TOOLCHAIN_TRIPLET}objcopy -Ibinary -Bi386 -Oi586-elf32-minix imgrd.mfs imgrd.o)
|
|
${TOOLCHAIN_TRIPLET}clang --sysroot=${DESTDIR} -L ${DESTDIR}/usr/lib -static -o ${WORK_DIR}/mod06_memory ${OBJ}/minix/drivers/storage/memory/memory.o ${WORK_DIR}/imgrd.o -nodefaultlibs -lblockdriver -lchardriver -lsys -lminc
|
|
}
|
|
|
|
#
|
|
# Bundle packages (won't preinstall them)
|
|
#
|
|
# $1 : packages to bundle
|
|
bundle_packages()
|
|
{
|
|
if [ -z "$1" ]
|
|
then
|
|
return
|
|
fi
|
|
|
|
if [ -z $PACKAGE_DIR ]
|
|
then
|
|
echo "Error: PACKAGE_DIR is not set while trying to bundle packages."
|
|
echo "Please fetch binary packages to bundle and set PACKAGE_DIR to continue."
|
|
exit 1
|
|
fi
|
|
|
|
DESTPACKAGES="usr/packages/$RELEASE_VERSION/$ARCH/All"
|
|
RELEASEPACKAGE="${ROOT_DIR}/$DESTPACKAGES"
|
|
index=pkg_summary
|
|
|
|
# create directories
|
|
mkdir -p $RELEASEPACKAGE
|
|
add_dir_spec "usr/packages" extra.pkgsrc
|
|
add_dir_spec "usr/packages/$RELEASE_VERSION" extra.pkgsrc
|
|
add_dir_spec "usr/packages/$RELEASE_VERSION/$ARCH" extra.pkgsrc
|
|
add_dir_spec "usr/packages/$RELEASE_VERSION/$ARCH/All" extra.pkgsrc
|
|
add_link_spec "packages" "usr/packages" extra.pkgsrc
|
|
for pkgprefix in $1
|
|
do
|
|
realfn=$(echo $PACKAGE_DIR/${pkgprefix}*.tgz | cut -d' ' -f1)
|
|
if [ -f "$realfn" ]
|
|
then
|
|
# Copy package
|
|
p="$(basename $realfn)"
|
|
echo " * Bundling $p..."
|
|
cp "$realfn" "$RELEASEPACKAGE/$p"
|
|
add_file_spec "$DESTPACKAGES/$p" extra.pkgsrc
|
|
else
|
|
echo "Error: Can't find $pkgprefix in directory $PACKAGE_DIR for bundling package."
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
if [ -x "$(which $PKG_INFO)" ]
|
|
then
|
|
# Create packages index
|
|
echo " * Generating package index..."
|
|
indexname=$indexpath/$p.$index
|
|
$PKG_INFO -X $RELEASEPACKAGE/*.tgz >> $RELEASEPACKAGE/$index
|
|
|
|
# Compress index
|
|
echo " * Compressing index..."
|
|
bzip2 -f $RELEASEPACKAGE/$index
|
|
add_file_spec "$DESTPACKAGES/$index.bz2" extra.pkgsrc
|
|
else
|
|
echo " * Skipping package index generation."
|
|
echo " PKG_INFO ("$(which $PKG_INFO)") not executable."
|
|
fi
|
|
}
|
|
|
|
#
|
|
# stuff executed automatically to set up environment
|
|
#
|
|
|
|
usage()
|
|
{
|
|
echo "Usage: $0 [options]"
|
|
echo " -X xsrc Build with X11 located in \"xsrc\""
|
|
echo " -x Add X11 sets to extraction list"
|
|
echo " -b Add ASR service binaries to the image"
|
|
echo " (said binaries must be built beforehand)"
|
|
echo ""
|
|
echo "Environment variables:"
|
|
echo " CREATE_IMAGE_ONLY If set to 1, skip invocation of build.sh (default: 0)"
|
|
echo " JOBS Number of CPUs to use for build.sh to use (default: 1)"
|
|
echo " SETS Sets to extract for image (default: depends on script)"
|
|
echo " BUILDVARS Extra options passed to build.sh (default: none)"
|
|
echo ""
|
|
echo " PACKAGE_DIR Path to packages to bundle (default: none)"
|
|
echo " BUNDLE_PACKAGES List of packages to bundle (default: none)"
|
|
echo " PKG_INFO Path to 'pkg_info' for bundling (default: pkg_info)"
|
|
echo ""
|
|
echo " BUNDLE_SETS If set to 1, bundle sets for setup (default: only for CD)"
|
|
}
|
|
|
|
# parse options
|
|
while getopts "ixX:bh" c
|
|
do
|
|
case "$c" in
|
|
i) echo "This method of generating the ISO installation media is obsolete."
|
|
echo "Run ./releasetools/x86_cdimage.sh instead."
|
|
exit 1;;
|
|
|
|
x) SETS="$SETS xbase xcomp xetc xfont xserver";;
|
|
|
|
X) MKX11=yes
|
|
export MKX11
|
|
BUILDVARS="$BUILDVARS -X $OPTARG";;
|
|
|
|
b) # bitcode build: increase partition sizes
|
|
ROOT_SIZE="$((${ROOT_SIZE} + 192*(2**20)))"
|
|
USR_SIZE="$((${USR_SIZE} + 256*(2**20)))"
|
|
ASR_HACK=1;;
|
|
|
|
h) usage
|
|
exit 0;;
|
|
|
|
:) usage
|
|
exit 2;;
|
|
|
|
\?)
|
|
usage
|
|
exit 2;;
|
|
esac
|
|
done
|
|
|
|
#
|
|
# Are we going to build the minix sources?
|
|
#
|
|
|
|
if [ ${CREATE_IMAGE_ONLY} -eq 1 ]
|
|
then
|
|
if [ ! -d ${DESTDIR} ]
|
|
then
|
|
echo "Minix source code doesn't appear to have been built."
|
|
echo "Please try with \$CREATE_IMAGE_ONLY set to 0."
|
|
exit 1
|
|
fi
|
|
if [ ! -d ${RELEASEDIR} ]
|
|
then
|
|
echo "Minix release tarball sets don't appear to have been created."
|
|
echo "Please try with \$CREATE_IMAGE_ONLY set to 0."
|
|
exit 1
|
|
fi
|
|
# FIXME: this won't change anything for tarballs
|
|
#${CROSS_TOOLS}/nbmake-i386 -C releasetools do-hdboot
|
|
else
|
|
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.
|
|
#
|
|
sh ${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u release
|
|
|
|
fi
|
|
|
|
# sanity check
|
|
if [ -d "${WORK_DIR}/.git" ]
|
|
then
|
|
echo "WORK_DIR directory has a Git repository in it, abort!"
|
|
exit 1
|
|
fi
|
|
|
|
# clean working directory
|
|
if [ -e "${WORK_DIR}" ]
|
|
then
|
|
rm -rf "${WORK_DIR}"
|
|
fi
|
|
mkdir -p ${WORK_DIR}
|
|
|
|
# get absolute paths to those directories
|
|
CROSS_TOOLS=$(cd ${CROSS_TOOLS} && pwd)
|
|
DESTDIR=$(cd ${DESTDIR} && pwd)
|
|
MODDIR=$(cd ${MODDIR} && pwd)
|
|
OBJ=$(cd ${OBJ} && pwd)
|
|
SETS_DIR=$(cd ${SETS_DIR} && pwd)
|
|
WORK_DIR=$(cd ${WORK_DIR} && pwd)
|
|
ROOT_DIR=${WORK_DIR}/fs
|
|
|
|
# get list of mods
|
|
mods="`( cd ${MODDIR}; echo mod* | tr ' ' ',' )`"
|