1*c9cab7f5SWarner Losh# $FreeBSD$ 2*c9cab7f5SWarner Losh 3*c9cab7f5SWarner Losh#- 4*c9cab7f5SWarner Losh# Copyright (c) 2014 Warner Losh. All Rights Reserved. 5*c9cab7f5SWarner Losh# Copyright (c) 2010-2011 iXsystems, Inc., All rights reserved. 6*c9cab7f5SWarner Losh# 7*c9cab7f5SWarner Losh# Redistribution and use in source and binary forms, with or without 8*c9cab7f5SWarner Losh# modification, are permitted provided that the following conditions 9*c9cab7f5SWarner Losh# are met: 10*c9cab7f5SWarner Losh# 1. Redistributions of source code must retain the above copyright 11*c9cab7f5SWarner Losh# notice, this list of conditions and the following disclaimer. 12*c9cab7f5SWarner Losh# 2. Redistributions in binary form must reproduce the above copyright 13*c9cab7f5SWarner Losh# notice, this list of conditions and the following disclaimer in the 14*c9cab7f5SWarner Losh# documentation and/or other materials provided with the distribution. 15*c9cab7f5SWarner Losh# 16*c9cab7f5SWarner Losh# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*c9cab7f5SWarner Losh# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*c9cab7f5SWarner Losh# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*c9cab7f5SWarner Losh# ARE DISCLAIMED. IN NO EVENT SHALL iXsystems, Inc. OR CONTRIBUTORS BE LIABLE 20*c9cab7f5SWarner Losh# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*c9cab7f5SWarner Losh# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*c9cab7f5SWarner Losh# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*c9cab7f5SWarner Losh# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*c9cab7f5SWarner Losh# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*c9cab7f5SWarner Losh# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*c9cab7f5SWarner Losh# SUCH DAMAGE. 27*c9cab7f5SWarner Losh# 28*c9cab7f5SWarner Losh# This file is heavily derived from both Sam Leffler's Avilia config, 29*c9cab7f5SWarner Losh# as well as the BSDRP project's config file. Neither of these have 30*c9cab7f5SWarner Losh# an explicit copyright/license statement, but are implicitly BSDL. This 31*c9cab7f5SWarner Losh# example has been taken from the FreeNAS project and simplified to meet 32*c9cab7f5SWarner Losh# the needs of the example. 33*c9cab7f5SWarner Losh# 34*c9cab7f5SWarner Losh 35*c9cab7f5SWarner Losh# Pull in common definitions. 36*c9cab7f5SWarner Losh. common 37*c9cab7f5SWarner Losh 38*c9cab7f5SWarner LoshNANO_BOOT0CFG="-o packet -s 1 -m 3 -t 18" 39*c9cab7f5SWarner Losh 40*c9cab7f5SWarner Losh# /var -> ~10MB (look through rc.initdiskless for the formula of how this 41*c9cab7f5SWarner Losh# number is calculated out). Since we hope to run 42*c9cab7f5SWarner LoshNANO_RAM_TMPVARSIZE=10240 43*c9cab7f5SWarner Losh 44*c9cab7f5SWarner LoshNANO_IMAGES=2 45*c9cab7f5SWarner LoshFlashDevice generic 2g 46*c9cab7f5SWarner Losh 47*c9cab7f5SWarner Loshif [ "$DEBUG" = 1 ]; then 48*c9cab7f5SWarner Losh DEBUG_BUILD=" 49*c9cab7f5SWarner LoshDEBUG_FLAGS= -g 50*c9cab7f5SWarner Losh" 51*c9cab7f5SWarner Loshelse 52*c9cab7f5SWarner Losh DEBUG_INSTALL=" 53*c9cab7f5SWarner LoshINSTALL_NODEBUG= t 54*c9cab7f5SWarner Losh" 55*c9cab7f5SWarner Loshfi 56*c9cab7f5SWarner Losh 57*c9cab7f5SWarner LoshCONF_INSTALL="$CONF_BUILD 58*c9cab7f5SWarner Losh${DEBUG_BUILD} 59*c9cab7f5SWarner Losh" 60*c9cab7f5SWarner LoshCONF_INSTALL="$CONF_INSTALL 61*c9cab7f5SWarner Losh${DEBUG_INSTALL} 62*c9cab7f5SWarner Losh" 63*c9cab7f5SWarner Losh 64*c9cab7f5SWarner Loshadd_port security/sudo 65*c9cab7f5SWarner Loshadd_port ftp/curl 66*c9cab7f5SWarner Losh 67*c9cab7f5SWarner Loshif [ "${NANO_PACKAGE_ONLY}" -eq 1 ]; then 68*c9cab7f5SWarner Losh CONF_INSTALL="${CONF_INSTALL} 69*c9cab7f5SWarner Losh${PKG_ONLY_MAKE_CONF} 70*c9cab7f5SWarner Losh" 71*c9cab7f5SWarner Losh echo "Automatically building a thin image with packages" 72*c9cab7f5SWarner Loshelse 73*c9cab7f5SWarner Losh echo "Automatically building a * * F A T * * image so we can build ports" 74*c9cab7f5SWarner Loshfi 75*c9cab7f5SWarner Losh 76*c9cab7f5SWarner LoshVARS="MASTER_SITE_BACKUP MASTER_SITE_OVERRIDE PACKAGEROOT PACKAGESITE" 77*c9cab7f5SWarner Losh 78*c9cab7f5SWarner Loshfor var in $VARS; do 79*c9cab7f5SWarner Losh val=$(eval echo "\$$var") 80*c9cab7f5SWarner Losh if [ -n "$val" ]; then 81*c9cab7f5SWarner Losh CONF_INSTALL="${CONF_INSTALL} 82*c9cab7f5SWarner Losh$var=$val" 83*c9cab7f5SWarner Losh fi 84*c9cab7f5SWarner Loshdone 85*c9cab7f5SWarner Losh 86*c9cab7f5SWarner Loshif [ "$PACKAGE_PREP_BUILD" = 1 ]; then 87*c9cab7f5SWarner Losh echo "Skipping post-package customize steps" 88*c9cab7f5SWarner Losh do_image=false 89*c9cab7f5SWarner Loshelse 90*c9cab7f5SWarner Losh 91*c9cab7f5SWarner Loshhack_nsswitch_conf ( ) 92*c9cab7f5SWarner Losh{ 93*c9cab7f5SWarner Losh # Remove all references to NIS in the nsswitch.conf file 94*c9cab7f5SWarner Losh # Not sure this is still needed, but FreeNAS has it... 95*c9cab7f5SWarner Losh sed -i.bak -es/nis/files/g ${NANO_WORLDDIR}/etc/nsswitch.conf 96*c9cab7f5SWarner Losh rm -f ${NANO_WORLDDIR}/etc/nsswitch.conf.bak 97*c9cab7f5SWarner Losh} 98*c9cab7f5SWarner Loshcustomize_cmd hack_nsswitch_conf 99*c9cab7f5SWarner Losh 100*c9cab7f5SWarner Loshsave_build ( ) 101*c9cab7f5SWarner Losh{ 102*c9cab7f5SWarner Losh VERSION_FILE=${NANO_WORLDDIR}/etc/version 103*c9cab7f5SWarner Losh if [ "${SVNREVISION}" = "${REVISION}" ]; then 104*c9cab7f5SWarner Losh echo "${NANO_NAME}" > "${VERSION_FILE}" 105*c9cab7f5SWarner Losh else 106*c9cab7f5SWarner Losh echo "${NANO_NAME} (${SVNREVISION})" > "${VERSION_FILE}" 107*c9cab7f5SWarner Losh fi 108*c9cab7f5SWarner Losh} 109*c9cab7f5SWarner Loshcustomize_cmd save_build 110*c9cab7f5SWarner Losh 111*c9cab7f5SWarner Losh# Move the $world/data to the /data partion 112*c9cab7f5SWarner Loshmove_data() 113*c9cab7f5SWarner Losh{ 114*c9cab7f5SWarner Losh db=${NANO_WORLDDIR}/data 115*c9cab7f5SWarner Losh rm -rf ${NANO_DATADIR} 116*c9cab7f5SWarner Losh mkdir -p ${NANO_DATADIR} 117*c9cab7f5SWarner Losh ( cd ${db} ; find . | cpio -R root:wheel -dumpv ${NANO_DATADIR} ) 118*c9cab7f5SWarner Losh rm -rf ${db} 119*c9cab7f5SWarner Losh} 120*c9cab7f5SWarner Loshcustomize_cmd move_data 121*c9cab7f5SWarner Losh 122*c9cab7f5SWarner Loshadd_data_to_fstab ( ) 123*c9cab7f5SWarner Losh{ 124*c9cab7f5SWarner Losh ( 125*c9cab7f5SWarner Losh cd ${NANO_WORLDDIR} 126*c9cab7f5SWarner Losh echo "/dev/${NANO_DRIVE}s4 /data ufs rw,noatime 2 2" >> etc/fstab 127*c9cab7f5SWarner Losh mkdir -p data 128*c9cab7f5SWarner Losh ) 129*c9cab7f5SWarner Losh 130*c9cab7f5SWarner Losh} 131*c9cab7f5SWarner Loshcustomize_cmd add_data_to_fstab 132*c9cab7f5SWarner Losh 133*c9cab7f5SWarner Loshremove_patch_divots ( ) 134*c9cab7f5SWarner Losh{ 135*c9cab7f5SWarner Losh find ${NANO_WORLDDIR} -name \*.orig -or -name \*.rej -delete 136*c9cab7f5SWarner Losh} 137*c9cab7f5SWarner Loshcustomize_cmd remove_patch_divots 138*c9cab7f5SWarner Losh 139*c9cab7f5SWarner Loshconfigure_mnt_md ( ) 140*c9cab7f5SWarner Losh{ 141*c9cab7f5SWarner Losh mkdir -m 755 -p ${NANO_WORLDDIR}/conf/base/mnt 142*c9cab7f5SWarner Losh echo 2048 > ${NANO_WORLDDIR}/conf/base/mnt/md_size 143*c9cab7f5SWarner Losh} 144*c9cab7f5SWarner Loshcustomize_cmd configure_mnt_md 145*c9cab7f5SWarner Losh 146*c9cab7f5SWarner Loshshrink_md_fbsize() 147*c9cab7f5SWarner Losh{ 148*c9cab7f5SWarner Losh # We have a lot of little files on our memory disks. Let's decrease 149*c9cab7f5SWarner Losh # the block and frag size to fit more little files on them (this 150*c9cab7f5SWarner Losh # halves our space requirement by ~50% on /etc and /var on 8.x -- 151*c9cab7f5SWarner Losh # and gives us more back on 9.x as the default block and frag size 152*c9cab7f5SWarner Losh # are 4 times larger). 153*c9cab7f5SWarner Losh sed -i '' -e 's,-S -i 4096,-S -i 4096 -b 4096 -f 512,' \ 154*c9cab7f5SWarner Losh ${NANO_WORLDDIR}/etc/rc.initdiskless 155*c9cab7f5SWarner Losh} 156*c9cab7f5SWarner Loshcustomize_cmd shrink_md_fbsize 157*c9cab7f5SWarner Losh 158*c9cab7f5SWarner Loshif [ "${DEBUG}" = 1 ]; then 159*c9cab7f5SWarner Losh 160*c9cab7f5SWarner Loshunmute_console_logging() 161*c9cab7f5SWarner Losh{ 162*c9cab7f5SWarner Losh # /var is small. Don't fill it up with messages from console.log 163*c9cab7f5SWarner Losh # because it's a chatty log. 164*c9cab7f5SWarner Losh sed -i '' -e 's/#console.info/console.info/' \ 165*c9cab7f5SWarner Losh "${NANO_WORLDDIR}/etc/syslog.conf" 166*c9cab7f5SWarner Losh} 167*c9cab7f5SWarner Loshcustomize_cmd unmute_console_logging 168*c9cab7f5SWarner Losh 169*c9cab7f5SWarner Loshfi 170*c9cab7f5SWarner Losh 171*c9cab7f5SWarner Loshfreenas_custom() 172*c9cab7f5SWarner Losh{ 173*c9cab7f5SWarner Losh gzip -v9 ${NANO_WORLDDIR}/boot/kernel/kernel 174*c9cab7f5SWarner Losh 175*c9cab7f5SWarner Losh # kill includes (saves 14MB) 176*c9cab7f5SWarner Losh find ${NANO_WORLDDIR}/usr/local/include \! -name 'pyconfig.h' -type f | xargs rm -f 177*c9cab7f5SWarner Losh 178*c9cab7f5SWarner Losh # kill docs (saves 22MB) 179*c9cab7f5SWarner Losh rm -rf ${NANO_WORLDDIR}/usr/local/share/doc 180*c9cab7f5SWarner Losh rm -rf ${NANO_WORLDDIR}/usr/local/share/gtk-doc 181*c9cab7f5SWarner Losh 182*c9cab7f5SWarner Losh # and info (2MB) 183*c9cab7f5SWarner Losh rm -rf ${NANO_WORLDDIR}/usr/local/info 184*c9cab7f5SWarner Losh 185*c9cab7f5SWarner Losh # and man pages (4.4MB) 186*c9cab7f5SWarner Losh rm -rf ${NANO_WORLDDIR}/usr/local/man 187*c9cab7f5SWarner Losh 188*c9cab7f5SWarner Losh # and examples (1.7M) 189*c9cab7f5SWarner Losh rm -rf ${NANO_WORLDDIR}/usr/local/share/examples 190*c9cab7f5SWarner Losh 191*c9cab7f5SWarner Losh # and groff_fonts junk (3MB) 192*c9cab7f5SWarner Losh rm -rf ${NANO_WORLDDIR}/usr/share/groff_font 193*c9cab7f5SWarner Losh rm -rf ${NANO_WORLDDIR}/usr/share/tmac 194*c9cab7f5SWarner Losh rm -rf ${NANO_WORLDDIR}/usr/share/me 195*c9cab7f5SWarner Losh 196*c9cab7f5SWarner Losh # Kill all .a's and .la's that are installed (20MB+) 197*c9cab7f5SWarner Losh find ${NANO_WORLDDIR} -name \*.a -or -name \*.la -delete 198*c9cab7f5SWarner Losh 199*c9cab7f5SWarner Losh # magic.mgc is just a speed optimization. Kill it for 1.7MB 200*c9cab7f5SWarner Losh rm -f ${NANO_WORLDDIR}/usr/share/misc/magic.mgc 201*c9cab7f5SWarner Losh 202*c9cab7f5SWarner Losh # strip binaries (saves spaces on non-debug images). 203*c9cab7f5SWarner Losh if [ "${DEBUG}" != 1 ]; then 204*c9cab7f5SWarner Losh pprint 4 "Stripping binaries and libraries" 205*c9cab7f5SWarner Losh for dir in $(find ${NANO_WORLDDIR}/usr/local -name '*bin' -or -name 'libexec' -maxdepth 3); do 206*c9cab7f5SWarner Losh for f in $(find $dir -type f); do 207*c9cab7f5SWarner Losh if ! dontstrip "$f" 208*c9cab7f5SWarner Losh then 209*c9cab7f5SWarner Losh strip 2>/dev/null $f || : 210*c9cab7f5SWarner Losh fi 211*c9cab7f5SWarner Losh done 212*c9cab7f5SWarner Losh done 213*c9cab7f5SWarner Losh # .so's are the only thing that need to be stripped. The rest 214*c9cab7f5SWarner Losh # should remain untouched. 215*c9cab7f5SWarner Losh for f in $(find ${NANO_WORLDDIR}/usr/local/lib -name '*.so' -or -name '*.so.*' -maxdepth 3); do 216*c9cab7f5SWarner Losh strip 2>/dev/null $f || : 217*c9cab7f5SWarner Losh done 218*c9cab7f5SWarner Losh fi 219*c9cab7f5SWarner Losh 220*c9cab7f5SWarner Losh # Last second tweaks 221*c9cab7f5SWarner Losh chown -R root:wheel ${NANO_WORLDDIR}/root 222*c9cab7f5SWarner Losh chmod 0755 ${NANO_WORLDDIR}/root/* 223*c9cab7f5SWarner Losh chmod 0755 ${NANO_WORLDDIR}/* 224*c9cab7f5SWarner Losh chmod 0440 ${NANO_WORLDDIR}/usr/local/etc/sudoers 225*c9cab7f5SWarner Losh chown -R root:wheel ${NANO_WORLDDIR}/etc 226*c9cab7f5SWarner Losh chown -R root:wheel ${NANO_WORLDDIR}/boot 227*c9cab7f5SWarner Losh chown root:wheel ${NANO_WORLDDIR}/ 228*c9cab7f5SWarner Losh chown root:wheel ${NANO_WORLDDIR}/usr 229*c9cab7f5SWarner Losh find ${NANO_WORLDDIR} -type f -name "*~" -delete 230*c9cab7f5SWarner Losh find ${NANO_WORLDDIR}/usr/local -type f -name "*.po" -delete 231*c9cab7f5SWarner Losh find ${NANO_WORLDDIR} -type f -name "*.service" -delete 232*c9cab7f5SWarner Losh mkdir ${NANO_WORLDDIR}/data/zfs 233*c9cab7f5SWarner Losh ln -s -f /usr/local/bin/bash ${NANO_WORLDDIR}/bin/bash 234*c9cab7f5SWarner Losh ln -s -f /data/zfs/zpool.cache ${NANO_WORLDDIR}/boot/zfs/zpool.cache 235*c9cab7f5SWarner Losh 236*c9cab7f5SWarner Losh # This is wrong. Needs a way to tell kernel how to find the mount utility 237*c9cab7f5SWarner Losh # instead. 238*c9cab7f5SWarner Losh mv ${NANO_WORLDDIR}/sbin/mount_ntfs ${NANO_WORLDDIR}/sbin/mount_ntfs-kern 239*c9cab7f5SWarner Losh ln -s -f /usr/local/bin/ntfs-3g ${NANO_WORLDDIR}/sbin/mount_ntfs 240*c9cab7f5SWarner Losh 241*c9cab7f5SWarner Losh} 242*c9cab7f5SWarner Loshlate_customize_cmd freenas_custom 243*c9cab7f5SWarner Losh 244*c9cab7f5SWarner Loshfi # [ $PACKAGE_PREP_BUILD = 1 ] 245