From da7dc4d54caa3a22721cccbd93b0fc85e3a0091e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Boric Date: Tue, 6 Oct 2015 08:58:08 +0200 Subject: [PATCH] PXE boot generation script Leveraging the new image generation framework, MINIX has now turn-key PXE booting capability. The booting process uses SYSLINUX, licensed under GPL2+. Due to the lack of NFS support, a ramdisk is provided as a root device. The generated ramdisk is quite huge for a network boot, but it can be trimmed down at a later date. --- etc/rc | 14 +++-- minix/drivers/storage/ramdisk/rc | 17 ++++-- releasetools/fetch.functions | 58 +++++++++++++++++++++ releasetools/fetch_syslinux.sh | 8 +++ releasetools/fetch_u-boot.sh | 57 ++------------------ releasetools/image.defaults | 2 + releasetools/image.functions | 14 +++++ releasetools/release/pxe/etc/issue | 8 +++ releasetools/x86_pxeimage.sh | 83 ++++++++++++++++++++++++++++++ 9 files changed, 201 insertions(+), 60 deletions(-) create mode 100644 releasetools/fetch.functions create mode 100755 releasetools/fetch_syslinux.sh create mode 100644 releasetools/release/pxe/etc/issue create mode 100755 releasetools/x86_pxeimage.sh diff --git a/etc/rc b/etc/rc index d38ff0bf5..f9fcd2140 100755 --- a/etc/rc +++ b/etc/rc @@ -1,5 +1,10 @@ # /etc/rc - System startup script run by init before going multiuser. +if sysenv bootramdisk >/dev/null +then + /bin/sh /etc/rc.ramdisk +fi + # Are we booting from CD? bootcd="`/bin/sysenv bootcd`" @@ -138,9 +143,12 @@ autoboot|start) fsck -x / $fflag $fsckopts mount -a - # Unmount and free now defunct ramdisk - umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk" - ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk" + if [ -z "`sysenv bootramdisk`" ] + then + # Unmount and free now defunct ramdisk + umount /dev/imgrd > /dev/null || echo "Failed to unmount boot ramdisk" + ramdisk 0 /dev/imgrd || echo "Failed to free boot ramdisk" + fi # Initialize files. >/var/run/utmp # /etc/utmp keeps track of logins diff --git a/minix/drivers/storage/ramdisk/rc b/minix/drivers/storage/ramdisk/rc index 5849f8572..de2a3a6a8 100644 --- a/minix/drivers/storage/ramdisk/rc +++ b/minix/drivers/storage/ramdisk/rc @@ -55,7 +55,7 @@ fi if /bin/sysenv rootdevname >/dev/null then rootdevname=/dev/`/bin/sysenv rootdevname` else - if ! sysenv cdproberoot >/dev/null + if (! sysenv cdproberoot) && (! sysenv bootramdisk) >/dev/null then echo "rootdevname not set" exit 1 fi @@ -81,6 +81,11 @@ then loadramdisk "$ramimagename" || echo "WARNING: loadramdisk failed" fi +if sysenv bootramdisk >/dev/null +then + rootdevname=imgrd +fi + echo "Root device name is $rootdevname" if ! sysenv cdproberoot >/dev/null @@ -92,8 +97,14 @@ fi # Change root from temporary boot ramdisk to the configure # root device -/bin/mount -n $bin_img"$rootdevname" / +if ! sysenv bootramdisk >/dev/null +then + /bin/mount -n $bin_img"$rootdevname" / +fi /bin/mount -e -n -t procfs none /proc || echo "WARNING: couldn't mount procfs" -exec /bin/sh /etc/rc `sysenv bootopts` "$@" +if ! sysenv bootramdisk >/dev/null +then + exec /bin/sh /etc/rc `sysenv bootopts` "$@" +fi diff --git a/releasetools/fetch.functions b/releasetools/fetch.functions new file mode 100644 index 000000000..d0db41be0 --- /dev/null +++ b/releasetools/fetch.functions @@ -0,0 +1,58 @@ +#!/bin/sh +# +# Common logic to perform checkout of repos +# + +# -o output dir +OUTPUT_DIR="" +GIT_VERSION="" +while getopts "o:n:?" c +do + case "$c" in + \?) + echo "Usage: $0 -o output dir -n version " >&2 + exit 1 + ;; + o) + OUTPUT_DIR=$OPTARG + ;; + n) + GIT_VERSION=$OPTARG + ;; + esac +done + + +# +# check arguments +# +if [ -z "$OUTPUT_DIR" -o -z "$GIT_VERSION" ] +then + echo "Missing required parameters OUTPUT_DIR=$OUTPUT_DIR GIT_VERSION=$GIT_VERSION" + echo "Usage: $0 -o output dir -n version " >&2 + exit 1 +fi + + +# +# if the file doesn't exist it's easy , to a checkout +# +if [ ! -e "$OUTPUT_DIR" ] +then + git clone ${REPO_URL} -b minix $OUTPUT_DIR +fi + +( + cd "$OUTPUT_DIR" + + # + # perform an update + # + CURRENT_VERSION=`git rev-parse HEAD` + if [ "$CURRENT_VERSION" != "$GIT_VERSION" ] + then + echo "Current version $CURRENT_VERSION does not match wanted $GIT_VERSION performing update and checkout" + git fetch -v + git checkout $GIT_VERSION + fi +) diff --git a/releasetools/fetch_syslinux.sh b/releasetools/fetch_syslinux.sh new file mode 100755 index 000000000..8c39e8b5f --- /dev/null +++ b/releasetools/fetch_syslinux.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# Perform a checkout / update the MINIX PXELINUX git repo if needed +# + +: ${REPO_URL=https://github.com/boricj/syslinux.git} + +. releasetools/fetch.functions diff --git a/releasetools/fetch_u-boot.sh b/releasetools/fetch_u-boot.sh index 5531cd5b8..02a489e3b 100755 --- a/releasetools/fetch_u-boot.sh +++ b/releasetools/fetch_u-boot.sh @@ -1,59 +1,8 @@ -#!/bin/sh +#!/bin/sh # # Perform a checkout / update the MINIX u-boot git repo if needed -# -: ${UBOOT_REPO_URL=git://git.minix3.org/u-boot} - -# -o output dir -OUTPUT_DIR="" -GIT_VERSION="" -while getopts "o:n:?" c -do - case "$c" in - \?) - echo "Usage: $0 -o output dir -n version " >&2 - exit 1 - ;; - o) - OUTPUT_DIR=$OPTARG - ;; - n) - GIT_VERSION=$OPTARG - ;; - esac -done - - # -# check arguments -# -if [ -z "$OUTPUT_DIR" -o -z "$GIT_VERSION" ] -then - echo "Missing required parameters OUTPUT_DIR=$OUTPUT_DIR GIT_VERSION=$GIT_VERSION" - echo "Usage: $0 -o output dir -n version " >&2 - exit 1 -fi +: ${REPO_URL=git://git.minix3.org/u-boot} -# -# if the file doesn't exist it's easy , to a checkout -# -if [ ! -e "$OUTPUT_DIR" ] -then - git clone ${UBOOT_REPO_URL} -b minix $OUTPUT_DIR -fi - -( - cd "$OUTPUT_DIR" - - # - # perform an update - # - CURRENT_VERSION=`git rev-parse HEAD` - if [ "$CURRENT_VERSION" != "$GIT_VERSION" ] - then - echo "Current version $CURRENT_VERSION does not match wanted $GIT_VERSION performing update and checkout" - git fetch -v - git checkout $GIT_VERSION - fi -) +. releasetools/fetch.functions diff --git a/releasetools/image.defaults b/releasetools/image.defaults index 4a69d0303..b035dbe8b 100644 --- a/releasetools/image.defaults +++ b/releasetools/image.defaults @@ -18,3 +18,5 @@ : ${RC=../local/rc.${ARCH}} : ${ASR_HACK=0} + +: ${SYSLINUX_GIT_VERSION=d00acec90ccc5e05e5b80bfd96d17c4dc4a7d36e} diff --git a/releasetools/image.functions b/releasetools/image.functions index 5aa581b11..ac4948c77 100644 --- a/releasetools/image.functions +++ b/releasetools/image.functions @@ -184,6 +184,20 @@ create_protos() done } +# +# Create ramdisk image from root directory +# +# $1 : size of ramdisk +create_ramdisk_image() +{ + PATH=$(cd ${CROSS_TOOLS}; pwd):$PATH + + # Build image + _RAMDISKSIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d -b $1 -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) # diff --git a/releasetools/release/pxe/etc/issue b/releasetools/release/pxe/etc/issue new file mode 100644 index 000000000..fbbb52dd8 --- /dev/null +++ b/releasetools/release/pxe/etc/issue @@ -0,0 +1,8 @@ + +Welcome to MINIX. + +The system is now running and many commands work normally. To use MINIX +in a serious way, you need to install it to your hard disk. + +Type "root" at the login prompt, and hit enter. +Note: the setup script can't be used when booting over the network. diff --git a/releasetools/x86_pxeimage.sh b/releasetools/x86_pxeimage.sh new file mode 100755 index 000000000..76c4fdc16 --- /dev/null +++ b/releasetools/x86_pxeimage.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +set -e + +# +# This script creates a bootable image and should at some point in the future +# be replaced by the proper NetBSD infrastructure. +# + +: ${ARCH=i386} +: ${OBJ=../obj.${ARCH}} +: ${TOOLCHAIN_TRIPLET=i586-elf32-minix-} +: ${BUILDSH=build.sh} + +: ${SETS="minix-base"} +: ${IMG=minix_x86_usb.img} + +if [ ! -f ${BUILDSH} ] +then + echo "Please invoke me from the root source dir, where ${BUILDSH} is." + exit 1 +fi + +# set up disk creation environment +. releasetools/image.defaults +. releasetools/image.functions + +: ${RAMDISK_SIZE=$(( 200*(2**20) / 512 / 8 ))} + +# where the kernel & boot modules will be +MODDIR=${DESTDIR}/boot/minix/.temp + +echo "Fetching syslinux..." +${RELEASETOOLSDIR}/fetch_syslinux.sh -o ${RELEASETOOLSDIR}/syslinux -n $SYSLINUX_GIT_VERSION + +echo "Building work directory..." +build_workdir "$SETS" + +echo "Adding extra files..." + +# create a fstab entry in /etc +cat >${ROOT_DIR}/etc/fstab <${WORK_DIR}/pxelinux.cfg/default <