From 09143af258b10a1fef85aad285fb5d5f673d2283 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Tue, 5 Nov 2013 15:43:44 +0100 Subject: [PATCH] x86_hdimage.sh -i: crossbuild x86 release CD . build writeisofs as a native tool too for it . also mkfs.mfs: make missing file in proto nonlethal . make setup script a little more self-sufficient . hdboot: use INSTALL_FILE instead of INSTALL so that the results get added to the METALOG Change-Id: Id233e4c861f81046bf6c4be0510b8a3bf39ff9be --- commands/setup/setup.sh | 52 ++++++--------- commands/writeisofs/Makefile | 2 + commands/writeisofs/writeisofs.c | 2 +- releasetools/Makefile | 5 +- releasetools/x86_hdimage.sh | 109 +++++++++++++++++++++---------- tools/Makefile | 3 +- tools/writeisofs/Makefile | 4 ++ usr.sbin/mkfs.mfs/mkfs.c | 3 +- 8 files changed, 109 insertions(+), 71 deletions(-) create mode 100644 tools/writeisofs/Makefile diff --git a/commands/setup/setup.sh b/commands/setup/setup.sh index ed276bd62..fe9cf5fca 100644 --- a/commands/setup/setup.sh +++ b/commands/setup/setup.sh @@ -13,42 +13,22 @@ MYLOCALRC=/mnt/etc/rc.local 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 @@ -729,6 +709,7 @@ cpdir -vx / /mnt | progressbar "$ROOTFILES" || exit 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 @@ -748,7 +729,16 @@ mount /dev/$usr /mnt/usr >/dev/null || exit # 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 diff --git a/commands/writeisofs/Makefile b/commands/writeisofs/Makefile index 001a6a161..eb0dfb14a 100644 --- a/commands/writeisofs/Makefile +++ b/commands/writeisofs/Makefile @@ -1,4 +1,6 @@ PROG= writeisofs MAN= +CPPFLAGS+= -I${NETBSDSRCDIR}/include/arch/${MACHINE_ARCH}/include + .include diff --git a/commands/writeisofs/writeisofs.c b/commands/writeisofs/writeisofs.c index 77aaad867..a5cefc557 100644 --- a/commands/writeisofs/writeisofs.c +++ b/commands/writeisofs/writeisofs.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include diff --git a/releasetools/Makefile b/releasetools/Makefile index 429caa327..765298dc3 100644 --- a/releasetools/Makefile +++ b/releasetools/Makefile @@ -93,7 +93,8 @@ do-hdboot: n=`expr $$n + 1`; \ [ "$$n" -ge 10 ] && prefix="mod" || prefix="mod0"; \ newname="${DESTDIR}/boot/minix/.temp/$${prefix}$${n}_`basename $$i`"; \ - ${INSTALL} $$i $$newname; \ + ${INSTALL_FILE} $$i $$newname; \ + echo ${INSTALL_FILE} $$i $$newname; \ done @cp ${PROGROOT}/kernel/kernel ${DESTDIR}/boot/minix/.temp/ @if [ "${MKINSTALLBOOT:Uno}" != "no" ] ; then \ @@ -103,7 +104,7 @@ do-hdboot: ${HOST_SH} ../commands/update_bootcfg/update_bootcfg.sh;\ else \ ${INSTALL_DIR} ${DESTDIR}/multiboot; \ - ${INSTALL} ${DESTDIR}/boot/minix/.temp/* ${DESTDIR}/multiboot; \ + ${INSTALL_FILE} ${DESTDIR}/boot/minix/.temp/* ${DESTDIR}/multiboot; \ fi # download and update NetBSD reference sources. diff --git a/releasetools/x86_hdimage.sh b/releasetools/x86_hdimage.sh index 1f4bd14bf..869bb0644 100755 --- a/releasetools/x86_hdimage.sh +++ b/releasetools/x86_hdimage.sh @@ -11,11 +11,15 @@ set -e : ${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." @@ -27,7 +31,19 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH # # 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 @@ -35,16 +51,25 @@ mkdir -p $IMG_DIR 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))} @@ -54,8 +79,8 @@ sh ${BUILDSH} -V SLOPPY_FLIST=yes -V MKBINUTILS=yes -V MKGCCCMDS=yes -j ${JOBS} # setup phase on x86 # cat >${FSTAB} </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 @@ -124,26 +133,58 @@ rm ${IMG_DIR}/root.in 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 diff --git a/tools/Makefile b/tools/Makefile index 8b19f3979..adecc7c6c 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -77,7 +77,8 @@ SUBDIR= host-mkdep .WAIT compat .WAIT \ file \ .WAIT \ pwd_mkdb stat zic \ - partition + partition \ + writeisofs .if ${MKLLVM} != "no" # .WAIT between llvm-tblgen and llvm-clang-tblgen ensures install diff --git a/tools/writeisofs/Makefile b/tools/writeisofs/Makefile new file mode 100644 index 000000000..5535af993 --- /dev/null +++ b/tools/writeisofs/Makefile @@ -0,0 +1,4 @@ +HOSTPROGNAME= ${_TOOL_PREFIX}writeisofs +HOST_SRCDIR= commands/writeisofs + +.include "${.CURDIR}/../Makefile.host" diff --git a/usr.sbin/mkfs.mfs/mkfs.c b/usr.sbin/mkfs.mfs/mkfs.c index 1806b8007..d732b4eac 100644 --- a/usr.sbin/mkfs.mfs/mkfs.c +++ b/usr.sbin/mkfs.mfs/mkfs.c @@ -494,8 +494,7 @@ sizeup_dir(struct fs_size * fssize) fssize->zonecount++; /* Symlink contents is always stored a block */ } else { if ((f = fopen(token[4], "rb")) == NULL) { - pexit("dynamic size detection failed: can't open %s", - token[4]); + warn("dynamic sizing: can't open %s", token[4]); } else if (fseek(f, 0, SEEK_END) < 0) { pexit("dynamic size detection failed: seek to end of %s", token[4]); -- 2.44.0