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.
This commit is contained in:
Jean-Baptiste Boric 2015-10-06 08:58:08 +02:00
parent 135965dc20
commit da7dc4d54c
9 changed files with 201 additions and 60 deletions

14
etc/rc
View File

@ -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

View File

@ -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

View File

@ -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
)

8
releasetools/fetch_syslinux.sh Executable file
View File

@ -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

View File

@ -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

View File

@ -18,3 +18,5 @@
: ${RC=../local/rc.${ARCH}}
: ${ASR_HACK=0}
: ${SYSLINUX_GIT_VERSION=d00acec90ccc5e05e5b80bfd96d17c4dc4a7d36e}

View File

@ -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)
#

View File

@ -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.

83
releasetools/x86_pxeimage.sh Executable file
View File

@ -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 <<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
cp minix/drivers/storage/ramdisk/rc ${ROOT_DIR}/etc/rc.ramdisk
add_file_spec "etc/rc.ramdisk" extra.fstab
cp releasetools/release/pxe/etc/issue ${ROOT_DIR}/etc/issue
add_file_spec "etc/issue" extra.cdfiles
echo "Bundling packages..."
bundle_packages "$BUNDLE_PACKAGES"
echo "Creating specification files..."
create_input_spec
create_protos
echo "Writing ramdisk image..."
cp ${MODDIR}/* ${WORK_DIR}
create_ramdisk_image ${RAMDISK_SIZE}
echo "Preparing PXE boot directory..."
mkdir ${WORK_DIR}/pxelinux.cfg
cat >${WORK_DIR}/pxelinux.cfg/default <<EOF
DEFAULT menu.c32
TIMEOUT 100
LABEL x86
MENU LABEL Minix3
KERNEL mboot.c32
APPEND kernel bootramdisk=1 --- mod01_ds --- mod02_rs --- mod03_pm --- mod04_sched --- mod05_vfs --- mod06_memory --- mod07_tty --- mod08_mib --- mod09_vm --- mod10_pfs --- mod11_mfs --- mod12_init
EOF
cp ${RELEASETOOLSDIR}/syslinux/bios/com32/elflink/ldlinux/ldlinux.c32 ${WORK_DIR}/
cp ${RELEASETOOLSDIR}/syslinux/bios/com32/lib/libcom32.c32 ${WORK_DIR}/
cp ${RELEASETOOLSDIR}/syslinux/bios/com32/libutil/libutil.c32 ${WORK_DIR}/
cp ${RELEASETOOLSDIR}/syslinux/bios/com32/mboot/mboot.c32 ${WORK_DIR}/
cp ${RELEASETOOLSDIR}/syslinux/bios/com32/menu/menu.c32 ${WORK_DIR}/
cp ${RELEASETOOLSDIR}/syslinux/bios/core/pxelinux.0 ${WORK_DIR}/
rm -rf ${WORK_DIR}/extra.* ${WORK_DIR}/set.* ${WORK_DIR}/proto.* ${WORK_DIR}/imgrd.mfs ${WORK_DIR}/imgrd.o
echo "PXE boot directory at ${WORK_DIR}"
echo "To boot this image on kvm:"
echo "cd ${WORK_DIR} && qemu-system-i386 --enable-kvm -m 512M -tftp . -bootp pxelinux.0 -boot n"