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