From 929fc52ac978aecd2189ee86485da19eafc68869 Mon Sep 17 00:00:00 2001 From: imp Date: Thu, 1 May 2014 00:31:19 +0000 Subject: [PATCH] MFC: r258705,r258709,r263140,r263184,r263185,r263186,r263187,r263188, r263189,r263190,r263192,r263193,r263287,r263288,r263890,r264281, r264655,r264656,r264856,r264857,r264858,r264859,r264860,r264861, r264891,r264892,r264909 Catch up on all the referenced changes in -current, in brief: r258705 | n_hibma | Use NANO_PMAKE for build, but not install r258709 | mr | pkgng goo + bootstrap r263140 | glebius | Axe IPX. r263184 | imp | Fix build with spaces in names. r263185 | imp | Make pcengines config files compile again. r263186 | imp | Use UFS2 by default, but allow fallback to UFS1 r263187 | imp | Print an error message when we exit out early. r263188 | imp | Sometimes only copy MBR when backing via swap r263189 | imp | Update save_cfg r263190 | imp | Be more explicit about setting SRCCONF to /dev/null r263192 | imp | Rely on default UFS type r263193 | imp | Remove TARGET_BIG_ENDIAN. It's no longer relevant. r263287 | bdrewery | pkg(8) has no limits r263288 | bdrewery | Remove comment meant for removal in r263287 r263890 | imp | Up default media size to 1GB. r264281 | imp | Ignore .hg and .git files r264655 | imp | rm -x for safety r264656 | imp | new example: dhcpd derived from FreeNAS/BSDRP r264856 | imp | Override the parallel make target to use all CPUs. r264857 | imp | No need for true here, remove it. r264858 | imp | NANO_PKG_META_BASE r264859 | imp | stylize umount hack r264860 | imp | switch dhcpd to pkg(8). r264861 | imp | CR and CR0 added from dhcpd r264891 | imp | Try to alwaays use () for functions r264892 | imp | bash whines about r264857, revert r264909 | imp | Move back to {} for functions that need global effects git-svn-id: svn://svn.freebsd.org/base/stable/10@265166 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- tools/tools/nanobsd/Files/root/save_cfg | 80 ++++++- tools/tools/nanobsd/dhcpd/README | 14 ++ tools/tools/nanobsd/dhcpd/common | 280 ++++++++++++++++++++++ tools/tools/nanobsd/dhcpd/os-base | 194 +++++++++++++++ tools/tools/nanobsd/gateworks/common | 1 - tools/tools/nanobsd/nanobsd.sh | 192 ++++++++++++--- tools/tools/nanobsd/pcengines/ALIX_DSK | 8 +- tools/tools/nanobsd/pcengines/common.conf | 7 +- 8 files changed, 730 insertions(+), 46 deletions(-) create mode 100644 tools/tools/nanobsd/dhcpd/README create mode 100644 tools/tools/nanobsd/dhcpd/common create mode 100644 tools/tools/nanobsd/dhcpd/os-base diff --git a/tools/tools/nanobsd/Files/root/save_cfg b/tools/tools/nanobsd/Files/root/save_cfg index 19f11950c..a41f8dff7 100644 --- a/tools/tools/nanobsd/Files/root/save_cfg +++ b/tools/tools/nanobsd/Files/root/save_cfg @@ -1,6 +1,7 @@ #!/bin/sh # # Copyright (c) 2006 Mathieu Arnold +# Copyright (c) 2010 Alex Bakhtin # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -32,11 +33,86 @@ set -e trap "umount /cfg" 1 2 15 EXIT mount /cfg ( +cd /etc +for filename in "$@" `find * -type f` +do + if [ ! -f /cfg/$filename -a ! -f /cfg/.ignore/$filename ] + then + + # + # If file doesn't exist in /cfg and file is not in the 'ignore' list + # then check if this file is exactly the same as original file + # in nanobsd image + # + if ! cmp -s /etc/$filename /conf/base/etc/$filename + then + file_path=`echo "$filename" | sed 's/\/[^/]*$//'` + if [ $file_path != $filename ] + then + if [ ! -d /etc/$file_path ] + then + # should never go here unless we have some errors in + # sed script extracting file path + echo "Error: Path /etc/$file_path is not directory." + exit 1; + fi + fi + + # + # Ask user - how should we handle this file. + # Add to cfg (y/n/i)? + # y) -> save this file in /cfg + # n) -> do not save this file in /cfg for current script invocation ONLY + # i) -> add file to ignore list (/cfg/.ignore hiereachy) and never save + # try to add this file to /cfg. + # + # touch is ised to add files to /cfg to keep the script flow straight and easy + # + read -p "New file /etc/$filename found. Add to /cfg (y/n/i)? " key + case "$key" in + [yY]) + if [ $file_path != $filename ] + then + mkdir -vp /cfg/$file_path + fi + touch /cfg/$filename && echo "File /etc/$filename added to /cfg." + ;; + [iI]) + mkdir -vp /cfg/.ignore + if [ $file_path != $filename ] + then + mkdir -vp /cfg/.ignore/$file_path + fi + touch /cfg/.ignore/$filename && echo "File /etc/$filename added to ignore list." + ;; + esac + fi + fi +done + +# +# Actually check all files in /cfg and save if necessary +# cd /cfg -for i in "$@" `find * -type f` +for filename in "$@" `find * -type f` do - cmp -s /etc/$i /cfg/$i || cp -pfv /etc/$i /cfg/$i + if [ -f /etc/$filename ] + then + cmp -s /etc/$filename /cfg/$filename || cp -pfv /etc/$filename /cfg/$filename + else + + # + # Give user an option to remove file from /cfg if this file is removed from /etc + # + read -p "File /cfg/$filename not found in /etc. Remove from /cfg (y/n)? " key + case "$key" in + [yY]) + rm /cfg/$filename && echo "File /cfg/$filename removed" + ;; + esac + fi done + ) umount /cfg trap 1 2 15 EXIT diff --git a/tools/tools/nanobsd/dhcpd/README b/tools/tools/nanobsd/dhcpd/README new file mode 100644 index 000000000..8d9960c53 --- /dev/null +++ b/tools/tools/nanobsd/dhcpd/README @@ -0,0 +1,14 @@ +$FreeBSD$ + +Example for creating many different builds (including different +arch) from a common set of files, as well as building natively +using qemu user space emulation. + +This creates a simple appliance that uses dnsmasq to serve DNS +and DHCPd. + +This is a work in progress. Generally, to build this you should + cd tools/tools/nanobsd/dhcpd + sudo sh ../nandobsd.sh -C os-base +but do be careful if things are interrupted. There may still be +bugs lurking that cause your entire FreeBSD tree to disappear. diff --git a/tools/tools/nanobsd/dhcpd/common b/tools/tools/nanobsd/dhcpd/common new file mode 100644 index 000000000..412c1a121 --- /dev/null +++ b/tools/tools/nanobsd/dhcpd/common @@ -0,0 +1,280 @@ +# $FreeBSD$ + +#- +# Copyright (c) 2014 Warner Losh. All Rights Reserved. +# Copyright (c) 2010 iXsystems, Inc., All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL iXsystems, Inc OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# +# This file is heavily derived from both Sam Leffler's Avilia config, +# as well as the BSDRP project's config file. Neither of these have +# an explicit copyright/license statement, but are implicitly BSDL. This +# example has been taken from the FreeNAS project (an early version) and +# simplified to meet the needs of the example. +# + +# NB: You want the other file + +NANO_PMAKE="make -j $(sysctl -n hw.ncpu)" + +NANO_CFG_BASE=$(pwd) +NANO_CFG_BASE=${NANO_CFG_BASE%/dhcpd} +NANO_SRC=$(pwd) +NANO_SRC=${NANO_SRC%/tools/tools/nanobsd/dhcpd} +NANO_OBJ=${NANO_SRC}/../dhcpd/obj +# Where cust_pkg() finds packages to install +#XXX: Is this the right place? +#NANO_PORTS=$(realpath ${NANO_SRC}/../ports) +NANO_PORTS=/usr/ports +NANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg +NANO_DATADIR=${NANO_OBJ}/_.data +NANO_DATASIZE=40960 +NANO_INIT_IMG2=0 +unset MAKEOBJDIRPREFIX + +# this to go into nanobsd.sh +NANO_PORTS=${NANO_PORTS:-/usr/ports} + +customize_cmd cust_allow_ssh_root + +add_etc_make_conf() +{ + touch ${NANO_WORLDDIR}/etc/make.conf +} +customize_cmd add_etc_make_conf + +clean_usr_local() +{ + LOCAL_DIR=${NANO_WORLDDIR}/usr/local + pprint 2 "Clean and create world directory (${LOCAL_DIR})" + if rm -rf ${LOCAL_DIR}/ > /dev/null 2>&1 ; then + true + else + chflags -R noschg ${LOCAL_DIR}/ + rm -rf ${LOCAL_DIR}/ + fi + for f in bin etc lib libdata libexec sbin share; do + mkdir -p ${LOCAL_DIR}/$f + done +} +customize_cmd clean_usr_local + +cust_install_machine_files() +{ + echo "cd ${NANO_CFG_BASE}/Files" + cd ${NANO_CFG_BASE}/Files + find . -print | grep -Ev '/(CVS|\.svn)' | cpio -dumpv ${NANO_WORLDDIR} +} +customize_cmd cust_install_files +customize_cmd cust_install_machine_files + +buildenv() +{ + cd ${NANO_SRC} + env __MAKE_CONF=${NANO_MAKE_CONF_BUILD} DESTDIR=${NANO_WORLDDIR} make buildenv +} + +NANO_MAKEFS="makefs -B big \ + -o bsize=4096,fsize=512,density=8192,optimization=space" +export NANO_MAKEFS + +# NB: leave c++ enabled so devd can be built +CONF_BUILD=" +WITHOUT_ACPI=true +WITHOUT_ATM=true +WITHOUT_AUDIT=true +WITHOUT_BIND_DNSSEC=true +WITHOUT_BIND_ETC=true +WITHOUT_BIND_LIBS_LWRES=true +WITHOUT_BLUETOOTH=true +WITHOUT_CALENDAR=true +WITHOUT_CVS=true +WITHOUT_DICT=true +WITHOUT_EXAMPLES=true +WITHOUT_FORTRAN=true +WITHOUT_GAMES=true +WITHOUT_GCOV=true +WITHOUT_GPIB=true +WITHOUT_HTML=true +WITHOUT_I4B=true +WITHOUT_IPFILTER=true +WITHOUT_IPX=true +WITHOUT_LIBKSE=true +WITHOUT_LOCALES=true +WITHOUT_LPR=true +WITHOUT_MAN=true +WITHOUT_NETCAT=true +WITHOUT_NIS=true +WITHOUT_NLS=true +WITHOUT_NS_CACHING=true +WITHOUT_OBJC=true +WITHOUT_PROFILE=true +WITHOUT_RCMDS=true +WITHOUT_SENDMAIL=true +WITHOUT_SHAREDOCS=true +WITHOUT_SYSCONS=true +WITHOUT_LIB32=true +" +CONF_INSTALL="$CONF_BUILD +INSTALL_NODEBUG=t +NOPORTDOCS=t +NO_INSTALL_MANPAGES=t +" +# The following would help... +# WITHOUT_TOOLCHAIN=true can't build ports +# WITHOUT_INSTALLLIB=true libgcc.a +# +# from the build +# WITHOUT_INFO=true makeinfo +# WITHOUT_RCS=true +PKG_ONLY_MAKE_CONF=" +WITHOUT_TOOLCHAIN=true +WITHOUT_INSTALLLIB=true +WITHOUT_INFO=true +WITHOUT_RCS=true +" + +NANO_PACKAGE_ONLY=1 + +# install a package from a pre-built binary +do_add_pkg () +{ + # Need to create ${NANO_OBJ}/ports in this add_pkg_${port} function + set -x + mkdir -p ${NANO_OBJ}/ports/distfiles + mkdir -p ${NANO_OBJ}/ports/packages + mkdir -p ${NANO_WORLDDIR}/usr/ports/packages + mkdir -p ${NANO_WORLDDIR}/usr/ports/distfiles + mount -t nullfs -o noatime ${NANO_OBJ}/ports/packages \ + ${NANO_WORLDDIR}/usr/ports/packages + mount -t nullfs -o noatime ${NANO_OBJ}/ports/distfiles \ + ${NANO_WORLDDIR}/usr/ports/distfiles + CR env ASSUME_ALWAYS_YES=YES SIGNATURE_TYPE=none /usr/sbin/pkg add /usr/ports/packages/All/$1.txz + umount ${NANO_WORLDDIR}/usr/ports/distfiles + umount ${NANO_WORLDDIR}/usr/ports/packages + rmdir ${NANO_WORLDDIR}/usr/ports/packages + rmdir ${NANO_WORLDDIR}/usr/ports/distfiles + rmdir ${NANO_WORLDDIR}/usr/ports + set +x +} + +# Build a port (with the side effect of creating a package) +do_add_port () +{ + local port_path + port_path=$1 + shift + set -x + # Need to create ${NANO_OBJ}/ports in this add_port_${port} function + mkdir -p ${NANO_OBJ}/ports/distfiles + mkdir -p ${NANO_OBJ}/ports/packages + mkdir -p ${NANO_PORTS}/packages + mkdir -p ${NANO_PORTS}/distfiles + mkdir -p ${NANO_WORLDDIR}/usr/src + mkdir -p ${NANO_WORLDDIR}/usr/ports + mount -t nullfs -o noatime ${NANO_SRC} ${NANO_WORLDDIR}/usr/src + mount -t nullfs -o noatime ${NANO_PORTS} ${NANO_WORLDDIR}/usr/ports + mount -t nullfs -o noatime ${NANO_OBJ}/ports/packages \ + ${NANO_WORLDDIR}/usr/ports/packages + mount -t nullfs -o noatime ${NANO_OBJ}/ports/distfiles \ + ${NANO_WORLDDIR}/usr/ports/distfiles + mkdir -p ${NANO_WORLDDIR}/dev + mount -t devfs devfs ${NANO_WORLDDIR}/dev + mkdir -p ${NANO_WORLDDIR}/usr/workdir + cp /etc/resolv.conf ${NANO_WORLDDIR}/etc/resolv.conf + # OK, a little inefficient, but likely not enough to worry about. + CR ldconfig /lib /usr/lib /usr/local/lib + CR ldconfig -R + CR ldconfig -r +# Improvement: Don't know why package-recursive don't works here + CR "env UNAME_p=${NANO_ARCH} TARGET=${NANO_ARCH} \ + TARGET_ARCH=${NANO_ARCH} PORTSDIR=${NANO_PORTS} make \ + __MAKE_CONF=${NANO_MAKE_CONF_BUILD} \ + WRKDIRPREFIX=/usr/workdir -C /usr/ports/$port_path \ + package-recursive BATCH=yes $* clean FORCE_PKG_REGISTER=t" + rm ${NANO_WORLDDIR}/etc/resolv.conf + rm -rf ${NANO_WORLDDIR}/usr/obj + rm -rf ${NANO_WORLDDIR}/usr/workdir + umount ${NANO_WORLDDIR}/dev + umount ${NANO_WORLDDIR}/usr/ports/packages + umount ${NANO_WORLDDIR}/usr/ports/distfiles + umount ${NANO_WORLDDIR}/usr/ports + umount ${NANO_WORLDDIR}/usr/src + set +x +} + +# Need to check if this function works with cross-compiling architecture!!!! +# Recursive complex fonction: Generate one function for each ports +add_port () { + local port_path=$1 + local port=`echo $1 | sed -e 's/\//_/'` + shift + # Check if package allready exist + # Need to: + # 1. check ARCH of this package! + # 2. Add a trap + cd ${NANO_PORTS}/${port_path} + PKG_NAME=`env PORTSDIR=${NANO_PORTS} make __MAKE_CONF=${NANO_MAKE_CONF_BUILD} package-name` + if [ -f ${NANO_OBJ}/ports/packages/All/${PKG_NAME}.txz ]; then + # Pkg file found: Generate add_pkg_NAME function + eval " + add_pkg_${port} () { + do_add_pkg ${PKG_NAME} + } + customize_cmd add_pkg_${port} + " + else + # No pkg file: Generate add_port_NAME function + eval " + add_port_${port} () { + do_add_port ${port_path} $* + } + customize_cmd add_port_${port} + " + NANO_PACKAGE_ONLY=0 + fi +} + +die() +{ + echo "$*" + exit 1 +} + +create_amd64_diskimage() +{ + create_i386_diskimage "$*" +} + +# Automatically include the packaging port here so it is always first so it +# builds the port and adds the package so we can add other packages. +add_port ports-mgmt/pkg + +rp=$(realpath ${NANO_OBJ}/) +__a=`mount | grep ${rp} | awk '{print length($3), $3;}' | sort -rn | awk '{$1=""; print;}'` +if [ -n "$__a" ]; then + echo "unmounting $__a" + umount $__a +fi + +NANO_BOOTLOADER="boot/boot0" diff --git a/tools/tools/nanobsd/dhcpd/os-base b/tools/tools/nanobsd/dhcpd/os-base new file mode 100644 index 000000000..10e1a8fb3 --- /dev/null +++ b/tools/tools/nanobsd/dhcpd/os-base @@ -0,0 +1,194 @@ +# $FreeBSD$ + +#- +# Copyright (c) 2014 Warner Losh. All Rights Reserved. +# Copyright (c) 2010-2011 iXsystems, Inc., All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL iXsystems, Inc. OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# This file is heavily derived from both Sam Leffler's Avilia config, +# as well as the BSDRP project's config file. Neither of these have +# an explicit copyright/license statement, but are implicitly BSDL. This +# example has been taken from the FreeNAS project and simplified to meet +# the needs of the example. +# + +# Pull in common definitions. +. common + +NANO_BOOT0CFG="-o packet -s 1 -m 3 -t 18" + +# /var -> ~10MB (look through rc.initdiskless for the formula of how this +# number is calculated out). Since we hope to run +NANO_RAM_TMPVARSIZE=10240 + +NANO_IMAGES=2 +FlashDevice generic 2g + +if [ "$DEBUG" = 1 ]; then + DEBUG_BUILD=" +DEBUG_FLAGS= -g +" +else + DEBUG_INSTALL=" +INSTALL_NODEBUG= t +" +fi + +CONF_INSTALL="$CONF_BUILD +${DEBUG_BUILD} +" +CONF_INSTALL="$CONF_INSTALL +${DEBUG_INSTALL} +" + +add_port security/sudo +add_port ftp/curl + +if [ "${NANO_PACKAGE_ONLY}" -eq 1 ]; then + CONF_INSTALL="${CONF_INSTALL} +${PKG_ONLY_MAKE_CONF} +" + echo "Automatically building a thin image with packages" +else + echo "Automatically building a * * F A T * * image so we can build ports" +fi + +VARS="MASTER_SITE_BACKUP MASTER_SITE_OVERRIDE PACKAGEROOT PACKAGESITE" + +for var in $VARS; do + val=$(eval echo "\$$var") + if [ -n "$val" ]; then + CONF_INSTALL="${CONF_INSTALL} +$var=$val" + fi +done + +if [ "$PACKAGE_PREP_BUILD" = 1 ]; then + echo "Skipping post-package customize steps" + do_image=false +else + +hack_nsswitch_conf ( ) +{ + # Remove all references to NIS in the nsswitch.conf file + # Not sure this is still needed, but FreeNAS has it... + sed -i.bak -es/nis/files/g ${NANO_WORLDDIR}/etc/nsswitch.conf + rm -f ${NANO_WORLDDIR}/etc/nsswitch.conf.bak +} +customize_cmd hack_nsswitch_conf + +save_build ( ) +{ + VERSION_FILE=${NANO_WORLDDIR}/etc/version + if [ "${SVNREVISION}" = "${REVISION}" ]; then + echo "${NANO_NAME}" > "${VERSION_FILE}" + else + echo "${NANO_NAME} (${SVNREVISION})" > "${VERSION_FILE}" + fi +} +customize_cmd save_build + +remove_patch_divots ( ) +{ + find ${NANO_WORLDDIR} -name \*.orig -or -name \*.rej -delete +} +customize_cmd remove_patch_divots + +configure_mnt_md ( ) +{ + mkdir -m 755 -p ${NANO_WORLDDIR}/conf/base/mnt + echo 2048 > ${NANO_WORLDDIR}/conf/base/mnt/md_size +} +customize_cmd configure_mnt_md + +shrink_md_fbsize() +{ + # We have a lot of little files on our memory disks. Let's decrease + # the block and frag size to fit more little files on them (this + # halves our space requirement by ~50% on /etc and /var on 8.x -- + # and gives us more back on 9.x as the default block and frag size + # are 4 times larger). + sed -i '' -e 's,-S -i 4096,-S -i 4096 -b 4096 -f 512,' \ + ${NANO_WORLDDIR}/etc/rc.initdiskless +} +customize_cmd shrink_md_fbsize + +if [ "${DEBUG}" = 1 ]; then + +unmute_console_logging() +{ + # /var is small. Don't fill it up with messages from console.log + # because it's a chatty log. + sed -i '' -e 's/#console.info/console.info/' \ + "${NANO_WORLDDIR}/etc/syslog.conf" +} +customize_cmd unmute_console_logging + +fi + +product_custom() +{ + gzip -v9 ${NANO_WORLDDIR}/boot/kernel/kernel + + # kill includes (saves 14MB) + find ${NANO_WORLDDIR}/usr/local/include \! -name 'pyconfig.h' -type f | xargs rm -f + + # kill docs (saves 22MB) + rm -rf ${NANO_WORLDDIR}/usr/local/share/doc + rm -rf ${NANO_WORLDDIR}/usr/local/share/gtk-doc + + # and info (2MB) + rm -rf ${NANO_WORLDDIR}/usr/local/info + + # and man pages (4.4MB) + rm -rf ${NANO_WORLDDIR}/usr/local/man + + # and examples (1.7M) + rm -rf ${NANO_WORLDDIR}/usr/local/share/examples + + # and groff_fonts junk (3MB) + rm -rf ${NANO_WORLDDIR}/usr/share/groff_font + rm -rf ${NANO_WORLDDIR}/usr/share/tmac + rm -rf ${NANO_WORLDDIR}/usr/share/me + + # Kill all .a's and .la's that are installed (20MB+) + find ${NANO_WORLDDIR} -name \*.a -or -name \*.la -delete + + # magic.mgc is just a speed optimization. Kill it for 1.7MB + rm -f ${NANO_WORLDDIR}/usr/share/misc/magic.mgc + + # Last second tweaks + chown -R root:wheel ${NANO_WORLDDIR}/root + chmod 0755 ${NANO_WORLDDIR}/root/* + chmod 0755 ${NANO_WORLDDIR}/* + chown -R root:wheel ${NANO_WORLDDIR}/etc + chown -R root:wheel ${NANO_WORLDDIR}/boot + chown root:wheel ${NANO_WORLDDIR}/ + chown root:wheel ${NANO_WORLDDIR}/usr + find ${NANO_WORLDDIR} -type f -name "*~" -delete + find ${NANO_WORLDDIR}/usr/local -type f -name "*.po" -delete + find ${NANO_WORLDDIR} -type f -name "*.service" -delete +} +late_customize_cmd product_custom + +fi # [ $PACKAGE_PREP_BUILD = 1 ] diff --git a/tools/tools/nanobsd/gateworks/common b/tools/tools/nanobsd/gateworks/common index 182bfbd55..8cedf38fd 100644 --- a/tools/tools/nanobsd/gateworks/common +++ b/tools/tools/nanobsd/gateworks/common @@ -125,7 +125,6 @@ WITHOUT_HTML=true WITHOUT_INET6=true WITHOUT_INFO=true WITHOUT_IPFILTER=true -WITHOUT_IPX=true WITHOUT_KERBEROS=true WITHOUT_LOCALES=true WITHOUT_LPR=true diff --git a/tools/tools/nanobsd/nanobsd.sh b/tools/tools/nanobsd/nanobsd.sh index 216c9004e..3f7fbe29a 100644 --- a/tools/tools/nanobsd/nanobsd.sh +++ b/tools/tools/nanobsd/nanobsd.sh @@ -49,6 +49,9 @@ NANO_TOOLS=tools/tools/nanobsd NANO_PACKAGE_DIR=${NANO_SRC}/${NANO_TOOLS}/Pkg NANO_PACKAGE_LIST="*" +# where package metadata gets placed +NANO_PKG_META_BASE=/var/db + # Object tree directory # default is subdir of /usr/obj #NANO_OBJ="" @@ -57,7 +60,8 @@ NANO_PACKAGE_LIST="*" # default is ${NANO_OBJ} #NANO_DISKIMGDIR="" -# Parallel Make +# Make & parallel Make +NANO_MAKE="make" NANO_PMAKE="make -j 3" # The default name for any image we create. @@ -85,13 +89,13 @@ NANO_CUSTOMIZE="" NANO_LATE_CUSTOMIZE="" # Newfs paramters to use -NANO_NEWFS="-b 4096 -f 512 -i 8192 -O1 -U" +NANO_NEWFS="-b 4096 -f 512 -i 8192 -U" # The drive name of the media at runtime NANO_DRIVE=ad0 # Target media size in 512 bytes sectors -NANO_MEDIASIZE=1500000 +NANO_MEDIASIZE=2000000 # Number of code images on media (1 or 2) NANO_IMAGES=2 @@ -135,6 +139,9 @@ NANO_BOOT2CFG="-h" # Can be "file" or "swap" NANO_MD_BACKING="file" +# for swap type md(4) backing, write out the mbr only +NANO_IMAGE_MBRONLY=true + # Progress Print level PPLEVEL=3 @@ -159,6 +166,10 @@ NANO_CFGDIR="" # Directory to populate /data from NANO_DATADIR="" +# src.conf to use when building the image. Defaults to /dev/null for the sake +# of determinism. +SRCCONF=${SRCCONF:=/dev/null} + ####################################################################### # # The functions which do the real work. @@ -166,12 +177,31 @@ NANO_DATADIR="" # ####################################################################### +# run in the world chroot, errors fatal +CR() +{ + chroot ${NANO_WORLDDIR} /bin/sh -exc "$*" +} + +# run in the world chroot, errors not fatal +CR0() +{ + chroot ${NANO_WORLDDIR} /bin/sh -c "$*" || true +} + +nano_cleanup ( ) ( + if [ $? -ne 0 ]; then + echo "Error encountered. Check for errors in last log file." 1>&2 + fi + exit $? +) + clean_build ( ) ( pprint 2 "Clean and create object directory (${MAKEOBJDIRPREFIX})" - if ! rm -rf ${MAKEOBJDIRPREFIX} > /dev/null 2>&1 ; then - chflags -R noschg ${MAKEOBJDIRPREFIX} - rm -r ${MAKEOBJDIRPREFIX} + if ! rm -xrf ${MAKEOBJDIRPREFIX}/ > /dev/null 2>&1 ; then + chflags -R noschg ${MAKEOBJDIRPREFIX}/ + rm -xr ${MAKEOBJDIRPREFIX}/ fi mkdir -p ${MAKEOBJDIRPREFIX} printenv > ${MAKEOBJDIRPREFIX}/_.env @@ -182,7 +212,6 @@ make_conf_build ( ) ( echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_BUILD} echo "${CONF_BUILD}" >> ${NANO_MAKE_CONF_BUILD} - echo "SRCCONF=/dev/null" >> ${NANO_MAKE_CONF_BUILD} ) build_world ( ) ( @@ -191,17 +220,20 @@ build_world ( ) ( cd ${NANO_SRC} env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} \ + SRCCONF=${SRCCONF} \ __MAKE_CONF=${NANO_MAKE_CONF_BUILD} buildworld \ > ${MAKEOBJDIRPREFIX}/_.bw 2>&1 ) build_kernel ( ) ( + local extra + pprint 2 "build kernel ($NANO_KERNEL)" pprint 3 "log: ${MAKEOBJDIRPREFIX}/_.bk" ( if [ -f ${NANO_KERNEL} ] ; then - kernconfdir=$(realpath $(dirname ${NANO_KERNEL})) + extra="KERNCONFDIR=$(realpath $(dirname ${NANO_KERNEL}))" kernconf=$(basename ${NANO_KERNEL}) else kernconf=${NANO_KERNEL} @@ -211,12 +243,11 @@ build_kernel ( ) ( # unset these just in case to avoid compiler complaints # when cross-building unset TARGET_CPUTYPE - unset TARGET_BIG_ENDIAN # Note: We intentionally build all modules, not only the ones in # NANO_MODULES so the built world can be reused by multiple images. env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} buildkernel \ - __MAKE_CONF=${NANO_MAKE_CONF_BUILD} \ - ${kernconfdir:+"KERNCONFDIR="}${kernconfdir} \ + SRCCONF=${SRCCONF} \ + ${extra} __MAKE_CONF=${NANO_MAKE_CONF_BUILD} \ KERNCONF=${kernconf} ) > ${MAKEOBJDIRPREFIX}/_.bk 2>&1 ) @@ -224,17 +255,17 @@ build_kernel ( ) ( clean_world ( ) ( if [ "${NANO_OBJ}" != "${MAKEOBJDIRPREFIX}" ]; then pprint 2 "Clean and create object directory (${NANO_OBJ})" - if ! rm -rf ${NANO_OBJ} > /dev/null 2>&1 ; then + if ! rm -rxf ${NANO_OBJ}/ > /dev/null 2>&1 ; then chflags -R noschg ${NANO_OBJ} - rm -r ${NANO_OBJ} + rm -xr ${NANO_OBJ}/ fi mkdir -p ${NANO_OBJ} ${NANO_WORLDDIR} printenv > ${NANO_OBJ}/_.env else pprint 2 "Clean and create world directory (${NANO_WORLDDIR})" - if ! rm -rf ${NANO_WORLDDIR}/ > /dev/null 2>&1 ; then + if ! rm -rxf ${NANO_WORLDDIR}/ > /dev/null 2>&1 ; then chflags -R noschg ${NANO_WORLDDIR} - rm -rf ${NANO_WORLDDIR} + rm -rxf ${NANO_WORLDDIR}/ fi mkdir -p ${NANO_WORLDDIR} fi @@ -245,7 +276,6 @@ make_conf_install ( ) ( echo "${CONF_WORLD}" > ${NANO_MAKE_CONF_INSTALL} echo "${CONF_INSTALL}" >> ${NANO_MAKE_CONF_INSTALL} - echo "SRCCONF=/dev/null" >> ${NANO_MAKE_CONF_INSTALL} ) install_world ( ) ( @@ -254,7 +284,8 @@ install_world ( ) ( cd ${NANO_SRC} env TARGET_ARCH=${NANO_ARCH} \ - ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} installworld \ + ${NANO_MAKE} SRCCONF=${SRCCONF} \ + __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} installworld \ DESTDIR=${NANO_WORLDDIR} \ > ${NANO_OBJ}/_.iw 2>&1 chflags -R noschg ${NANO_WORLDDIR} @@ -267,7 +298,8 @@ install_etc ( ) ( cd ${NANO_SRC} env TARGET_ARCH=${NANO_ARCH} \ - ${NANO_PMAKE} __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} distribution \ + ${NANO_MAKE} SRCCONF=${SRCCONF} \ + __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} distribution \ DESTDIR=${NANO_WORLDDIR} \ > ${NANO_OBJ}/_.etc 2>&1 # make.conf doesn't get created by default, but some ports need it @@ -276,22 +308,24 @@ install_etc ( ) ( ) install_kernel ( ) ( + local extra + pprint 2 "install kernel ($NANO_KERNEL)" pprint 3 "log: ${NANO_OBJ}/_.ik" ( if [ -f ${NANO_KERNEL} ] ; then - kernconfdir=$(realpath $(dirname ${NANO_KERNEL})) + extra="KERNCONFDIR=$(realpath $(dirname ${NANO_KERNEL}))" kernconf=$(basename ${NANO_KERNEL}) else kernconf=${NANO_KERNEL} fi cd ${NANO_SRC} - env TARGET_ARCH=${NANO_ARCH} ${NANO_PMAKE} installkernel \ + env TARGET_ARCH=${NANO_ARCH} ${NANO_MAKE} installkernel \ DESTDIR=${NANO_WORLDDIR} \ - __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \ - ${kernconfdir:+"KERNCONFDIR="}${kernconfdir} \ + SRCCONF=${SRCCONF} \ + ${extra} __MAKE_CONF=${NANO_MAKE_CONF_INSTALL} \ KERNCONF=${kernconf} \ MODULES_OVERRIDE="${NANO_MODULES}" ) > ${NANO_OBJ}/_.ik 2>&1 @@ -406,6 +440,12 @@ newfs_part ( ) ( mount -o async ${dev} ${mnt} ) +# Convenient spot to work around any umount issues that your build environment +# hits by overriding this method. +nano_umount () ( + umount ${1} +) + populate_slice ( ) ( local dev dir mnt lbl dev=$1 @@ -417,10 +457,10 @@ populate_slice ( ) ( if [ -n "${dir}" -a -d "${dir}" ]; then echo "Populating ${lbl} from ${dir}" cd ${dir} - find . -print | grep -Ev '/(CVS|\.svn)' | cpio -dumpv ${mnt} + find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -dumpv ${mnt} fi df -i ${mnt} - umount ${mnt} + nano_umount ${mnt} ) populate_cfg_slice ( ) ( @@ -519,7 +559,7 @@ create_i386_diskimage ( ) ( -y ${NANO_HEADS}` fi - trap "echo 'Running exit trap code' ; df -i ${MNT} ; umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT + trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount ${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT fdisk -i -f ${NANO_OBJ}/_.fdisk ${MD} fdisk ${MD} @@ -535,7 +575,7 @@ create_i386_diskimage ( ) ( echo "Generating mtree..." ( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree ( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du - umount ${MNT} + nano_umount ${MNT} if [ $NANO_IMAGES -gt 1 -a $NANO_INIT_IMG2 -gt 0 ] ; then # Duplicate to second image (if present) @@ -546,7 +586,7 @@ create_i386_diskimage ( ) ( do sed -i "" "s=${NANO_DRIVE}s1=${NANO_DRIVE}s2=g" $f done - umount ${MNT} + nano_umount ${MNT} # Override the label from the first partition so we # don't confuse glabel with duplicates. if [ ! -z ${NANO_LABEL} ]; then @@ -563,6 +603,14 @@ create_i386_diskimage ( ) ( fi if [ "${NANO_MD_BACKING}" = "swap" ] ; then + if [ ${NANO_IMAGE_MBRONLY} ]; then + echo "Writing out _.disk.mbr..." + dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 count=1 + else + echo "Writing out ${NANO_IMGNAME}..." + dd if=/dev/${MD} of=${IMG} bs=64k + fi + echo "Writing out ${NANO_IMGNAME}..." dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k fi @@ -573,7 +621,8 @@ create_i386_diskimage ( ) ( fi mdconfig -d -u $MD - trap - 1 2 15 EXIT + trap - 1 2 15 + trap nano_cleanup EXIT ) > ${NANO_OBJ}/_.di 2>&1 ) @@ -677,7 +726,7 @@ cust_allow_ssh_root () ( cust_install_files () ( cd ${NANO_TOOLS}/Files - find . -print | grep -Ev '/(CVS|\.svn)' | cpio -Ldumpv ${NANO_WORLDDIR} + find . -print | grep -Ev '/(CVS|\.svn|\.hg|\.git)' | cpio -Ldumpv ${NANO_WORLDDIR} ) ####################################################################### @@ -692,7 +741,7 @@ cust_pkg () ( fi # Copy packages into chroot - mkdir -p ${NANO_WORLDDIR}/Pkg + mkdir -p ${NANO_WORLDDIR}/Pkg ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg ( cd ${NANO_PACKAGE_DIR} find ${NANO_PACKAGE_LIST} -print | @@ -707,18 +756,17 @@ cust_pkg () ( while true do # Record how many we have now - have=`ls ${NANO_WORLDDIR}/var/db/pkg | wc -l` + have=`ls ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg | wc -l` # Attempt to install more packages # ...but no more than 200 at a time due to pkg_add's internal # limitations. - chroot ${NANO_WORLDDIR} sh -c \ - 'ls Pkg/*tbz | xargs -n 200 pkg_add -F' || true + CR0 'ls Pkg/*tbz | xargs -n 200 env PKG_DBDIR='${NANO_PKG_META_BASE}'/pkg pkg_add -v -F' # See what that got us - now=`ls ${NANO_WORLDDIR}/var/db/pkg | wc -l` + now=`ls ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg | wc -l` echo "=== NOW $now" - ls ${NANO_WORLDDIR}/var/db/pkg + ls ${NANO_WORLDDIR}/${NANO_PKG_META_BASE}/pkg echo "===" @@ -730,7 +778,71 @@ cust_pkg () ( exit 2 fi done - rm -rf ${NANO_WORLDDIR}/Pkg + rm -rxf ${NANO_WORLDDIR}/Pkg +) + +cust_pkgng () ( + + # If the package directory doesn't exist, we're done. + if [ ! -d ${NANO_PACKAGE_DIR} ]; then + echo "DONE 0 packages" + return 0 + fi + + # Find a pkg-* package + for x in `find -s ${NANO_PACKAGE_DIR} -iname 'pkg-*'`; do + _NANO_PKG_PACKAGE=`basename "$x"` + done + if [ -z "${_NANO_PKG_PACKAGE}" -o ! -f "${NANO_PACKAGE_DIR}/${_NANO_PKG_PACKAGE}" ]; then + echo "FAILED: need a pkg/ package for bootstrapping" + exit 2 + fi + + # Copy packages into chroot + mkdir -p ${NANO_WORLDDIR}/Pkg + ( + cd ${NANO_PACKAGE_DIR} + find ${NANO_PACKAGE_LIST} -print | + cpio -Ldumpv ${NANO_WORLDDIR}/Pkg + ) + + #Bootstrap pkg + CR env ASSUME_ALWAYS_YES=YES SIGNATURE_TYPE=none /usr/sbin/pkg add /Pkg/${_NANO_PKG_PACKAGE} + CR pkg -N >/dev/null 2>&1 + if [ "$?" -ne "0" ]; then + echo "FAILED: pkg bootstrapping faied" + exit 2 + fi + rm -f ${NANO_WORLDDIR}/Pkg/pkg-* + + # Count & report how many we have to install + todo=`ls ${NANO_WORLDDIR}/Pkg | /usr/bin/wc -l` + todo=$(expr $todo + 1) # add one for pkg since it is installed already + echo "=== TODO: $todo" + ls ${NANO_WORLDDIR}/Pkg + echo "===" + while true + do + # Record how many we have now + have=$(CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info | /usr/bin/wc -l) + + # Attempt to install more packages + CR0 'ls 'Pkg/*txz' | xargs env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg add' + + # See what that got us + now=$(CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info | /usr/bin/wc -l) + echo "=== NOW $now" + CR env ASSUME_ALWAYS_YES=YES /usr/sbin/pkg info + echo "===" + if [ $now -eq $todo ] ; then + echo "DONE $now packages" + break + elif [ $now -eq $have ] ; then + echo "FAILED: Nothing happened on this pass" + exit 2 + fi + done + rm -rxf ${NANO_WORLDDIR}/Pkg ) ####################################################################### @@ -758,12 +870,12 @@ late_customize_cmd () { # Progress Print # Print $2 at level $1. -pprint() { +pprint() ( if [ "$1" -le $PPLEVEL ]; then runtime=$(( `date +%s` - $NANO_STARTTIME )) printf "%s %.${1}s %s\n" "`date -u -r $runtime +%H:%M:%S`" "#####" "$2" 1>&3 fi -} +) usage () { ( @@ -855,6 +967,8 @@ if [ $# -gt 0 ] ; then usage fi +trap nano_cleanup EXIT + ####################################################################### # Setup and Export Internal variables # @@ -878,6 +992,7 @@ fi if $do_clean ; then true else + NANO_MAKE="${NANO_MAKE} -DNO_CLEAN" NANO_PMAKE="${NANO_PMAKE} -DNO_CLEAN" fi @@ -897,6 +1012,7 @@ export NANO_DRIVE export NANO_HEADS export NANO_IMAGES export NANO_IMGNAME +export NANO_MAKE export NANO_MAKE_CONF_BUILD export NANO_MAKE_CONF_INSTALL export NANO_MEDIASIZE diff --git a/tools/tools/nanobsd/pcengines/ALIX_DSK b/tools/tools/nanobsd/pcengines/ALIX_DSK index b45822e56..32b0b8ca1 100644 --- a/tools/tools/nanobsd/pcengines/ALIX_DSK +++ b/tools/tools/nanobsd/pcengines/ALIX_DSK @@ -23,6 +23,9 @@ options PSEUDOFS options GEOM_PART_GPT options GEOM_LABEL options COMPAT_43TTY +options COMPAT_FREEBSD4 # Compatible with FreeBSD4 +options COMPAT_FREEBSD5 # Compatible with FreeBSD5 +options COMPAT_FREEBSD6 # Compatible with FreeBSD6 options COMPAT_FREEBSD7 options SCSI_DELAY=5000 options SYSVSHM @@ -32,12 +35,11 @@ options P1003_1B_SEMAPHORES options _KPOSIX_PRIORITY_SCHEDULING options PRINTF_BUFR_SIZE=128 device apic +device cpufreq +device acpi device pci device fdc device ata -device atadisk -device atapicd -device atapist options ATA_STATIC_ID device scbus device da diff --git a/tools/tools/nanobsd/pcengines/common.conf b/tools/tools/nanobsd/pcengines/common.conf index cfbe8d69e..53e359d67 100644 --- a/tools/tools/nanobsd/pcengines/common.conf +++ b/tools/tools/nanobsd/pcengines/common.conf @@ -2,8 +2,11 @@ # $FreeBSD$ # -NANO_TOOLS=`pwd` -NANO_PACKAGE_DIR=`pwd`/Pkg +NANO_SRC=$(pwd) +NANO_SRC=${NANO_SRC%/tools/tools/nanobsd/pcengines} +NANO_OBJ=${NANO_SRC}/../${NANO_NAME}/obj +NANO_TOOLS=$(pwd) +NANO_PACKAGE_DIR=$(pwd)/Pkg #NANO_RAM_TMPVARSIZE=20480 #NANO_RAM_TMPVARSIZE=30720 NANO_RAM_TMPVARSIZE=40960 -- 2.45.0