├── .cirrus.yml ├── .gitignore ├── BUILD.md ├── INSTALL.md ├── LICENSE ├── Makefile ├── README.md ├── ci └── ci.sh ├── conf ├── authorized_keys.sample ├── boot.config.sample ├── hosts.sample ├── interfaces.conf.sample ├── loader.conf.sample ├── rc.conf.sample ├── rc.local.sample ├── resolv.conf.sample └── ttys.sample ├── mini ├── Makefile ├── README.md ├── conf │ ├── .cshrc.sample │ ├── .profile.sample │ ├── hosts.sample │ ├── loader.conf.sample │ ├── rc.local │ ├── rc.sample │ └── ttys.sample └── files │ ├── basedirs │ ├── basefiles │ ├── instdirs │ ├── instfiles │ ├── localfiles │ └── rescuelinks ├── scripts ├── interfaces ├── mdinit ├── mfsbsd └── packages └── tools ├── destroygeom ├── doFS.sh ├── do_gpt.sh ├── kern_exclude ├── motd ├── motd.se ├── packages-mini.sample ├── packages.sample ├── prunelist ├── prunelist.9 ├── roothack ├── Makefile └── roothack.c └── zfsinstall /.cirrus.yml: -------------------------------------------------------------------------------- 1 | env: 2 | CIRRUS_CLONE_DEPTH: 1 3 | ARCH: amd64 4 | 5 | build_task: 6 | matrix: 7 | freebsd_instance: 8 | image_family: freebsd-14-2 9 | freebsd_instance: 10 | image_family: freebsd-13-5 11 | prepare_script: 12 | - ci/ci.sh -b prepare 13 | build_std_script: 14 | - ci/ci.sh -b build-std 15 | build_se_script: 16 | - ci/ci.sh -b build-se 17 | build_mini_script: 18 | - ci/ci.sh -b build-mini 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gz 2 | *.iso 3 | *.img 4 | mini/*.gz 5 | mini/*.iso 6 | mini/*.img 7 | tmp/ 8 | mini/tmp/ 9 | packages/*.txz 10 | mini/packages/*.txz 11 | tools/pkg-static 12 | tools/roothack/.depend 13 | tools/roothack/.depend.roothack.o 14 | tools/roothack/roothack 15 | tools/roothack/roothack.debug 16 | tools/roothack/roothack.full 17 | tools/roothack/roothack.o 18 | work 19 | -------------------------------------------------------------------------------- /BUILD.md: -------------------------------------------------------------------------------- 1 | # mfsBSD building instructions 2 | 3 | Copyright (c) 2019 Martin Matuska 4 | 5 | ## Configuration 6 | Read hints in the sample configuration files in the conf/ directory, copy 7 | these files to files without .sample ending and make modifications to suit 8 | your needs. 9 | 10 | The default root password is "mfsroot". You can pick a difrerent password 11 | with the `ROOTPW` or `ROOTPW_HASH` make variables. 12 | 13 | This password can be used to log in as root over SSH. 14 | 15 | To disable remote root login, pass `PERMIT_ROOT_LOGIN=no` to make. 16 | 17 | To disallow password authentication for root, set 18 | `PERMIT_ROOT_LOGIN=without-password`. If you do so, remember to add your SSH 19 | keys to `conf/authorized_keys` if you want to be able to log in via SSH. 20 | 21 | ## Additional packages and files 22 | If you want any packages installed, copy the .tbz files that should be 23 | automatically installed into the packages/ directory. 24 | 25 | Add any additional files into the customfiles/ directory. These will be copied 26 | recursively into the root of the boot image. 27 | 28 | WARNING: 29 | Your image should not exceed MFSROOT_MAXSIZE in total. 30 | Please adjust the variable for larger images. 31 | 32 | ## Distribution or custom world and kernel 33 | You may choose to build from a FreeBSD distribution (e.g. CDROM), or by 34 | using make buildworld / buildkernel from your own world and kernel 35 | configuration. 36 | 37 | To use a distribution (e.g. FreeBSD cdrom), you need access to it 38 | (e.g. a mounted FreeBSD ISO via mdconfig) and use BASE=/path/to/distribution 39 | 40 | To use your own but already built world and kernel, use CUSTOM=1 41 | If you want this script to do make buildworld and make buildkernel for you, 42 | use BUILDWORLD=1 and BUILDKERNEL=1 43 | 44 | ## Creating images 45 | 46 | You may create three types of output: disc image for use by dd(1), 47 | ISO image or a simple .tar.gz file 48 | 49 | ##Examples 50 | 51 | 1. disc image 52 | 53 | ```bash 54 | make BASE=/cdrom/usr/freebsd-dist 55 | make BASE=/cdrom/10.2-RELEASE 56 | make CUSTOM=1 BUILDWORLD=1 BUILDKERNEL=1 57 | ``` 58 | 59 | 2. bootable ISO file: 60 | 61 | ```bash 62 | make iso BASE=/cdrom/usr/freebsd-dist 63 | make iso BASE=/cdrom/10.2-RELEASE 64 | make iso CUSTOM=1 BUILDWORLD=1 BUILDKERNEL=1 65 | ``` 66 | 67 | 3. .tar.gz file: 68 | 69 | ```bash 70 | make tar BASE=/cdrom/usr/freebsd-dist 71 | make tar BASE=/cdrom/10.2-RELEASE 72 | make tar CUSTOM=1 BUILDWORLD=1 BUILDKERNEL=1 73 | ``` 74 | 75 | 4. roothack edition: 76 | 77 | ```bash 78 | make iso CUSTOM=1 BUILDWORLD=1 BUILDKERNEL=1 ROOTHACK=1 79 | ``` 80 | 81 | 5. special edition (with FreeBSD distribution): 82 | 83 | ```bash 84 | make iso BASE=/cdrom/11.0-RELEASE RELEASE=11.0-RELEASE ARCH=amd64 85 | ``` 86 | 87 | 6. GCE-compatible .tar.gz file: 88 | 89 | ```bash 90 | make gce BASE=/cdrom/11.0-RELEASE 91 | make gce CUSTOM=1 BUILDWORLD=1 BUILDKERNEL=1 92 | ``` 93 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | # mfsBSD installation (deployment) instructions 2 | 3 | Copyright (c) 2019 Martin Matuska 4 | 5 | ## Build 6 | For customized build please see the [BUILD](./BUILD.md) file 7 | 8 | ## Deploy 9 | 10 | ### Scenario 1 11 | You have a linux server without console access and want to install 12 | FreeBSD on this server. 13 | 14 | 1. modify your configuration files (do this properly, or no ssh access) 15 | 2. create an image file (e.g. make BASE=/cdrom/usr/freebsd-dist) 16 | 3. write image with dd to the bootable harddrive of the linux server 17 | 4. reboot 18 | 5. ssh to your machine and enjoy :) 19 | 20 | ### Scenario 2 21 | You want a rescue CD-ROM with a minimal FreeBSD installation that doesn't 22 | need to remain in the tray after booting. 23 | 24 | 1. modify your configuration files 25 | 2. create an iso image file (e.g. make iso BASE=/cdrom/usr/freebsd-dist) 26 | 3. burn ISO image onto a writable CD 27 | 4. boot from the CD and enjoy :) 28 | 29 | ### Scenario 3 30 | You want a rescue partition on your FreeBSD system so you can re-partition 31 | all harddrives remotely. 32 | 33 | 1. modify your configuration files 34 | 2. create an .tar.gz file (e.g. make tar BASE=/cdrom/usr/freebsd-dist) 35 | 3. create your UFS partition with sysinstall or gpart (e.g. ada0p2) 36 | 4. create a filesystem on the partition (e.g. newfs /dev/ada0p2) 37 | 5. mount the partition and extract your .tar.gz file on it 38 | 6. configure a bootmanager (e.g. gpart bootcode -b /poot/pmbr -p /boot/gptboot -i 1 ada0) 39 | 7. boot from your rescue system and enjoy :) 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2018, Martin Matuska 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # 3 | # mfsBSD 4 | # Copyright (c) 2019 Martin Matuska 5 | 6 | # 7 | # User-defined variables 8 | # 9 | BASE?= /cdrom/usr/freebsd-dist 10 | KERNCONF?= GENERIC 11 | MFSROOT_FREE_INODES?= 10% 12 | MFSROOT_FREE_BLOCKS?= 10% 13 | MFSROOT_MAXSIZE?= 120m 14 | ROOTPW_HASH?= $$6$$051DdQA7fTvLymkY$$Z5f6snVFQJKugWmGi8y0motBNaKn9em0y2K0ZsJMku3v9gkiYh8M.OTIIie3RvHpzT6udumtZUtc0kXwJcCMR1 15 | PERMIT_ROOT_LOGIN?= yes 16 | 17 | # If you want to build your own kernel and make you own world, you need to set 18 | # -DCUSTOM or CUSTOM=1 19 | # 20 | # To make buildworld use 21 | # -DCUSTOM -DBUILDWORLD or CUSTOM=1 BUILDWORLD=1 22 | # 23 | # To make buildkernel use 24 | # -DCUSTOM -DBUILDKERNEL or CUSTOM=1 BUILDKERNEL=1 25 | # 26 | # For all of this use 27 | # -DCUSTOM -DBUILDWORLD -DBUILDKERNEL or CUSTOM=1 BUILDKERNEL=1 BUILDWORLD=1 28 | # 29 | 30 | # 31 | # Paths 32 | # 33 | SRC_DIR?= /usr/src 34 | CFGDIR?= conf 35 | SCRIPTSDIR?= scripts 36 | PACKAGESDIR?= packages 37 | CUSTOMFILESDIR?= customfiles 38 | CUSTOMSCRIPTSDIR?= customscripts 39 | TOOLSDIR?= tools 40 | PRUNELIST?= ${TOOLSDIR}/prunelist 41 | KERN_EXCLUDE?= ${TOOLSDIR}/kern_exclude 42 | PKG_STATIC?= /usr/local/sbin/pkg-static 43 | # 44 | # Program defaults 45 | # 46 | MKDIR?= /bin/mkdir -p 47 | CHOWN?= /usr/sbin/chown 48 | CAT?= /bin/cat 49 | PWD?= /bin/pwd 50 | TAR?= /usr/bin/tar 51 | GTAR?= /usr/local/bin/gtar 52 | CP?= /bin/cp 53 | MV?= /bin/mv 54 | RM?= /bin/rm 55 | RMDIR?= /bin/rmdir 56 | CHFLAGS?= /bin/chflags 57 | GZIP?= /usr/bin/gzip 58 | TOUCH?= /usr/bin/touch 59 | INSTALL?= /usr/bin/install 60 | LS?= /bin/ls 61 | LN?= /bin/ln 62 | FIND?= /usr/bin/find 63 | PW?= /usr/sbin/pw 64 | SED?= /usr/bin/sed 65 | UNAME?= /usr/bin/uname 66 | BZIP2?= /usr/bin/bzip2 67 | XZ?= /usr/bin/xz 68 | MAKEFS?= /usr/sbin/makefs 69 | SSHKEYGEN?= /usr/bin/ssh-keygen 70 | SYSCTL?= /sbin/sysctl 71 | PKG?= /usr/local/sbin/pkg 72 | OPENSSL?= /usr/bin/openssl 73 | CUT?= /usr/bin/cut 74 | # 75 | WRKDIR?= ${.CURDIR}/work 76 | # 77 | BSDLABEL?= bsdlabel 78 | # 79 | DOFS?= ${TOOLSDIR}/doFS.sh 80 | SCRIPTS?= mdinit mfsbsd interfaces packages 81 | BOOTMODULES?= acpi ahci 82 | .if defined(LOADER_4TH) 83 | BOOTFILES?= defaults device.hints loader_4th *.rc *.4th 84 | EFILOADER?= loader_4th.efi 85 | .else 86 | BOOTFILES?= defaults device.hints loader_lua lua 87 | EFILOADER?= loader_lua.efi 88 | .endif 89 | MFSMODULES?= aesni crypto cryptodev ext2fs geom_eli geom_mirror geom_nop \ 90 | ipmi ntfs nullfs opensolaris smbus snp tmpfs zfs 91 | # Sometimes the kernel is compiled with a different destination. 92 | KERNDIR?= kernel 93 | # 94 | XZ_FLAGS?= 95 | # 96 | 97 | .if defined(V) 98 | _v= 99 | VERB=1 100 | .else 101 | _v=@ 102 | VERB= 103 | .endif 104 | 105 | .if !defined(ARCH) 106 | TARGET!= ${SYSCTL} -n hw.machine_arch 107 | .else 108 | TARGET= ${ARCH} 109 | .endif 110 | 111 | .if !defined(RELEASE) 112 | RELEASE!= ${UNAME} -r 113 | .endif 114 | 115 | .if !defined(PKG_ABI) 116 | PKG_ABI!= echo "FreeBSD:`${UNAME} -U | ${CUT} -c 1-2`:`${UNAME} -m`" 117 | .endif 118 | 119 | .if !defined(SE) 120 | IMAGE_PREFIX?= mfsbsd 121 | .else 122 | IMAGE_PREFIX?= mfsbsd-se 123 | .endif 124 | 125 | IMAGE?= ${IMAGE_PREFIX}-${RELEASE}-${TARGET}.img 126 | ISOIMAGE?= ${IMAGE_PREFIX}-${RELEASE}-${TARGET}.iso 127 | TARFILE?= ${IMAGE_PREFIX}-${RELEASE}-${TARGET}.tar 128 | GCEFILE?= ${IMAGE_PREFIX}-${RELEASE}-${TARGET}.tar.gz 129 | _DISTDIR= ${WRKDIR}/dist/${RELEASE}-${TARGET} 130 | 131 | .if !defined(DEBUG) 132 | EXCLUDE= --exclude *.symbols 133 | .else 134 | EXCLUDE= 135 | .endif 136 | 137 | # Roothack stuff 138 | .if !defined(NO_ROOTHACK) 139 | . if defined(ROOTHACK_FILE) && exists(${ROOTHACK_FILE}) 140 | ROOTHACK_PREBUILT=1 141 | . else 142 | ROOTHACK_FILE= ${WRKDIR}/roothack/roothack 143 | . endif 144 | .endif 145 | 146 | # Check if we are installing FreeBSD 9 or higher 147 | .if exists(${BASE}/base.txz) && exists(${BASE}/kernel.txz) 148 | FREEBSD9?= yes 149 | BASEFILE?= ${BASE}/base.txz 150 | KERNELFILE?= ${BASE}/kernel.txz 151 | .else 152 | BASEFILE?= ${BASE}/base/base.?? 153 | KERNELFILE?= ${BASE}/kernels/generic.?? 154 | .endif 155 | 156 | .if defined(MAKEJOBS) 157 | _MAKEJOBS= -j${MAKEJOBS} 158 | .endif 159 | 160 | _ROOTDIR= ${WRKDIR}/mfs 161 | _BOOTDIR= ${_ROOTDIR}/boot 162 | .if !defined(NO_ROOTHACK) 163 | _DESTDIR= ${_ROOTDIR}/rw 164 | MFSROOT_FREE_INODES?=1% 165 | MFSROOT_FREE_BLOCKS?=1% 166 | .else 167 | _DESTDIR= ${_ROOTDIR} 168 | .endif 169 | 170 | .if !defined(SE) 171 | # Environment for custom build 172 | BUILDENV?= env \ 173 | NO_FSCHG=1 \ 174 | WITHOUT_CLANG=1 \ 175 | WITHOUT_DICT=1 \ 176 | WITHOUT_GAMES=1 \ 177 | WITHOUT_LIB32=1 178 | 179 | # Environment for custom install 180 | INSTALLENV?= ${BUILDENV} \ 181 | WITHOUT_TOOLCHAIN=1 182 | .endif 183 | 184 | # Environment for custom scripts 185 | CUSTOMSCRIPTENV?= env \ 186 | WRKDIR=${WRKDIR} \ 187 | DESTDIR=${_DESTDIR} \ 188 | DISTDIR=${_DISTDIR} \ 189 | BASE=${BASE} 190 | 191 | .if defined(FULLDIST) 192 | NO_PRUNE=1 193 | WITH_RESCUE=1 194 | .endif 195 | 196 | all: image 197 | 198 | destdir: ${_DESTDIR} ${_BOOTDIR} 199 | ${_DESTDIR}: 200 | ${_v}${MKDIR} ${_DESTDIR} && ${CHOWN} root:wheel ${_DESTDIR} 201 | 202 | ${_BOOTDIR}: 203 | ${_v}${MKDIR} ${_BOOTDIR}/kernel ${_BOOTDIR}/modules && ${CHOWN} -R root:wheel ${_BOOTDIR} 204 | 205 | extract: destdir ${WRKDIR}/.extract_done 206 | ${WRKDIR}/.extract_done: 207 | .if !defined(CUSTOM) 208 | ${_v}if [ ! -d "${BASE}" ]; then \ 209 | echo "Please set the environment variable BASE to a path"; \ 210 | echo "with FreeBSD distribution files (e.g. /cdrom/9.2-RELEASE)"; \ 211 | echo "Examples:"; \ 212 | echo "make BASE=/cdrom/9.2-RELEASE"; \ 213 | echo "make BASE=/cdrom/usr/freebsd-dist"; \ 214 | exit 1; \ 215 | fi 216 | .if !defined(FREEBSD9) 217 | ${_v}for DIR in base kernels; do \ 218 | if [ ! -d "${BASE}/$$DIR" ]; then \ 219 | echo "Cannot find directory \"${BASE}/$$DIR\""; \ 220 | exit 1; \ 221 | fi \ 222 | done 223 | .endif 224 | @echo -n "Extracting base and kernel ..." 225 | ${_v}${CAT} ${BASEFILE} | ${TAR} --unlink -xpzf - -C ${_DESTDIR} 226 | .if !defined(FREEBSD9) 227 | ${_v}${CAT} ${KERNELFILE} | ${TAR} --unlink -xpzf - -C ${_BOOTDIR} 228 | ${_v}${MV} ${_BOOTDIR}/${KERNCONF}/* ${_BOOTDIR}/kernel 229 | ${_v}${RMDIR} ${_BOOTDIR}/${KERNCONF} 230 | .else 231 | ${_v}${CAT} ${KERNELFILE} | ${TAR} --unlink -xpzf - -C ${_ROOTDIR} 232 | .endif 233 | @echo " done" 234 | .endif 235 | ${_v}${TOUCH} ${WRKDIR}/.extract_done 236 | 237 | build: extract ${WRKDIR}/.build_done 238 | ${WRKDIR}/.build_done: 239 | .if defined(CUSTOM) 240 | . if defined(BUILDWORLD) 241 | @echo -n "Building world ..." 242 | ${_v}cd ${SRC_DIR} && \ 243 | ${BUILDENV} make ${_MAKEJOBS} buildworld TARGET=${TARGET} 244 | . endif 245 | . if defined(BUILDKERNEL) 246 | @echo -n "Building kernel KERNCONF=${KERNCONF} ..." 247 | ${_v}cd ${SRC_DIR} && make ${_MAKEJOBS} buildkernel KERNCONF=${KERNCONF} TARGET=${TARGET} 248 | . endif 249 | .endif 250 | ${_v}${TOUCH} ${WRKDIR}/.build_done 251 | 252 | install: destdir build ${WRKDIR}/.install_done 253 | ${WRKDIR}/.install_done: 254 | .if defined(CUSTOM) 255 | @echo -n "Installing world and kernel KERNCONF=${KERNCONF} ..." 256 | ${_v}cd ${SRC_DIR} && \ 257 | ${INSTALLENV} make installworld distribution DESTDIR="${_DESTDIR}" TARGET=${TARGET} && \ 258 | ${INSTALLENV} make installkernel KERNCONF=${KERNCONF} DESTDIR="${_ROOTDIR}" TARGET=${TARGET} 259 | .endif 260 | .if defined(SE) 261 | . if !defined(CUSTOM) && exists(${BASE}/base.txz) && exists(${BASE}/kernel.txz) 262 | @echo -n "Copying base.txz and kernel.txz ..." 263 | . else 264 | @echo -n "Creating base.txz and kernel.txz ..." 265 | . endif 266 | ${_v}${MKDIR} ${_DISTDIR} 267 | . if !defined(NO_ROOTHACK) 268 | ${_v}${CP} -rp ${_BOOTDIR}/${KERNDIR} ${_DESTDIR}/boot 269 | . if "${KERNDIR}" != "kernel" 270 | ${_v}${MV} -f ${_DESTDIR}/boot/${KERNDIR} ${_DESTDIR}/boot/kernel 271 | . endif 272 | . endif 273 | . if !defined(CUSTOM) && exists(${BASE}/base.txz) && exists(${BASE}/kernel.txz) 274 | ${_v}${CP} ${BASE}/base.txz ${_DISTDIR}/base.txz 275 | ${_v}${CP} ${BASE}/kernel.txz ${_DISTDIR}/kernel.txz 276 | . else 277 | ${_v}${TAR} -c -C ${_DESTDIR} -J ${EXCLUDE} --exclude "boot/${KERNDIR}/*" -f ${_DISTDIR}/base.txz . 278 | ${_v}${TAR} -c -C ${_DESTDIR} -J ${EXCLUDE} -f ${_DISTDIR}/kernel.txz boot/kernel 279 | . endif 280 | @echo " done" 281 | . if !defined(NO_ROOTHACK) 282 | ${_v}${RM} -rf ${_DESTDIR}/boot/${KERNDIR} 283 | . endif 284 | .endif 285 | ${_v}${CHFLAGS} -R noschg ${_DESTDIR} > /dev/null 2> /dev/null || exit 0 286 | .if !defined(WITHOUT_RESCUE) && defined(RESCUE_LINKS) 287 | ${_v}cd ${_DESTDIR} && \ 288 | for FILE in `${FIND} rescue -type f`; do \ 289 | FILE=$${FILE##rescue/}; \ 290 | if [ -f bin/$$FILE ]; then \ 291 | ${RM} bin/$$FILE && \ 292 | ${LN} rescue/$$FILE bin/$$FILE; \ 293 | elif [ -f sbin/$$FILE ]; then \ 294 | ${RM} sbin/$$FILE && \ 295 | ${LN} rescue/$$FILE sbin/$$FILE; \ 296 | elif [ -f usr/bin/$$FILE ]; then \ 297 | ${RM} usr/bin/$$FILE && \ 298 | ${LN} -s ../../rescue/$$FILE usr/bin/$$FILE; \ 299 | elif [ -f usr/sbin/$$FILE ]; then \ 300 | ${RM} usr/sbin/$$FILE && \ 301 | ${LN} -s ../../rescue/$$FILE usr/sbin/$$FILE; \ 302 | fi; \ 303 | done 304 | .endif 305 | .if defined(WITHOUT_RESCUE) 306 | ${_v}cd ${_DESTDIR} && ${RM} -rf rescue 307 | .endif 308 | ${_v}${TOUCH} ${WRKDIR}/.install_done 309 | 310 | prune: install ${WRKDIR}/.prune_done 311 | ${WRKDIR}/.prune_done: 312 | .if !defined(NO_PRUNE) 313 | @echo -n "Removing selected files from distribution ..." 314 | ${_v}if [ -f "${PRUNELIST}" ]; then \ 315 | for FILE in `${CAT} ${PRUNELIST}`; do \ 316 | if [ -n "$${FILE}" ]; then \ 317 | ${RM} -rf ${_DESTDIR}/$${FILE}; \ 318 | fi; \ 319 | done; \ 320 | fi 321 | ${_v}${TOUCH} ${WRKDIR}/.prune_done 322 | @echo " done" 323 | .endif 324 | 325 | cdboot: install prune ${WRKDIR}/.cdboot_done 326 | ${WRKDIR}/.cdboot_done: 327 | @echo -n "Copying out cdboot and EFI loader ..." 328 | ${_v}${MKDIR} ${WRKDIR}/cdboot 329 | ${_v}${CP} ${_DESTDIR}/boot/cdboot ${WRKDIR}/cdboot/ 330 | ${_v}${CP} ${_DESTDIR}/boot/loader_4th.efi ${_DESTDIR}/boot/loader_lua.efi ${WRKDIR}/cdboot/ 331 | ${_v}${TOUCH} ${WRKDIR}/.cdboot_done 332 | @echo " done" 333 | 334 | packages: install prune cdboot ${WRKDIR}/.packages_done 335 | ${WRKDIR}/.packages_done: 336 | @echo -n "Installing pkgng ..." 337 | . if !exists(${PKG_STATIC}) 338 | @echo "pkg-static not found at: ${PKG_STATIC}" 339 | ${_v}exit 1 340 | . endif 341 | ${_v}mkdir -p ${_DESTDIR}/usr/local/sbin 342 | ${_v}${INSTALL} -o root -g wheel -m 0755 ${PKG_STATIC} ${_DESTDIR}/usr/local/sbin/ 343 | ${_v}${LN} -sf pkg-static ${_DESTDIR}/usr/local/sbin/pkg 344 | @echo " done" 345 | @echo "Installing user packages ..." 346 | ${_v}if [ -f "${TOOLSDIR}/packages" ]; then \ 347 | _PKGS="${TOOLSDIR}/packages"; \ 348 | elif [ -f "${TOOLSDIR}/packages.sample" ]; then \ 349 | _PKGS="${TOOLSDIR}/packages.sample"; \ 350 | fi; \ 351 | if [ -n "$${_PKGS}" ]; then \ 352 | env ASSUME_ALWAYS_YES=yes \ 353 | PKG_ABI="${PKG_ABI}" \ 354 | PKG_CACHEDIR=${WRKDIR}/pkgcache \ 355 | ${PKG} -r ${_DESTDIR} install `${CAT} $${_PKGS}`; \ 356 | fi; 357 | ${_v}${TOUCH} ${WRKDIR}/.packages_done 358 | 359 | packages-mini: packages ${WRKDIR}/.packages_mini_done 360 | ${WRKDIR}/.packages_mini_done: 361 | @echo "Installing additional mini packages ..." 362 | ${_v}if [ -f "${TOOLSDIR}/packages-mini" ]; then \ 363 | _PKGS="${TOOLSDIR}/packages-mini"; \ 364 | elif [ -f "${TOOLSDIR}/packages-mini.sample" ]; then \ 365 | _PKGS="${TOOLSDIR}/packages-mini.sample"; \ 366 | fi; \ 367 | if [ -n "$${_PKGS}" ]; then \ 368 | env ASSUME_ALWAYS_YES=yes \ 369 | PKG_ABI="${PKG_ABI}" \ 370 | PKG_CACHEDIR=${WRKDIR}/pkgcache \ 371 | ${PKG} -r ${_DESTDIR} install `${CAT} $${_PKGS}`; \ 372 | fi; 373 | ${_v}${TOUCH} ${WRKDIR}/.packages_mini_done 374 | 375 | config: install ${WRKDIR}/.config_done 376 | ${WRKDIR}/.config_done: 377 | @echo -n "Installing configuration scripts and files ..." 378 | .for FILE in boot.config loader.conf rc.conf rc.local resolv.conf interfaces.conf ttys 379 | . if !exists(${CFGDIR}/${FILE}) && !exists(${CFGDIR}/${FILE}.sample) 380 | @echo "Missing ${CFGDIR}/${FILE}.sample" && exit 1 381 | . endif 382 | .endfor 383 | .if defined(SE) 384 | ${_v}${INSTALL} -m 0644 ${TOOLSDIR}/motd.se ${_DESTDIR}/etc/motd 385 | ${_v}${INSTALL} -d -m 0755 ${_DESTDIR}/cdrom 386 | .else 387 | ${_v}${INSTALL} -m 0644 ${TOOLSDIR}/motd ${_DESTDIR}/etc/motd 388 | .endif 389 | ${_v}${MKDIR} ${_DESTDIR}/stand ${_DESTDIR}/etc/rc.conf.d 390 | ${_v}if [ -f "${CFGDIR}/boot.config" ]; then \ 391 | ${INSTALL} -m 0644 ${CFGDIR}/boot.config ${_DESTDIR}/boot.config; \ 392 | else \ 393 | ${INSTALL} -m 0644 ${CFGDIR}/boot.config.sample ${_DESTDIR}/boot.config; \ 394 | fi 395 | ${_v}if [ -f "${CFGDIR}/loader.conf" ]; then \ 396 | ${INSTALL} -m 0644 ${CFGDIR}/loader.conf ${_BOOTDIR}/loader.conf; \ 397 | else \ 398 | ${INSTALL} -m 0644 ${CFGDIR}/loader.conf.sample ${_BOOTDIR}/loader.conf; \ 399 | fi 400 | ${_v}if [ -f "${CFGDIR}/rc.local" ]; then \ 401 | ${INSTALL} -m 0744 ${CFGDIR}/rc.local ${_DESTDIR}/etc/rc.local; \ 402 | else \ 403 | ${INSTALL} -m 0744 ${CFGDIR}/rc.local.sample ${_DESTDIR}/etc/rc.local; \ 404 | fi 405 | .for FILE in rc.conf ttys 406 | ${_v}if [ -f "${CFGDIR}/${FILE}" ]; then \ 407 | ${INSTALL} -m 0644 ${CFGDIR}/${FILE} ${_DESTDIR}/etc/${FILE}; \ 408 | else \ 409 | ${INSTALL} -m 0644 ${CFGDIR}/${FILE}.sample ${_DESTDIR}/etc/${FILE}; \ 410 | fi 411 | .endfor 412 | .if !defined(NO_ROOTHACK) 413 | @echo 'root_rw_mount="NO"' >> ${_DESTDIR}/etc/rc.conf 414 | .endif 415 | ${_v}if [ -f "${CFGDIR}/resolv.conf" ]; then \ 416 | ${INSTALL} -m 0644 ${CFGDIR}/resolv.conf ${_DESTDIR}/etc/resolv.conf; \ 417 | fi 418 | ${_v}if [ -f "${CFGDIR}/interfaces.conf" ]; then \ 419 | ${INSTALL} -m 0644 ${CFGDIR}/interfaces.conf ${_DESTDIR}/etc/rc.conf.d/interfaces; \ 420 | fi 421 | ${_v}if [ -f "${CFGDIR}/authorized_keys" ]; then \ 422 | ${INSTALL} -d -m 0700 ${_DESTDIR}/root/.ssh; \ 423 | ${INSTALL} ${CFGDIR}/authorized_keys ${_DESTDIR}/root/.ssh/; \ 424 | fi 425 | ${_v}${MKDIR} ${_DESTDIR}/root/bin 426 | ${_v}${INSTALL} ${TOOLSDIR}/zfsinstall ${_DESTDIR}/root/bin 427 | ${_v}${INSTALL} ${TOOLSDIR}/destroygeom ${_DESTDIR}/root/bin 428 | ${_v}for SCRIPT in ${SCRIPTS}; do \ 429 | ${INSTALL} -m 0555 ${SCRIPTSDIR}/$${SCRIPT} ${_DESTDIR}/etc/rc.d/; \ 430 | done 431 | # ${_v}${SED} -I -E 's/\(ttyv[2-7].*\)on /\1off/g' ${_DESTDIR}/etc/ttys 432 | .if defined(NO_ROOTHACK) 433 | ${_v}echo "/dev/md0 / ufs rw 0 0" > ${_DESTDIR}/etc/fstab 434 | ${_v}echo "tmpfs /tmp tmpfs rw,mode=1777 0 0" >> ${_DESTDIR}/etc/fstab 435 | .else 436 | ${_v}${TOUCH} ${_DESTDIR}/etc/fstab 437 | .endif 438 | .if defined(ROOTPW) 439 | ${_v}echo '${ROOTPW}'| ${OPENSSL} passwd -6 -stdin | ${PW} -V ${_DESTDIR}/etc usermod root -H 0 440 | .elif !empty(ROOTPW_HASH) 441 | ${_v}echo '${ROOTPW_HASH}'| ${PW} -V ${_DESTDIR}/etc usermod root -H 0 442 | .endif 443 | ${_v}echo PermitRootLogin ${PERMIT_ROOT_LOGIN} >> ${_DESTDIR}/etc/ssh/sshd_config 444 | .if exists(${CFGDIR}/hosts) 445 | ${_v}${INSTALL} -m 0644 ${CFGDIR}/hosts ${_DESTDIR}/etc/hosts 446 | .elif exists(${CFGDIR}/hosts.sample) 447 | ${_v}${INSTALL} -m 0644 ${CFGDIR}/hosts.sample ${_DESTDIR}/etc/hosts 448 | .else 449 | @echo "Missing ${CFGDIR}/hosts.sample" && exit 1 450 | .endif 451 | ${_v}${TOUCH} ${WRKDIR}/.config_done 452 | @echo " done" 453 | 454 | genkeys: config ${WRKDIR}/.genkeys_done 455 | ${WRKDIR}/.genkeys_done: 456 | @echo -n "Generating SSH host keys ..." 457 | ${_v}test -f ${_DESTDIR}/etc/ssh/ssh_host_key || ${SSHKEYGEN} -t rsa1 -b 1024 -f ${_DESTDIR}/etc/ssh/ssh_host_key -N '' > /dev/null 2> /dev/null || true 458 | ${_v}test -f ${_DESTDIR}/etc/ssh/ssh_host_dsa_key || ${SSHKEYGEN} -t dsa -f ${_DESTDIR}/etc/ssh/ssh_host_dsa_key -N '' > /dev/null 2> /dev/null || true 459 | ${_v}test -f ${_DESTDIR}/etc/ssh/ssh_host_rsa_key || ${SSHKEYGEN} -t rsa -f ${_DESTDIR}/etc/ssh/ssh_host_rsa_key -N '' > /dev/null 460 | ${_v}test -f ${_DESTDIR}/etc/ssh/ssh_host_ecdsa_key || ${SSHKEYGEN} -t ecdsa -f ${_DESTDIR}/etc/ssh/ssh_host_ecdsa_key -N '' > /dev/null 461 | ${_v}test -f ${_DESTDIR}/etc/ssh/ssh_host_ed25519_key || ${SSHKEYGEN} -t ed25519 -f ${_DESTDIR}/etc/ssh/ssh_host_ed25519_key -N '' > /dev/null 462 | ${_v}${TOUCH} ${WRKDIR}/.genkeys_done 463 | @echo " done" 464 | 465 | customfiles: config ${WRKDIR}/.customfiles_done 466 | ${WRKDIR}/.customfiles_done: 467 | .if exists(${CUSTOMFILESDIR}) 468 | @echo "Copying user files ..." 469 | ${_v}${CP} -afv ${CUSTOMFILESDIR}/ ${_DESTDIR}/ 470 | ${_v}${TOUCH} ${WRKDIR}/.customfiles_done 471 | @echo " done" 472 | .endif 473 | 474 | customscripts: config ${WRKDIR}/.customscripts_done 475 | ${WRKDIR}/.customscripts_done: 476 | .if exists(${CUSTOMSCRIPTSDIR}) 477 | @echo -n "Running user scripts ..." 478 | @for SCRIPT in `find ${CUSTOMSCRIPTSDIR} -type f`; do \ 479 | chmod +x $$SCRIPT; \ 480 | ${CUSTOMSCRIPTENV} $$SCRIPT; \ 481 | done 482 | ${_v}${TOUCH} ${WRKDIR}/.customscripts_done 483 | @echo " done" 484 | .endif 485 | 486 | compress-usr: install prune cdboot config genkeys customfiles customscripts boot efiboot packages ${WRKDIR}/.compress-usr_done 487 | ${WRKDIR}/.compress-usr_done: 488 | .if defined(NO_ROOTHACK) 489 | @echo -n "Compressing usr ..." 490 | ${_v}${TAR} -c -J -C ${_DESTDIR} -f ${_DESTDIR}/.usr.tar.xz usr 491 | ${_v}${RM} -rf ${_DESTDIR}/usr && ${MKDIR} ${_DESTDIR}/usr 492 | .else 493 | @echo -n "Compressing root ..." 494 | ${_v}${TAR} -c -C ${_ROOTDIR} -f - rw | \ 495 | ${XZ} ${XZ_FLAGS} -v -c > ${_ROOTDIR}/root.txz 496 | ${_v}${RM} -rf ${_DESTDIR} && ${MKDIR} ${_DESTDIR} 497 | .endif 498 | ${_v}${TOUCH} ${WRKDIR}/.compress-usr_done 499 | @echo " done" 500 | 501 | roothack: ${WRKDIR}/roothack/roothack 502 | ${WRKDIR}/roothack/roothack: 503 | .if !defined(ROOTHACK_PREBUILT) 504 | ${_v}${MKDIR} -p ${WRKDIR}/roothack 505 | ${_v}cd ${TOOLSDIR}/roothack && env MAKEOBJDIR=${WRKDIR}/roothack make 506 | .endif 507 | 508 | install-roothack: compress-usr roothack ${WRKDIR}/.install-roothack_done 509 | ${WRKDIR}/.install-roothack_done: 510 | @echo -n "Installing roothack ..." 511 | ${_v}${MKDIR} -p ${_ROOTDIR}/dev ${_ROOTDIR}/sbin 512 | ${_v}${INSTALL} -m 555 ${ROOTHACK_FILE} ${_ROOTDIR}/sbin/init 513 | ${_v}${TOUCH} ${WRKDIR}/.install-roothack_done 514 | @echo " done" 515 | 516 | boot: install prune cdboot ${WRKDIR}/.boot_done 517 | ${WRKDIR}/.boot_done: 518 | @echo -n "Configuring boot environment ..." 519 | ${_v}${MKDIR} -p ${WRKDIR}/disk/boot/kernel 520 | ${_v}${CHOWN} root:wheel ${WRKDIR}/disk 521 | ${_v}${TAR} -c -X ${KERN_EXCLUDE} -C ${_BOOTDIR}/${KERNDIR} -f - . | ${TAR} -xv -C ${WRKDIR}/disk/boot/kernel -f - 522 | ${_v}${CP} -rp ${_DESTDIR}/boot.config ${WRKDIR}/disk 523 | .for FILE in ${BOOTFILES} 524 | ${_v}${CP} -rp ${_DESTDIR}/boot/${FILE} ${WRKDIR}/disk/boot 525 | .endfor 526 | .if defined(LOADER_4TH) 527 | ${_v}${MV} -f ${WRKDIR}/disk/boot/loader_4th ${WRKDIR}/disk/boot/loader 528 | .else 529 | ${_v}${MV} -f ${WRKDIR}/disk/boot/loader_lua ${WRKDIR}/disk/boot/loader 530 | .endif 531 | ${_v}${RM} -rf ${WRKDIR}/disk/boot/kernel/*.ko ${WRKDIR}/disk/boot/kernel/*.symbols 532 | .if defined(DEBUG) 533 | ${_v}-${INSTALL} -m 0555 ${_BOOTDIR}/${KERNDIR}/kernel.symbols ${WRKDIR}/disk/boot/kernel 534 | .endif 535 | # Install modules need to boot into the kernel directory 536 | ${_v}${FIND} ${_BOOTDIR}/${KERNDIR} -name 'acpi*.ko' -exec ${INSTALL} -m 0555 {} ${WRKDIR}/disk/boot/kernel \; 537 | .for FILE in ${BOOTMODULES} 538 | ${_v}[ ! -f ${_BOOTDIR}/${KERNDIR}/${FILE}.ko ] || \ 539 | ${INSTALL} -m 0555 ${_BOOTDIR}/${KERNDIR}/${FILE}.ko ${WRKDIR}/disk/boot/kernel 540 | . if defined(DEBUG) 541 | ${_v}[ ! -f ${_BOOTDIR}/${KERNDIR}/${FILE}.ko.symbols ] || \ 542 | ${INSTALL} -m 0555 ${_BOOTDIR}/${KERNDIR}/${FILE}.ko.symbols ${WRKDIR}/disk/boot/kernel 543 | . endif 544 | .endfor 545 | ${_v}${MKDIR} -p ${_DESTDIR}/boot/modules 546 | .for FILE in ${MFSMODULES} 547 | ${_v}[ ! -f ${_BOOTDIR}/${KERNDIR}/${FILE}.ko ] || \ 548 | ${INSTALL} -m 0555 ${_BOOTDIR}/${KERNDIR}/${FILE}.ko ${_DESTDIR}/boot/modules 549 | . if defined(DEBUG) 550 | ${_v}[ ! -f ${_BOOTDIR}/${KERNDIR}/${FILE}.ko.symbols ] || \ 551 | ${INSTALL} -m 0555 ${_BOOTDIR}/${KERNDIR}/${FILE}.ko.symbols ${_DESTDIR}/boot/modules 552 | . endif 553 | .endfor 554 | .if !defined(NO_ROOTHACK) 555 | ${_v}${MKDIR} -p ${_ROOTDIR}/boot/modules 556 | ${_v}${INSTALL} -m 0666 ${_BOOTDIR}/${KERNDIR}/tmpfs.ko ${_ROOTDIR}/boot/modules 557 | .endif 558 | ${_v}${RM} -rf ${_BOOTDIR}/${KERNDIR} ${_BOOTDIR}/*.symbols 559 | ${_v}${MKDIR} -p ${WRKDIR}/boot 560 | ${_v}${CP} -p ${_DESTDIR}/boot/pmbr ${_DESTDIR}/boot/gptboot ${WRKDIR}/boot 561 | ${_v}${TOUCH} ${WRKDIR}/.boot_done 562 | @echo " done" 563 | 564 | efiboot: install prune cdboot config genkeys customfiles customscripts boot ${WRKDIR}/.efiboot_done 565 | ${WRKDIR}/.efiboot_done: 566 | .if !defined(NO_EFIBOOT) 567 | @echo -n "Creating EFI boot image ..." 568 | ${_v}${MKDIR} -p ${WRKDIR}/efiroot/EFI/BOOT 569 | ${_v}${CP} ${WRKDIR}/cdboot/${EFILOADER} ${WRKDIR}/efiroot/EFI/BOOT/BOOTX64.efi 570 | ${_v}${MAKEFS} -t msdos -s 2048k -o fat_type=12,sectors_per_cluster=1 ${WRKDIR}/cdboot/efiboot.img ${WRKDIR}/efiroot 571 | ${_v}${TOUCH} ${WRKDIR}/.efiboot_done 572 | @echo " done" 573 | .endif 574 | 575 | .if !defined(NO_ROOTHACK) 576 | mfsroot: install prune cdboot config genkeys customfiles customscripts boot efiboot compress-usr packages install-roothack ${WRKDIR}/.mfsroot_done 577 | .else 578 | mfsroot: install prune cdboot config genkeys customfiles customscripts boot efiboot compress-usr packages ${WRKDIR}/.mfsroot_done 579 | .endif 580 | ${WRKDIR}/.mfsroot_done: 581 | @echo -n "Creating and compressing mfsroot ..." 582 | ${_v}${MKDIR} ${WRKDIR}/mnt 583 | ${_v}${MAKEFS} -t ffs -m ${MFSROOT_MAXSIZE} -f ${MFSROOT_FREE_INODES} -b ${MFSROOT_FREE_BLOCKS} ${WRKDIR}/disk/mfsroot ${_ROOTDIR} > /dev/null 584 | ${_v}${RM} -rf ${WRKDIR}/mnt 585 | ${_v}${GZIP} -9 -f ${WRKDIR}/disk/mfsroot 586 | ${_v}${GZIP} -9 -f ${WRKDIR}/disk/boot/kernel/kernel 587 | ${_v}if [ -f "${CFGDIR}/loader.conf" ]; then \ 588 | ${INSTALL} -m 0644 ${CFGDIR}/loader.conf ${WRKDIR}/disk/boot/loader.conf; \ 589 | else \ 590 | ${INSTALL} -m 0644 ${CFGDIR}/loader.conf.sample ${WRKDIR}/disk/boot/loader.conf; \ 591 | fi 592 | ${_v}${TOUCH} ${WRKDIR}/.mfsroot_done 593 | @echo " done" 594 | 595 | fbsddist: install prune cdboot config genkeys customfiles customscripts boot efiboot compress-usr packages mfsroot ${WRKDIR}/.fbsddist_done 596 | ${WRKDIR}/.fbsddist_done: 597 | .if defined(SE) 598 | @echo -n "Copying FreeBSD installation image ..." 599 | ${_v}${CP} -rf ${_DISTDIR} ${WRKDIR}/disk/ 600 | @echo " done" 601 | .endif 602 | ${_v}${TOUCH} ${WRKDIR}/.fbsddist_done 603 | 604 | image: install prune cdboot config genkeys customfiles customscripts boot efiboot compress-usr mfsroot fbsddist ${IMAGE} 605 | ${IMAGE}: 606 | @echo -n "Creating image file ..." 607 | .if defined(BSDPART) 608 | ${_v}${MKDIR} ${WRKDIR}/mnt ${WRKDIR}/trees/base/boot 609 | ${_v}${INSTALL} -m 0444 ${WRKDIR}/disk/boot/boot ${WRKDIR}/trees/base/boot/ 610 | ${_v}${DOFS} ${BSDLABEL} "" ${WRKDIR}/disk.img ${WRKDIR} ${WRKDIR}/mnt 0 ${WRKDIR}/disk 80000 auto > /dev/null 2> /dev/null 611 | ${_v}${RM} -rf ${WRKDIR}/mnt ${WRKDIR}/trees 612 | ${_v}${MV} ${WRKDIR}/disk.img ${.TARGET} 613 | .else 614 | ${_v}${TOOLSDIR}/do_gpt.sh ${.TARGET} ${WRKDIR}/disk 0 ${WRKDIR}/boot ${WRKDIR}/cdboot/efiboot.img ${VERB} 615 | .endif 616 | @echo " done" 617 | ${_v}${LS} -l ${.TARGET} 618 | 619 | gce: install prune cdboot config genkeys customfiles customscripts boot efiboot compress-usr mfsroot fbsddist ${IMAGE} ${GCEFILE} 620 | ${GCEFILE}: 621 | @echo -n "Creating GCE-compatible tarball..." 622 | .if !exists(${GTAR}) 623 | ${_v}echo "${GTAR} is missing, please install archivers/gtar first"; exit 1 624 | .else 625 | ${_v}${GTAR} -C ${.CURDIR} -Szcf ${GCEFILE} --transform='s/${IMAGE}/disk.raw/' ${IMAGE} 626 | @echo " GCE tarball built" 627 | ${_v}${LS} -l ${GCEFILE} 628 | .endif 629 | 630 | iso: install prune cdboot config genkeys customfiles customscripts boot efiboot compress-usr mfsroot fbsddist ${ISOIMAGE} 631 | ${ISOIMAGE}: 632 | @echo -n "Creating ISO image ..." 633 | .if !defined(NO_EFIBOOT) 634 | ${_v}${MAKEFS} -t cd9660 -o rockridge,label=mfsBSD \ 635 | -o bootimage=i386\;${WRKDIR}/cdboot/cdboot,no-emul-boot \ 636 | -o bootimage=i386\;${WRKDIR}/cdboot/efiboot.img,no-emul-boot,platformid=efi \ 637 | ${ISOIMAGE} ${WRKDIR}/disk 638 | .else 639 | ${_v}${MAKEFS} -t cd9660 -o rockridge,label=mfsBSD \ 640 | -o bootimage=i386\;${WRKDIR}/cdboot/cdboot,no-emul-boot \ 641 | ${ISOIMAGE} ${WRKDIR}/disk 642 | .endif 643 | @echo " done" 644 | ${_v}${LS} -l ${ISOIMAGE} 645 | 646 | tar: install prune cdboot config customfiles customscripts boot efiboot compress-usr mfsroot fbsddist ${TARFILE} 647 | ${TARFILE}: 648 | @echo -n "Creating tar file ..." 649 | ${_v}cd ${WRKDIR}/disk && ${FIND} . -depth 1 \ 650 | -exec ${TAR} -r -f ${.CURDIR}/${TARFILE} {} \; 651 | @echo " done" 652 | ${_v}${LS} -l ${TARFILE} 653 | 654 | prepare-mini: packages-mini config boot cdboot 655 | 656 | clean-roothack: 657 | ${_v}${RM} -rf ${WRKDIR}/roothack 658 | 659 | clean-pkgcache: 660 | ${_v}${RM} -rf ${WRKDIR}/pkgcache 661 | 662 | clean: 663 | ${_v}if [ -d ${WRKDIR} ]; then \ 664 | ${CHFLAGS} -R noschg ${WRKDIR} && \ 665 | cd ${WRKDIR} && \ 666 | ${RM} -rf boot mfs mnt disk dist trees cdboot efiroot .*_done; \ 667 | fi 668 | 669 | clean-all: clean clean-roothack clean-pkgcache 670 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mfsBSD 2 | 3 | Copyright (c) 2019 Martin Matuska 4 | 5 | Version 2.4 6 | 7 | ## Description 8 | 9 | This is a set of scripts that generates a bootable image, ISO file or boot 10 | files only, that create a working minimal installation of FreeBSD. This 11 | minimal installation gets completely loaded into memory. 12 | 13 | The image may be written directly using dd(1) onto any bootable block device, 14 | e.g. a hard disk or a USB stick e.g. /dev/da0, or a bootable slice only, 15 | e.g. /dev/ada0s1 16 | 17 | ## Build-time requirements 18 | - FreeBSD 11 or higher installed, tested on i386 or amd64 19 | - base.txz and kernel.txz from a FreeBSD 11 or higher distribution 20 | 21 | ## Runtime requirements 22 | - a minimum of 512MB system memory 23 | 24 | ## Other information 25 | 26 | See [BUILD](./BUILD.md) and [INSTALL](./INSTALL.md) for building and installation instructions. 27 | 28 | Project homepage: http://mfsbsd.vx.sk 29 | 30 | This project is based on the ideas of the depenguinator project: 31 | http://www.daemonology.net/depenguinator/ 32 | -------------------------------------------------------------------------------- /ci/ci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | BASE=/tmp/freebsd-dist 4 | RELEASE=${RELEASE:-`uname -r`} 5 | DOWNLOAD_URL=http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/${RELEASE} 6 | while getopts b:r: opt 7 | do 8 | case $opt in 9 | b) ACTION="${OPTARG}";; 10 | r) RELEASE="${OPTARG}";; 11 | esac 12 | done 13 | if [ "${ACTION}" = "prepare" ] 14 | then 15 | mkdir -p ${BASE} 16 | fetch -m -o ${BASE}/base.txz ${DOWNLOAD_URL}/base.txz 17 | fetch -m -o ${BASE}/kernel.txz ${DOWNLOAD_URL}/kernel.txz 18 | if [ -x tools/roothack/roothack ] 19 | then 20 | cd tools/roothack && make depend && make 21 | fi 22 | elif [ "${ACTION}" = "build-std" ] 23 | then 24 | make clean V=1 25 | make iso V=1 RELEASE=${RELEASE} BASE=${BASE} ROOTHACK=1 26 | make V=1 RELEASE=${RELEASE} BASE=${BASE} ROOTHACK=1 27 | elif [ "${ACTION}" = "build-se" ] 28 | then 29 | make clean V=1 30 | make iso V=1 RELEASE=${RELEASE} BASE=${BASE} ROOTHCK=1 SE=1 31 | make V=1 RELEASE=${RELEASE} BASE=${BASE} ROOTHACK=1 SE=1 32 | elif [ "${ACTION}" = "build-mini" ] 33 | then 34 | make clean V=1 35 | make prepare-mini V=1 RELEASE=${RELEASE} ROOTHACK=1 BASE=${BASE} 36 | cd mini 37 | make clean V=1 38 | make iso V=1 RELEASE=${RELEASE} ROOTHACK=1 BASE=${BASE} 39 | make clean V=1 40 | cd .. 41 | make clean V=1 42 | mv mini/*.iso . 43 | else 44 | echo "Unknown build step" 45 | false 46 | fi 47 | -------------------------------------------------------------------------------- /conf/authorized_keys.sample: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # Public SSH key(s) for root authorization 3 | -------------------------------------------------------------------------------- /conf/boot.config.sample: -------------------------------------------------------------------------------- 1 | -D 2 | -------------------------------------------------------------------------------- /conf/hosts.sample: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # 3 | # The file will be the /etc/hosts file in your image 4 | # 5 | ::1 localhost localhost.my.domain 6 | 127.0.0.1 localhost localhost.my.domain 7 | -------------------------------------------------------------------------------- /conf/interfaces.conf.sample: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # 3 | # If you don't know the exact interface names and/or order in which they 4 | # appear, you can configure interfaces depending on their MAC addresses here. 5 | 6 | # mac_interfaces should be a user-defined list of virtual interface names. 7 | #mac_interfaces="ext1 ext2" 8 | 9 | # ifconfig_FOO_mac should be the MAC address of interface FOO 10 | #ifconfig_ext1_mac="00:00:00:00:00:00" 11 | #ifconfig_ext2_mac="ff:ff:ff:ff:ff:ff" 12 | 13 | # ifconfig_FOO should be configured like the real interface behind FOO 14 | # for more information, see ifconfig(8) 15 | #ifconfig_ext1="inet 192.168.0.1/24" 16 | #ifconfig_ext2="inet 192.168.1.1/24" 17 | -------------------------------------------------------------------------------- /conf/loader.conf.sample: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # 3 | # This is the /boot/loader.conf of your image 4 | # 5 | # Custom mfsbsd variables 6 | # 7 | # Set all auto-detected interfaces to DHCP 8 | #mfsbsd.autodhcp="YES" 9 | # 10 | # Define a new root password 11 | #mfsbsd.rootpw="foobar" 12 | # 13 | # Alternatively define a root password hash like in master.passwd 14 | # NOTICE: replace '$' characters with '%' 15 | #mfsbsd.rootpwhash="" 16 | # 17 | # Add additional nameservers here 18 | #mfsbsd.nameservers="192.168.1.1 192.168.1.2" 19 | # 20 | # Change system hostname 21 | #mfsbsd.hostname="mfsbsd" 22 | # 23 | # List of interfaces to be set 24 | #mfsbsd.interfaces="em0 em1" 25 | # 26 | # Individual configuration of each interface 27 | #mfsbsd.ifconfig_em0="DHCP" 28 | #mfsbsd.ifconfig_em1="DHCP" 29 | # 30 | # List of special interfaces to be created 31 | #mfsbsd.cloned_interfaces="" 32 | # 33 | # List of mac_interfaces (see interfaces.conf.sample) 34 | #mfsbsd.mac_interfaces="eth0" 35 | #mfsbsd.ifconfig_eth0_mac="xx:xx:xx:xx:xx:xx" 36 | #mfsbsd.ifconfig_eth0="inet 192.168.1.10/24" 37 | # 38 | # Default router 39 | #mfsbsd.defaultrouter="192.168.1.1" 40 | # 41 | # List of static routes and their definitions 42 | #mfsbsd.static_routes="r1 r2" 43 | #mfsbsd.route_r1="-net 192.168.2 192.168.1.1" 44 | #mfsbsd.route_r2="-net 192.168.3 192.168.1.1" 45 | 46 | # 47 | # Do not change anything here until you know what you are doing 48 | # 49 | mfs_load="YES" 50 | mfs_type="mfs_root" 51 | mfs_name="/mfsroot" 52 | ahci_load="YES" 53 | vfs.root.mountfrom="ufs:/dev/md0" 54 | mfsbsd.autodhcp="YES" 55 | -------------------------------------------------------------------------------- /conf/rc.conf.sample: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # 3 | # This will be the rc.conf file in your image. 4 | # 5 | # You may set anything you want here, including network interfaces. 6 | # If you are not sure about network interface names and/or their order, 7 | # see the interfaces.conf file in this directory. 8 | # 9 | # Set this to any desired hostname 10 | hostname="mfsbsd" 11 | # 12 | # You need a gateway defined for a working network setup 13 | #defaultrouter="192.168.0.254" 14 | # 15 | # You may configure a network interface here, you may use "DHCP" as well 16 | #ifconfig_em0="inet 192.168.0.1 netmask 255.255.255.0" 17 | #ifconfig_rl0="DHCP" 18 | # 19 | # Change the values below only if you know what you are doing! 20 | # 21 | sshd_enable="YES" 22 | sendmail_enable="NONE" 23 | cron_enable="NO" 24 | local_enable="YES" 25 | -------------------------------------------------------------------------------- /conf/rc.local.sample: -------------------------------------------------------------------------------- 1 | # sample rc.local 2 | # add your code below -------------------------------------------------------------------------------- /conf/resolv.conf.sample: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # 3 | # The file will be the /etc/resolv.conf file in your image 4 | # 5 | #domain com 6 | #nameserver 192.168.0.254 7 | -------------------------------------------------------------------------------- /conf/ttys.sample: -------------------------------------------------------------------------------- 1 | # $FreeBSD$ 2 | # 3 | console none unknown off secure 4 | # 5 | ttyv0 "/usr/libexec/getty Pc" xterm on secure 6 | # Virtual terminals 7 | ttyv1 "/usr/libexec/getty Pc" xterm off secure 8 | ttyv2 "/usr/libexec/getty Pc" xterm off secure 9 | ttyv3 "/usr/libexec/getty Pc" xterm off secure 10 | ttyv4 "/usr/libexec/getty Pc" xterm off secure 11 | ttyv5 "/usr/libexec/getty Pc" xterm off secure 12 | ttyv6 "/usr/libexec/getty Pc" xterm off secure 13 | ttyv7 "/usr/libexec/getty Pc" xterm off secure 14 | ttyv8 "/usr/local/bin/xdm -nodaemon" xterm off secure 15 | # Serial terminals 16 | # The 'dialup' keyword identifies dialin lines to login, fingerd etc. 17 | ttyu0 "/usr/libexec/getty 3wire" vt100 onifconsole secure 18 | ttyu1 "/usr/libexec/getty 3wire" vt100 onifconsole secure 19 | ttyu2 "/usr/libexec/getty 3wire" vt100 onifconsole secure 20 | ttyu3 "/usr/libexec/getty 3wire" vt100 onifconsole secure 21 | # Dumb console 22 | dcons "/usr/libexec/getty std.9600" vt100 off secure 23 | -------------------------------------------------------------------------------- /mini/Makefile: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # 3 | # mfsBSD-mini 4 | # Copyright (c) 2018 Martin Matuska 5 | # 6 | # Version 0.2 7 | # 8 | 9 | # 10 | # User-defined variables 11 | # 12 | BASEDIR?=${CURDIR}/../work/mfs/rw 13 | BOOTBASE?=${CURDIR}/../work/disk/boot 14 | CDBOOTBASE?=${CURDIR}/../work/cdboot 15 | CFGDIR?=${CURDIR}/conf 16 | MFSROOT_FREE_INODES?=5000 17 | MFSROOT_FREE_BLOCKS?=10% 18 | MFSROOT_MINSIZE?=80m 19 | MFSROOT_MAXSIZE?=80m 20 | ROOTPW_HASH?=$$6$$051DdQA7fTvLymkY$$Z5f6snVFQJKugWmGi8y0motBNaKn9em0y2K0ZsJMku3v9gkiYh8M.OTIIie3RvHpzT6udumtZUtc0kXwJcCMR1 21 | LOCALBASEDIR?=${BASEDIR} 22 | 23 | .if defined(LOADER_4TH) 24 | BOOTFILES?= defaults device.hints loader *.rc *.4th 25 | EFILOADER?= loader_4th.efi 26 | .else 27 | BOOTFILES?= defaults device.hints loader lua 28 | EFILOADER?= loader_lua.efi 29 | .endif 30 | 31 | # 32 | # Program defaults 33 | # 34 | CAT=/bin/cat 35 | CHFLAGS=/bin/chflags 36 | CHOWN=/usr/sbin/chown 37 | CP=/bin/cp 38 | DIRNAME=/usr/bin/dirname 39 | FIND=/usr/bin/find 40 | GTAR=/usr/local/bin/gtar 41 | GZIP=/usr/bin/gzip 42 | INSTALL=/usr/bin/install 43 | LN=/bin/ln 44 | LS=/bin/ls 45 | MAKEFS=/usr/sbin/makefs 46 | MKDIR=/bin/mkdir -p 47 | MTREE=/usr/sbin/mtree 48 | MV=/bin/mv 49 | OPENSSL=/usr/bin/openssl 50 | PW=/usr/sbin/pw 51 | PWD=/bin/pwd 52 | RM=/bin/rm 53 | RMDIR=/bin/rmdir 54 | SYSCTL=/sbin/sysctl 55 | TAR=/usr/bin/tar 56 | TOUCH=/usr/bin/touch 57 | UNAME=/usr/bin/uname 58 | # 59 | BSDLABEL=bsdlabel 60 | 61 | # 62 | CURDIR!=${PWD} 63 | WRKDIR?=${CURDIR}/tmp 64 | FILESDIR=${CURDIR}/files 65 | TOOLSDIR=${CURDIR}/../tools 66 | # 67 | # 68 | DOFS=${TOOLSDIR}/doFS.sh 69 | BOOTMODULES=acpi ahci 70 | MFSMODULES=geom_mirror geom_nop opensolaris zfs ext2fs smbus ipmi ntfs nullfs tmpfs \ 71 | aesni crypto cryptodev geom_eli 72 | # 73 | .if defined(V) 74 | _v= 75 | VERB=1 76 | .else 77 | _v=@ 78 | VERB= 79 | .endif 80 | 81 | .if !defined(ARCH) 82 | TARGET!= ${SYSCTL} -n hw.machine_arch 83 | .else 84 | TARGET= ${ARCH} 85 | .endif 86 | 87 | .if !defined(RELEASE) 88 | RELEASE!=${UNAME} -r 89 | .endif 90 | 91 | IMAGE_PREFIX=mfsbsd-mini 92 | 93 | IMAGE?= ${IMAGE_PREFIX}-${RELEASE}-${TARGET}.img 94 | ISOIMAGE?= ${IMAGE_PREFIX}-${RELEASE}-${TARGET}.iso 95 | TARFILE?= ${IMAGE_PREFIX}-${RELEASE}-${TARGET}.tar 96 | GCEFILE?= ${IMAGE_PREFIX}-${RELEASE}-${TARGET}.tar.gz 97 | _DISTDIR= ${WRKDIR}/dist/${RELEASE}-${TARGET} 98 | 99 | .if !defined(DEBUG) 100 | EXCLUDE=--exclude *.symbols 101 | .else 102 | EXCLUDE= 103 | .endif 104 | 105 | _ROOTDIR= ${WRKDIR}/mfs 106 | _BOOTDIR= ${_ROOTDIR}/boot 107 | _MODULESDIR= ${BASEDIR}/boot/modules 108 | 109 | all: image 110 | 111 | destdir: ${_ROOTDIR} ${_BOOTDIR} 112 | ${_ROOTDIR}: 113 | ${_v}${MKDIR} ${_ROOTDIR} && ${CHOWN} root:wheel ${_ROOTDIR} 114 | 115 | ${_BOOTDIR}: 116 | ${_v}${MKDIR} ${_BOOTDIR}/kernel ${_BOOTDIR}/modules && ${CHOWN} -R root:wheel ${_BOOTDIR} 117 | 118 | hierarchy: destdir ${WRKDIR}/.hierarchy_done 119 | ${WRKDIR}/.hierarchy_done: 120 | ${_v}echo -n "Creating directory hierarchy ..." 121 | ${_v}${MTREE} -deU -f ${BASEDIR}/etc/mtree/BSD.root.dist -p ${_ROOTDIR} > /dev/null 122 | ${_v}${MTREE} -deU -f ${BASEDIR}/etc/mtree/BSD.usr.dist -p ${_ROOTDIR}/usr > /dev/null 123 | ${_v}${TOUCH} ${WRKDIR}/.hierarchy_done 124 | ${_v}echo " done" 125 | 126 | installkernel: ${_BOOTDIR} ${WRKDIR}/.installkernel_done 127 | ${WRKDIR}/.installkernel_done: 128 | ${_v}echo -n "Installing kernel ..." 129 | ${_v}${CP} -a ${BOOTBASE}/ ${_BOOTDIR} 130 | ${_v}${TOUCH} ${WRKDIR}/.installkernel_done 131 | ${_v}echo " done" 132 | 133 | rescuelinks: hierarchy ${WRKDIR}/.rescuelinks_done 134 | ${WRKDIR}/.rescuelinks_done: 135 | ${_v}echo -n "Installing rescue with linking script ..." 136 | ${_v}${INSTALL} -m 0555 ${BASEDIR}/rescue/rescue ${_ROOTDIR}/rescue/rescue 137 | ${_v}for FILE in `cat ${FILESDIR}/rescuelinks`; do \ 138 | ${LN} ${_ROOTDIR}/rescue/rescue ${_ROOTDIR}/$${FILE}; \ 139 | done 140 | ${_v}${TOUCH} ${WRKDIR}/.rescuelinks_done 141 | ${_v}echo " done" 142 | 143 | installbase: hierarchy rescuelinks ${WRKDIR}/.installbase_done 144 | ${WRKDIR}/.installbase_done: 145 | ${_v}echo -n "Installing base files ..." 146 | ${_v}cd ${_ROOTDIR} && for FILE in `cat ${FILESDIR}/instfiles`; do \ 147 | ${CP} -pP ${BASEDIR}/$${FILE} ${_ROOTDIR}/$${FILE}; \ 148 | done 149 | ${_v}cd ${_ROOTDIR} && for DIR in `cat ${FILESDIR}/instdirs`; do \ 150 | ${CP} -a ${BASEDIR}/$${DIR}/ ${_ROOTDIR}/$${DIR}; \ 151 | done 152 | ${_v}${TOUCH} ${WRKDIR}/.installbase_done 153 | ${_v}echo " done" 154 | 155 | basetar: hierarchy rescuelinks ${WRKDIR}/.basetar_done 156 | ${WRKDIR}/.basetar_done: 157 | ${_v}echo -n "Creating tar of base libraries and binaries ..." 158 | ${_v}cd ${BASEDIR} && ${TAR} -cJf ${_ROOTDIR}/.mfs_base.txz \ 159 | `cat ${FILESDIR}/basedirs` `cat ${FILESDIR}/basefiles` || exit 0 160 | ${_v}${TOUCH} ${WRKDIR}/.basetar_done 161 | ${_v}echo " done" 162 | 163 | localtar: hierarchy ${WRKDIR}/.localtar_done 164 | ${WRKDIR}/.localtar_done: 165 | .if exists(${FILESDIR}/localfiles) 166 | ${_v}echo -n "Creating local files tar ..." 167 | ${_v}cd ${LOCALBASEDIR}/usr/local && ${TAR} -cJf ${_ROOTDIR}/.mfs_local.txz \ 168 | `cat ${FILESDIR}/localfiles` 169 | ${_v}${TOUCH} ${WRKDIR}/.localtar_done 170 | ${_v}echo " done" 171 | .endif 172 | 173 | install: installbase basetar localtar 174 | 175 | config: install ${WRKDIR}/.config_done 176 | ${WRKDIR}/.config_done: 177 | ${_v}echo -n "Installing configuration scripts and files ..." 178 | ${_v}if [ -f "${CFGDIR}/loader.conf" ]; then \ 179 | ${INSTALL} -m 0644 ${CFGDIR}/loader.conf ${_BOOTDIR}/loader.conf; \ 180 | else \ 181 | ${INSTALL} -m 0644 ${CFGDIR}/loader.conf.sample ${_BOOTDIR}/loader.conf; \ 182 | fi 183 | .for FILE in rc hosts ttys resolv.conf rc.local 184 | ${_v}if [ -f "${CFGDIR}/${FILE}" ]; then \ 185 | ${INSTALL} -m 0644 ${CFGDIR}/${FILE} ${_ROOTDIR}/etc/${FILE}; \ 186 | elif [ -f "${CFGDIR}/${FILE}.sample" ]; then \ 187 | ${INSTALL} -m 0644 ${CFGDIR}/${FILE}.sample ${_ROOTDIR}/etc/${FILE}; \ 188 | fi 189 | .endfor 190 | ${_v}${MKDIR} ${_ROOTDIR}/root/bin 191 | .for FILE in .cshrc .profile 192 | ${_v}if [ -f "${CFGDIR}/${FILE}" ]; then \ 193 | ${INSTALL} -m 0644 ${CFGDIR}/${FILE} ${_ROOTDIR}/root/${FILE}; \ 194 | elif [ -f "${CFGDIR}/${FILE}.sample" ]; then \ 195 | ${INSTALL} -m 0644 ${CFGDIR}/${FILE}.sample ${_ROOTDIR}/root/${FILE}; \ 196 | fi 197 | .endfor 198 | ${_v}${INSTALL} ${TOOLSDIR}/zfsinstall ${_ROOTDIR}/root/bin 199 | ${_v}${INSTALL} ${TOOLSDIR}/destroygeom ${_ROOTDIR}/root/bin 200 | ${_v}echo "/dev/md0 / ufs rw 0 0" > ${_ROOTDIR}/etc/fstab 201 | ${_v}echo "tmpfs /tmp tmpfs rw,mode=1777 0 0" >> ${_ROOTDIR}/etc/fstab 202 | .if defined(ROOTPW) 203 | ${_v}echo '${ROOTPW}'| ${OPENSSL} passwd -6 -stdin | ${PW} -V ${_ROOTDIR}/etc usermod root -H 0 204 | .elif !empty(ROOTPW_HASH) 205 | ${_v}echo '${ROOTPW_HASH}'| ${PW} -V ${_ROOTDIR}/etc usermod root -H 0 206 | .endif 207 | ${_v}${TOUCH} ${WRKDIR}/.config_done 208 | ${_v}echo " done" 209 | 210 | boot: installkernel install ${WRKDIR}/.boot_done 211 | ${WRKDIR}/.boot_done: 212 | ${_v}echo -n "Configuring boot environment ..." 213 | ${_v}${MKDIR} ${WRKDIR}/disk/boot && ${CHOWN} root:wheel ${WRKDIR}/disk 214 | ${_v}${RM} -f ${_BOOTDIR}/kernel/kernel.debug 215 | ${_v}${CP} -rp ${_BOOTDIR}/kernel ${WRKDIR}/disk/boot 216 | .for FILE in ${BOOTFILES} 217 | ${_v}${CP} -rp ${_ROOTDIR}/boot/${FILE} ${WRKDIR}/disk/boot 218 | .endfor 219 | ${_v}${RM} -rf ${WRKDIR}/disk/boot/kernel/*.ko ${WRKDIR}/disk/boot/kernel/*.symbols 220 | .if defined(DEBUG) 221 | ${_v}test -f ${_BOOTDIR}/kernel/kernel.symbols \ 222 | && ${INSTALL} -m 0555 ${_BOOTDIR}/kernel/kernel.symbols ${WRKDIR}/disk/boot/kernel >/dev/null 2>/dev/null || exit 0 223 | .endif 224 | .for FILE in ${BOOTMODULES} 225 | ${_v}test -f ${_BOOTDIR}/kernel/${FILE}.ko \ 226 | && ${INSTALL} -m 0555 ${_BOOTDIR}/kernel/${FILE}.ko ${WRKDIR}/disk/boot/kernel >/dev/null 2>/dev/null || exit 0 227 | . if defined(DEBUG) 228 | ${_v}test -f ${_BOOTDIR}/kernel/${FILE}.ko \ 229 | && ${INSTALL} -m 0555 ${_BOOTDIR}/kernel/${FILE}.ko.symbols ${WRKDIR}/disk/boot/kernel >/dev/null 2>/dev/null || exit 0 230 | . endif 231 | .endfor 232 | ${_v}${MKDIR} ${_ROOTDIR}/boot/modules 233 | .for FILE in ${MFSMODULES} 234 | ${_v}test -f ${_MODULESDIR}/${FILE}.ko \ 235 | && ${INSTALL} -m 0555 ${_MODULESDIR}/${FILE}.ko ${_ROOTDIR}/boot/modules >/dev/null 2>/dev/null || exit 0 236 | . if defined(DEBUG) 237 | ${_v}test -f ${_MODULESDIR}/${FILE}.ko.symbols \ 238 | && ${INSTALL} -m 0555 ${_MODULESDIR}/${FILE}.ko.symbols ${_ROOTDIR}/boot/modules >/dev/null 2>/dev/null || exit 0 239 | . endif 240 | .endfor 241 | ${_v}${RM} -rf ${_BOOTDIR}/kernel ${_BOOTDIR}/*.symbols 242 | ${_v}${TOUCH} ${WRKDIR}/.boot_done 243 | ${_v}echo " done" 244 | 245 | efiboot: boot ${WRKDIR}/.efiboot_done 246 | ${WRKDIR}/.efiboot_done: 247 | .if !defined(NO_EFIBOOT) 248 | @echo -n "Creating EFI boot image ..." 249 | ${_v}${MKDIR} -p ${WRKDIR}/efiroot/EFI/BOOT ${WRKDIR}/cdboot 250 | ${_v}${CP} ${CDBOOTBASE}/${EFILOADER} ${WRKDIR}/efiroot/EFI/BOOT/BOOTX64.efi 251 | ${_v}${MAKEFS} -t msdos -s 2048k -o fat_type=12,sectors_per_cluster=1,volume_label=EFISYS ${WRKDIR}/cdboot/efiboot.img ${WRKDIR}/efiroot 252 | ${_v}${TOUCH} ${WRKDIR}/.efiboot_done 253 | @echo " done" 254 | .endif 255 | 256 | boottar: boot ${WRKDIR}/.boottar_done 257 | ${WRKDIR}/.boottar_done: 258 | ${_v}echo -n "Compressing mfsroot boot ..." 259 | ${_v}${TAR} -c -J -C ${_ROOTDIR} -f ${_ROOTDIR}/.mfs_boot.txz boot 260 | ${_v}cd ${_ROOTDIR} && ${RM} -rf boot 261 | ${_v}${TOUCH} ${WRKDIR}/.boottar_done 262 | ${_v}echo " done" 263 | 264 | mfsroot: boottar ${WRKDIR}/.mfsroot_done 265 | ${WRKDIR}/.mfsroot_done: 266 | ${_v}echo -n "Creating and compressing mfsroot ..." 267 | ${_v}${MKDIR} ${WRKDIR}/mnt 268 | ${_v}${MAKEFS} -t ffs -M ${MFSROOT_MINSIZE} -m ${MFSROOT_MAXSIZE} -f ${MFSROOT_FREE_INODES} -b ${MFSROOT_FREE_BLOCKS} ${WRKDIR}/disk/mfsroot ${_ROOTDIR} > /dev/null 269 | ${_v}${RM} -rf ${WRKDIR}/mnt 270 | ${_v}${GZIP} -9 -f ${WRKDIR}/disk/mfsroot 271 | ${_v}${GZIP} -9 -f ${WRKDIR}/disk/boot/kernel/kernel 272 | ${_v}if [ -f "${CFGDIR}/loader.conf" ]; then \ 273 | ${INSTALL} -m 0644 ${CFGDIR}/loader.conf ${WRKDIR}/disk/boot/loader.conf; \ 274 | else \ 275 | ${INSTALL} -m 0644 ${CFGDIR}/loader.conf.sample ${WRKDIR}/disk/boot/loader.conf; \ 276 | fi 277 | ${_v}${TOUCH} ${WRKDIR}/.mfsroot_done 278 | ${_v}echo " done" 279 | 280 | image: install config boot mfsroot ${IMAGE} 281 | ${IMAGE}: 282 | @echo -n "Creating image file ..." 283 | .if defined(BSDPART) 284 | ${_v}${MKDIR} ${WRKDIR}/mnt ${WRKDIR}/trees/base/boot 285 | ${_v}${INSTALL} -m 0444 ${WRKDIR}/disk/boot/boot ${WRKDIR}/trees/base/boot/ 286 | ${_v}${DOFS} ${BSDLABEL} "" ${WRKDIR}/disk.img ${WRKDIR} ${WRKDIR}/mnt 0 ${WRKDIR}/disk 80000 auto > /dev/null 2> /dev/null 287 | ${_v}${RM} -rf ${WRKDIR}/mnt ${WRKDIR}/trees 288 | ${_v}${MV} ${WRKDIR}/disk.img ${.TARGET} 289 | .else 290 | ${_v}${TOOLSDIR}/do_gpt.sh ${.TARGET} ${WRKDIR}/disk 0 ${BASEDIR}/boot ${WRKDIR}/cdboot/efiboot.img ${VERB} 291 | .endif 292 | @echo " done" 293 | ${_v}${LS} -l ${.TARGET} 294 | 295 | gce: install config boot mfsroot ${IMAGE} ${GCEFILE} 296 | ${GCEFILE}: 297 | ${_v}echo -n "Creating GCE-compatible tarball..." 298 | .if !exists(${GTAR}) 299 | ${_v}echo "${GTAR} is missing, please install archivers/gtar first"; exit 1 300 | .else 301 | ${_v}${GTAR} -C ${CURDIR} -Szcf ${GCEFILE} --transform='s/${IMAGE}/disk.raw/' ${IMAGE} 302 | ${_v}echo " GCE tarball built" 303 | ${_v}${LS} -l ${GCEFILE} 304 | .endif 305 | 306 | iso: install config boot efiboot mfsroot ${ISOIMAGE} 307 | ${ISOIMAGE}: 308 | ${_v}echo -n "Creating ISO image ..." 309 | .if !defined(NO_EFIBOOT) 310 | ${_v}${MAKEFS} -t cd9660 -o rockridge,label=mfsBSD \ 311 | -o bootimage=i386\;${CDBOOTBASE}/cdboot,no-emul-boot \ 312 | -o bootimage=i386\;${WRKDIR}/cdboot/efiboot.img,no-emul-boot,platformid=efi \ 313 | ${ISOIMAGE} ${WRKDIR}/disk 314 | .else 315 | ${_v}${MAKEFS} -t cd9660 -o rockridge,label=mfsBSD \ 316 | -o bootimage=i386\;${CDBOOTBASE}/cdboot,no-emul-boot \ 317 | ${ISOIMAGE} ${WRKDIR}/disk 318 | .endif 319 | ${_v}echo " done" 320 | ${_v}${LS} -l ${ISOIMAGE} 321 | 322 | tar: install config boot mfsroot ${TARFILE} 323 | ${TARFILE}: 324 | ${_v}echo -n "Creating tar file ..." 325 | ${_v}cd ${WRKDIR}/disk && ${FIND} . -depth 1 \ 326 | -exec ${TAR} -r -f ${CURDIR}/${TARFILE} {} \; 327 | ${_v}echo " done" 328 | ${_v}${LS} -l ${TARFILE} 329 | 330 | clean: 331 | ${_v}if [ -d ${WRKDIR} ]; then \ 332 | ${CHFLAGS} -R noschg ${WRKDIR} && \ 333 | cd ${WRKDIR} && ${RM} -rf mfs mnt disk dist trees efiroot cdboot .*_done; \ 334 | fi 335 | -------------------------------------------------------------------------------- /mini/README.md: -------------------------------------------------------------------------------- 1 | # mfsBSD-mini 2 | 3 | Copyright (c) 2019 Martin Matuska 4 | 5 | ## Description 6 | 7 | This is a set of scripts that generates a small bootable image, ISO file or 8 | tar archive from a installed FreeBSD system. The image gets completely loaded 9 | into memory. 10 | 11 | The image may be written directly using dd(1) onto any bootable block device, 12 | e.g. a hard disk or a USB stick e.g. /dev/da0, or a bootable partition only, 13 | e.g. /dev/ada0p2 14 | 15 | ## Building 16 | 17 | You need to do "make prepare-mini" in the main mfsBSD directory 18 | 19 | Project homepage: http://mfsbsd.vx.sk 20 | -------------------------------------------------------------------------------- /mini/conf/.cshrc.sample: -------------------------------------------------------------------------------- 1 | # $FreeBSD: releng/10.1/etc/root/dot.cshrc 243893 2012-12-05 13:56:39Z eadler $ 2 | # 3 | # .cshrc - csh resource script, read at beginning of execution by each shell 4 | # 5 | # see also csh(1), environ(7). 6 | # more examples available at /usr/share/examples/csh/ 7 | # 8 | 9 | alias h history 25 10 | alias j jobs -l 11 | alias la ls -aF 12 | alias lf ls -FA 13 | alias ll ls -lAF 14 | 15 | # A righteous umask 16 | umask 22 17 | 18 | set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin) 19 | 20 | setenv EDITOR vi 21 | setenv PAGER more 22 | setenv BLOCKSIZE K 23 | 24 | if ($?prompt) then 25 | # An interactive shell -- set some stuff up 26 | set prompt = "%N@%m:%~ %# " 27 | set promptchars = "%#" 28 | 29 | set filec 30 | set history = 1000 31 | set savehist = (1000 merge) 32 | set autolist = ambiguous 33 | # Use history to aid expansion 34 | set autoexpand 35 | set autorehash 36 | set mail = (/var/mail/$USER) 37 | if ( $?tcsh ) then 38 | bindkey "^W" backward-delete-word 39 | bindkey -k up history-search-backward 40 | bindkey -k down history-search-forward 41 | endif 42 | 43 | endif 44 | -------------------------------------------------------------------------------- /mini/conf/.profile.sample: -------------------------------------------------------------------------------- 1 | # $FreeBSD: releng/10.1/etc/root/dot.profile 199243 2009-11-13 05:54:55Z ed $ 2 | # 3 | PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:~/bin 4 | export PATH 5 | HOME=/root 6 | export HOME 7 | TERM=${TERM:-xterm} 8 | export TERM 9 | PAGER=more 10 | export PAGER 11 | -------------------------------------------------------------------------------- /mini/conf/hosts.sample: -------------------------------------------------------------------------------- 1 | # $Id$ 2 | # 3 | # The file will be the /etc/hosts file in your image 4 | # 5 | ::1 localhost localhost.my.domain 6 | 127.0.0.1 localhost localhost.my.domain 7 | -------------------------------------------------------------------------------- /mini/conf/loader.conf.sample: -------------------------------------------------------------------------------- 1 | mfs_load="YES" 2 | mfs_type="mfs_root" 3 | mfs_name="/mfsroot" 4 | vfs.root.mountfrom="ufs:/dev/md0" 5 | -------------------------------------------------------------------------------- /mini/conf/rc.local: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ldconfig /usr/local/lib 3 | ln -s /usr/local/bin/dbclient /usr/bin/dbclient 4 | ln -s /usr/local/bin/dbclient /usr/local/bin/ssh 5 | mkdir -p /usr/local/etc/dropbear 6 | /usr/local/sbin/dropbear -R 7 | -------------------------------------------------------------------------------- /mini/conf/rc.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | HOME=/ 3 | PATH=/sbin:/bin/:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin 4 | export HOME PATH 5 | 6 | # REMOUT ROOT 7 | mount -uw / 8 | 9 | # EXTRACT BOOT 10 | tar -x -J -C / -f /.mfs_boot.txz 11 | 12 | # MOUNT TMPFS FILESYSTEMS 13 | mount -t tmpfs tmpfs /tmp 14 | mount -t tmpfs tmpfs /var 15 | mount -t tmpfs tmpfs /usr/local 16 | 17 | # EXTRACT BASE and LOCAL 18 | tar -x -J -C / -f /.mfs_base.txz 19 | [ -f /.mfs_local.txz ] && tar -x -J -C /usr/local -f /.mfs_local.txz 20 | 21 | # VAR 22 | mtree -deU -f /etc/mtree/BSD.var.dist -p /var > /dev/null 23 | touch /var/log/utx.lastlogin /var/log/utx.log 24 | cap_mkdb -f /tmp/termcap /etc/termcap.small 25 | 26 | # NETWORKING 27 | ifconfig lo0 inet 127.0.0.1/8 28 | for i in `ifconfig -l`; do 29 | if [ "$i" != "lo0" ]; then 30 | dhclient $i 31 | fi 32 | done 33 | hostname mfsbsd 34 | 35 | # SERVERS 36 | newsyslog -C 37 | syslogd -s 38 | 39 | # LOCAL 40 | [ -f /etc/rc.local ] && . /etc/rc.local 41 | -------------------------------------------------------------------------------- /mini/conf/ttys.sample: -------------------------------------------------------------------------------- 1 | # $FreeBSD$ 2 | # 3 | console none unknown off secure 4 | # 5 | ttyv0 "/usr/libexec/getty Pc" xterm on secure 6 | # Virtual terminals 7 | ttyv1 "/usr/libexec/getty Pc" xterm off secure 8 | ttyv2 "/usr/libexec/getty Pc" xterm off secure 9 | ttyv3 "/usr/libexec/getty Pc" xterm off secure 10 | ttyv4 "/usr/libexec/getty Pc" xterm off secure 11 | ttyv5 "/usr/libexec/getty Pc" xterm off secure 12 | ttyv6 "/usr/libexec/getty Pc" xterm off secure 13 | ttyv7 "/usr/libexec/getty Pc" xterm off secure 14 | ttyv8 "/usr/local/bin/xdm -nodaemon" xterm off secure 15 | # Serial terminals 16 | # The 'dialup' keyword identifies dialin lines to login, fingerd etc. 17 | ttyu0 "/usr/libexec/getty 3wire" vt100 onifconsole secure 18 | ttyu1 "/usr/libexec/getty 3wire" vt100 onifconsole secure 19 | ttyu2 "/usr/libexec/getty 3wire" vt100 onifconsole secure 20 | ttyu3 "/usr/libexec/getty 3wire" vt100 onifconsole secure 21 | # Dumb console 22 | dcons "/usr/libexec/getty std.9600" vt100 off secure 23 | -------------------------------------------------------------------------------- /mini/files/basedirs: -------------------------------------------------------------------------------- 1 | lib/geom 2 | libexec 3 | usr/libexec/bsdconfig 4 | usr/libexec/bsdinstall 5 | usr/share/bsdconfig 6 | usr/share/locale/C.UTF-8 7 | usr/share/locale/en_US.UTF-8 8 | usr/share/syscons 9 | usr/share/zoneinfo 10 | -------------------------------------------------------------------------------- /mini/files/basefiles: -------------------------------------------------------------------------------- 1 | bin/domainname 2 | bin/sleep 3 | sbin/dhclient-script 4 | sbin/geli 5 | sbin/gnop 6 | sbin/poweroff 7 | sbin/resolvconf 8 | sbin/rmd160 9 | sbin/sha1 10 | sbin/sha256 11 | sbin/sha512 12 | sbin/shutdown 13 | lib/casper/libcap_dns.so* 14 | lib/casper/libcap_fileargs.so* 15 | lib/libalias* 16 | lib/libbegemot.so* 17 | lib/libbsdxml.so* 18 | lib/libc.so* 19 | lib/libcam.so* 20 | lib/libcasper.so* 21 | lib/libcrypt.so* 22 | lib/libcrypto.so* 23 | lib/libctf.so* 24 | lib/libcxxrt.so* 25 | lib/libdevstat.so* 26 | lib/libedit.so* 27 | lib/libelf.so* 28 | lib/libgcc_s.so* 29 | lib/libgeom.so* 30 | lib/libibverbs.so* 31 | lib/libipsec.so* 32 | lib/libjail.so* 33 | lib/libkiconv.so* 34 | lib/libkvm.so* 35 | lib/libm.so* 36 | lib/libmd.so* 37 | lib/libmlx5.so* 38 | lib/libncursesw.so* 39 | lib/libnv.so* 40 | lib/libpcap.so* 41 | lib/libsbuf.so* 42 | lib/libssp.so* 43 | lib/libtinfow.so.* 44 | lib/libthr.so* 45 | lib/libufs.so* 46 | lib/libulog.so* 47 | lib/libutil.so* 48 | lib/libxo.so* 49 | lib/libz.so* 50 | usr/bin/awk 51 | usr/bin/basename 52 | usr/bin/bc 53 | usr/bin/cap_mkdb 54 | usr/bin/cut 55 | usr/bin/dc 56 | usr/bin/b64decode 57 | usr/bin/b64encode 58 | usr/bin/dialog 59 | usr/bin/dirname 60 | usr/bin/du 61 | usr/bin/false 62 | usr/bin/fetch 63 | usr/bin/file 64 | usr/bin/find 65 | usr/bin/grep 66 | usr/bin/last 67 | usr/bin/ldd 68 | usr/bin/login 69 | usr/bin/openssl 70 | usr/bin/passwd 71 | usr/bin/sort 72 | usr/bin/top 73 | usr/bin/touch 74 | usr/bin/true 75 | usr/bin/uname 76 | usr/bin/uniq 77 | usr/bin/uptime 78 | usr/bin/uudecode 79 | usr/bin/uuencode 80 | usr/bin/w 81 | usr/bin/wall 82 | usr/bin/wc 83 | usr/bin/which 84 | usr/bin/who 85 | usr/bin/xargs 86 | usr/lib/libarchive.so* 87 | usr/lib/libbsm.so* 88 | usr/lib/libbz2.so* 89 | usr/lib/libc++.so* 90 | usr/lib/libcap_dns.so* 91 | usr/lib/libcap_fileargs.so* 92 | usr/lib/libdialog.so* 93 | usr/lib/libdevctl.so* 94 | usr/lib/libdevinfo.so* 95 | usr/lib/libfetch.so* 96 | usr/lib/liblzma.so* 97 | usr/lib/libmagic.so* 98 | usr/lib/libopie.so* 99 | usr/lib/libpam.so* 100 | usr/lib/libregex.so* 101 | usr/lib/librt.so* 102 | usr/lib/libssl.so* 103 | usr/lib/libusb.so* 104 | usr/lib/libypclnt.so* 105 | usr/lib/pam_deny.so* 106 | usr/lib/pam_group.so* 107 | usr/lib/pam_lastlog.so* 108 | usr/lib/pam_login_access.so* 109 | usr/lib/pam_nologin.so* 110 | usr/lib/pam_opie.so* 111 | usr/lib/pam_opieaccess.so* 112 | usr/lib/pam_permit.so* 113 | usr/lib/pam_rootok.so* 114 | usr/lib/pam_securetty.so* 115 | usr/lib/pam_self.so* 116 | usr/lib/pam_unix.so* 117 | usr/lib/pam_xdg.so* 118 | usr/libexec/getty 119 | usr/sbin/acpidump 120 | usr/sbin/arp 121 | usr/sbin/bsdconfig 122 | usr/sbin/bsdinstall 123 | usr/sbin/boot0cfg 124 | usr/sbin/cpucontrol 125 | usr/sbin/cron 126 | usr/sbin/daemon 127 | usr/sbin/devctl 128 | usr/sbin/devinfo 129 | usr/sbin/diskinfo 130 | usr/sbin/getextattr 131 | usr/sbin/gstat 132 | usr/sbin/jail 133 | usr/sbin/jexec 134 | usr/sbin/jls 135 | usr/sbin/lsextattr 136 | usr/sbin/mtree 137 | usr/sbin/newsyslog 138 | usr/sbin/ntpdate 139 | usr/sbin/pciconf 140 | usr/sbin/pw 141 | usr/sbin/pwd_mkdb 142 | usr/sbin/rmextattr 143 | usr/sbin/sade 144 | usr/sbin/setextattr 145 | usr/sbin/syslogd 146 | usr/sbin/tcpdump 147 | usr/sbin/traceroute 148 | usr/sbin/traceroute6 149 | usr/sbin/trim 150 | usr/sbin/tzsetup 151 | usr/sbin/usbconfig 152 | usr/sbin/usbdump 153 | usr/share/misc/iso3166 154 | usr/share/misc/termcap 155 | usr/share/misc/magic 156 | usr/share/misc/magic.mgc 157 | -------------------------------------------------------------------------------- /mini/files/instdirs: -------------------------------------------------------------------------------- 1 | etc/pam.d 2 | etc/security 3 | -------------------------------------------------------------------------------- /mini/files/instfiles: -------------------------------------------------------------------------------- 1 | etc/crontab 2 | etc/gettytab 3 | etc/group 4 | etc/hosts 5 | etc/login.conf 6 | etc/master.passwd 7 | etc/mtree/BSD.var.dist 8 | etc/newsyslog.conf 9 | etc/nsswitch.conf 10 | etc/passwd 11 | etc/pwd.db 12 | etc/services 13 | etc/spwd.db 14 | etc/syslog.conf 15 | etc/termcap.small 16 | etc/ttys 17 | -------------------------------------------------------------------------------- /mini/files/localfiles: -------------------------------------------------------------------------------- 1 | bin/cpdup 2 | bin/dbclient 3 | bin/dbscp 4 | bin/dropbearconvert 5 | bin/dropbearkey 6 | bin/ipmitool 7 | bin/rsync 8 | bin/nano 9 | bin/tmux 10 | lib/libevent-2.1.so* 11 | lib/libiconv.so.* 12 | lib/libintl.so.* 13 | lib/liblz4.so.* 14 | lib/libreadline.so.* 15 | lib/libtomcrypt.so.* 16 | lib/libtommath.so.* 17 | lib/libutf8proc.so.* 18 | lib/libxxhash.so.* 19 | lib/libzstd.so.* 20 | sbin/dropbear 21 | sbin/dmidecode 22 | sbin/smartctl 23 | -------------------------------------------------------------------------------- /mini/files/rescuelinks: -------------------------------------------------------------------------------- 1 | rescue/sh 2 | bin/ln 3 | bin/sh 4 | bin/[ 5 | bin/cat 6 | bin/chflags 7 | bin/chio 8 | bin/chmod 9 | bin/cp 10 | bin/csh 11 | bin/date 12 | bin/dd 13 | bin/df 14 | bin/echo 15 | bin/ed 16 | bin/expr 17 | bin/getfacl 18 | bin/hostname 19 | bin/kenv 20 | bin/kill 21 | bin/link 22 | bin/ls 23 | bin/mkdir 24 | bin/mv 25 | bin/pgrep 26 | bin/pkill 27 | bin/ps 28 | bin/pwd 29 | bin/rcp 30 | bin/realpath 31 | bin/red 32 | bin/rm 33 | bin/rmdir 34 | bin/setfacl 35 | bin/stty 36 | bin/sync 37 | bin/tcsh 38 | bin/test 39 | bin/unlink 40 | sbin/atmconfig 41 | sbin/badsect 42 | sbin/bsdlabel 43 | sbin/camcontrol 44 | sbin/ccdconfig 45 | sbin/clri 46 | sbin/devfs 47 | sbin/dhclient 48 | sbin/disklabel 49 | sbin/dmesg 50 | sbin/dump 51 | sbin/dumpfs 52 | sbin/dumpon 53 | sbin/fastboot 54 | sbin/fasthalt 55 | sbin/fdisk 56 | sbin/fsck 57 | sbin/fsck_4.2bsd 58 | sbin/fsck_ffs 59 | sbin/fsck_msdosfs 60 | sbin/fsck_ufs 61 | sbin/fsdb 62 | sbin/fsirand 63 | sbin/gbde 64 | sbin/geom 65 | sbin/glabel 66 | sbin/gpart 67 | sbin/halt 68 | sbin/ifconfig 69 | sbin/init 70 | sbin/ipf 71 | sbin/kldconfig 72 | sbin/kldload 73 | sbin/kldstat 74 | sbin/kldunload 75 | sbin/ldconfig 76 | sbin/md5 77 | sbin/mdconfig 78 | sbin/mdmfs 79 | sbin/mknod 80 | sbin/mount 81 | sbin/mount_cd9660 82 | sbin/mount_msdosfs 83 | sbin/mount_nfs 84 | sbin/mount_nullfs 85 | sbin/mount_udf 86 | sbin/mount_unionfs 87 | sbin/newfs 88 | sbin/newfs_msdos 89 | sbin/nextboot 90 | sbin/nos-tun 91 | sbin/ping 92 | sbin/ping6 93 | sbin/rcorder 94 | sbin/rdump 95 | sbin/reboot 96 | sbin/restore 97 | sbin/route 98 | sbin/routed 99 | sbin/rrestore 100 | sbin/rtquery 101 | sbin/rtsol 102 | sbin/savecore 103 | sbin/spppcontrol 104 | sbin/swapon 105 | sbin/sysctl 106 | sbin/tunefs 107 | sbin/umount 108 | sbin/zfs 109 | sbin/zpool 110 | usr/bin/bunzip2 111 | usr/bin/bzcat 112 | usr/bin/bzip2 113 | usr/bin/chgrp 114 | usr/bin/ex 115 | usr/bin/groups 116 | usr/bin/gunzip 117 | usr/bin/gzcat 118 | usr/bin/gzip 119 | usr/bin/head 120 | usr/bin/id 121 | usr/bin/less 122 | usr/bin/lzcat 123 | usr/bin/lzma 124 | usr/bin/more 125 | usr/bin/mt 126 | usr/bin/nc 127 | usr/bin/sed 128 | usr/bin/tail 129 | usr/bin/tar 130 | usr/bin/tee 131 | usr/bin/unlzma 132 | usr/bin/unxz 133 | usr/bin/vi 134 | usr/bin/whoami 135 | usr/bin/xz 136 | usr/bin/xzcat 137 | usr/bin/zcat 138 | usr/sbin/chown 139 | usr/sbin/chroot 140 | usr/sbin/zdb 141 | -------------------------------------------------------------------------------- /scripts/interfaces: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id$ 3 | 4 | # PROVIDE: interfaces 5 | # BEFORE: NETWORKING netif 6 | # REQUIRE: mdinit mfsbsd 7 | # KEYWORD: FreeBSD 8 | 9 | . /etc/rc.subr 10 | 11 | name="interfaces" 12 | start_cmd="interfaces_start" 13 | stop_cmd=":" 14 | 15 | interfaces_start() 16 | { 17 | if [ -z "${mac_interfaces}" ]; then 18 | exit 0 19 | fi 20 | for if in ${mac_interfaces}; do 21 | _cmac=`eval echo "\\$ifconfig_${if}_mac"` 22 | if [ -n "$_cmac" ]; then 23 | _dif=`/sbin/ifconfig -l | /usr/bin/sed -E 's/lo[0-9]+//g'` 24 | for i in $_dif; do 25 | _mac=`/sbin/ifconfig $i | /usr/bin/grep ether | /usr/bin/awk '{ print $2 }'` 26 | if [ "$_mac" = "$_cmac" ]; then 27 | _cif=`eval echo "\\$ifconfig_${if}"` 28 | if [ -n "$_cif" ]; then 29 | echo "ifconfig_$i=\"${_cif}\"" >> /etc/rc.conf.d/network 30 | fi 31 | fi 32 | done 33 | fi 34 | done 35 | } 36 | 37 | load_rc_config $name 38 | run_rc_command "$1" 39 | -------------------------------------------------------------------------------- /scripts/mdinit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id$ 3 | 4 | # PROVIDE: mdinit 5 | # BEFORE: FILESYSTEMS 6 | # REQUIRE: mountcritlocal 7 | # KEYWORD: FreeBSD 8 | 9 | . /etc/rc.subr 10 | 11 | name="mdinit" 12 | start_cmd="mdinit_start" 13 | stop_cmd=":" 14 | 15 | mdinit_start() 16 | { 17 | if [ -f /.usr.tar.xz ]; then 18 | /sbin/mount -t tmpfs tmpfs /usr 19 | /rescue/xz -d -c /.usr.tar.xz | /rescue/tar -x -C / -f - 20 | elif [ -f /.usr.tar.bz2 ]; then 21 | /sbin/mount -t tmpfs tmpfs /usr 22 | /rescue/bzip2 -d -c /.usr.tar.bz2 | /rescue/tar -x -C / -f - 23 | elif [ -f /.usr.tar.gz ]; then 24 | /sbin/mount -t tmpfs tmpfs /usr 25 | /rescue/gzip -d -c /.usr.tar.gz | /rescue/tar -x -C / -f - 26 | fi 27 | # Check if we are using roothack 28 | if ! /sbin/mount -t tmpfs | /usr/bin/grep -q " /rw "; then 29 | /sbin/mount -t tmpfs tmpfs /var/db/pkg 30 | mkdir -p /var/cache/pkg 31 | /sbin/mount -t tmpfs tmpfs /var/cache/pkg 32 | fi 33 | } 34 | 35 | load_rc_config $name 36 | run_rc_command "$1" 37 | -------------------------------------------------------------------------------- /scripts/mfsbsd: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id$ 3 | 4 | # PROVIDE: mfsbsd 5 | # BEFORE: NETWORKING netif routing hostname 6 | # REQUIRE: mountcritlocal mdinit 7 | # KEYWORD: FreeBSD 8 | 9 | . /etc/rc.subr 10 | 11 | name="mfsbsd" 12 | start_cmd="mfsbsd_start" 13 | stop_cmd=":" 14 | 15 | mfsbsd_start() 16 | { 17 | _hn=`/bin/kenv -q mfsbsd.hostname` 18 | _clif=`/bin/kenv -q mfsbsd.cloned_interfaces` 19 | _mif=`/bin/kenv -q mfsbsd.mac_interfaces` 20 | _dhcp=`/bin/kenv -q mfsbsd.autodhcp` 21 | _if=`/bin/kenv -q mfsbsd.interfaces` 22 | _dr=`/bin/kenv -q mfsbsd.defaultrouter` 23 | _sr=`/bin/kenv -q mfsbsd.static_routes` 24 | _ns=`/bin/kenv -q mfsbsd.nameservers` 25 | _rootpw=`/bin/kenv -q mfsbsd.rootpw` 26 | _rootpwhash=`/bin/kenv -q mfsbsd.rootpwhash` 27 | if [ -n "$_hn" ]; then 28 | echo "hostname=\"$_hn\"" >> /etc/rc.conf.d/hostname 29 | fi 30 | if [ -n "$_clif" ]; then 31 | echo "cloned_interfaces=\"$_clif\"" >> /etc/rc.conf.d/network 32 | fi 33 | if [ -n "$_mif" ]; then 34 | echo "mac_interfaces=\"$_mif\"" >> /etc/rc.conf.d/interfaces 35 | for i in $_mif; do 36 | _mac=`/bin/kenv mfsbsd.ifconfig_${i}_mac` 37 | if [ -n "$_mac" ]; then 38 | echo "ifconfig_${i}_mac=\"$_mac\"" >> /etc/rc.conf.d/interfaces 39 | fi 40 | _config=`/bin/kenv mfsbsd.ifconfig_$i` 41 | if [ -n "$_config" ]; then 42 | echo "ifconfig_$i=\"$_config\"" >> /etc/rc.conf.d/interfaces 43 | fi 44 | done 45 | fi 46 | if [ -n "$_dhcp" ]; then 47 | if `checkyesno _dhcp`; then 48 | _dif=`/sbin/ifconfig -l | /usr/bin/sed -E 's/lo[0-9]+//g'` 49 | for i in $_dif; do 50 | echo "ifconfig_$i=\"DHCP\"" >> /etc/rc.conf.d/network 51 | done 52 | fi 53 | fi 54 | for i in $_if $_mif $_clif; do 55 | _config=`/bin/kenv mfsbsd.ifconfig_$i` 56 | if [ -n "$_config" ]; then 57 | echo "ifconfig_$i=\"$_config\"" >> /etc/rc.conf.d/network 58 | fi 59 | done 60 | if [ -n "$_dr" ]; then 61 | echo "defaultrouter=\"$_dr\"" >> /etc/rc.conf.d/routing 62 | fi 63 | if [ -n "$_sr" ]; then 64 | echo "static_routes=\"$_sr\"" >> /etc/rc.conf.d/routing 65 | for i in $_sr; do 66 | _config=`/bin/kenv mfsbsd.route_$i` 67 | if [ -n "$_config" ]; then 68 | echo "route_$i=\"$_config\"" >> /etc/rc.conf.d/routing 69 | fi 70 | done 71 | fi 72 | if [ -n "$_rootpw" ]; then 73 | echo $_rootpw | /usr/sbin/pw usermod root -h 0 74 | /bin/kenv -u mfsbsd.rootpw 75 | elif [ -n "$_rootpwhash" ]; then 76 | echo $_rootpwhash | /usr/bin/sed -e 's,%,$,g' | /usr/sbin/pw usermod root -H 0 77 | /bin/kenv -u mfsbsd.rootpwhash 78 | fi 79 | if [ -n "$_ns" ]; then 80 | for n in $_ns; do 81 | echo "nameserver $n" >> /etc/resolv.conf 82 | done 83 | fi 84 | } 85 | 86 | load_rc_config $name 87 | run_rc_command "$1" 88 | -------------------------------------------------------------------------------- /scripts/packages: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id$ 3 | 4 | # PROVIDE: packages 5 | # BEFORE: LOGIN 6 | # REQUIRE: mdinit tmp var 7 | # KEYWORD: FreeBSD 8 | 9 | . /etc/rc.subr 10 | 11 | name="packages" 12 | start_cmd="packages_start" 13 | stop_cmd=":" 14 | 15 | packages_start() 16 | { 17 | PACKAGES=`/bin/ls -1 /packages/*.t?z 2>/dev/null` 18 | if /bin/test -n "$PACKAGES"; then 19 | MD=`/sbin/mdconfig -a -t swap -s 64m` 20 | /sbin/newfs -U /dev/$MD 21 | /sbin/mount /dev/$MD /usr/local 22 | cd /packages && /usr/sbin/pkg_add *.t?z > /dev/null 2> /dev/null 23 | fi 24 | } 25 | 26 | load_rc_config $name 27 | run_rc_command "$1" 28 | -------------------------------------------------------------------------------- /tools/destroygeom: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id$ 3 | # 4 | # mfsBSD ZFS pool and geom partition deleting 5 | # 6 | # Copyright (c) 2010-2011 Georges Discry 7 | # Copyright (c) 2018 Martin Matuska 8 | 9 | usage () { 10 | echo "Usage: $0 [-h] -d geom [-d geom ...] [-p zpool ...]" 11 | } 12 | 13 | help () { 14 | echo; echo "Destroy all partitions on geom provider(s)" 15 | echo; echo "Required flags:" 16 | echo "-d geom : geom provider(s) to clear" 17 | echo;echo "Optional flags:" 18 | echo "-p zpool : zpool(s) installed on the geom providers to clear" 19 | echo;echo "Examples:" 20 | echo "Destroy all partitions on ad4 and ad6:" 21 | echo "$0 -d ad4 -d ad6" 22 | echo "Destroy ZFS pool tank and all partitions on ada0:" 23 | echo "$0 -p tank -d ada0" 24 | } 25 | 26 | while getopts d:p:h o; do 27 | case "$o" in 28 | d) DEVS="$DEVS ${OPTARG##/dev/}" ;; 29 | p) POOLS="$POOLS ${OPTARG}" ;; 30 | h) help; exit 1;; 31 | [?]) usage; exit 1;; 32 | esac 33 | done 34 | 35 | if [ -z "$DEVS" ]; then 36 | usage 37 | exit 1 38 | fi 39 | 40 | 41 | for DEV in ${DEVS}; do 42 | if ! [ -c "/dev/${DEV}" ]; then 43 | echo "error: /dev/${DEV} is not a block device" 44 | exit 1 45 | fi 46 | done 47 | 48 | for POOL in ${POOLS}; do 49 | if ! /sbin/zpool list -H ${POOL} > /dev/null 2> /dev/null; then 50 | echo "warning: pool does not exist" 51 | continue 52 | fi 53 | 54 | echo -n "Destroying ZFS pool ${POOL} ..." 55 | if ! /sbin/zpool destroy -f ${POOL} > /dev/null 2> /dev/null; then 56 | echo " error" 57 | exit 1 58 | fi 59 | echo " done" 60 | done 61 | 62 | 63 | for DEV in ${DEVS}; do 64 | GEOMS=`/sbin/gpart show | /usr/bin/tail -r | /usr/bin/grep '=>' | /usr/bin/awk '{print $4}' | /usr/bin/grep "^${DEV}" | /usr/bin/uniq` 65 | for GEOM in ${GEOMS}; do 66 | echo "Destroying geom ${GEOM}:" 67 | PARTS=`/sbin/gpart show ${GEOM} | /usr/bin/grep -v '=>\|- free -' | /usr/bin/awk '{if ($3 ~ /[0-9]+/) print $3}' | /usr/bin/sort -n | /usr/bin/uniq` 68 | for PART in ${PARTS}; do 69 | echo -n " Deleting partition ${PART} ..." 70 | if ! /sbin/gpart delete -i${PART} ${GEOM} > /dev/null 2> /dev/null; then 71 | echo " error" 72 | exit 1 73 | fi 74 | echo " done" 75 | done 76 | if ! /sbin/gpart destroy ${GEOM} > /dev/null 2> /dev/null; then 77 | echo "error: could not destroy geom ${GEOM}" 78 | exit 1 79 | fi 80 | done 81 | done 82 | -------------------------------------------------------------------------------- /tools/doFS.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # $FreeBSD: src/release/scripts/doFS.sh,v 1.60 2004/08/25 01:39:52 kensmith Exp $ 4 | # 5 | 6 | set -ex 7 | 8 | export BLOCKSIZE=512 9 | 10 | DISKLABEL=$1; shift 11 | MACHINE=${1:+"-m $1"}; shift 12 | FSIMG=$1; shift 13 | RD=$1 ; shift 14 | MNT=$1 ; shift 15 | FSSIZE=$1 ; shift 16 | FSPROTO=$1 ; shift 17 | FSINODE=$1 ; shift 18 | FSLABEL=$1 ; shift 19 | 20 | # 21 | # If we've been told to, compute the required file system size 22 | # and average inode size automatically. 23 | # 24 | if [ ${FSSIZE} -eq 0 -a ${FSLABEL} = "auto" ]; then 25 | roundup() echo $((($1+$2-1)-($1+$2-1)%$2)) 26 | nf=$(find ${FSPROTO} |wc -l) 27 | sk=$(du -skA ${FSPROTO} |cut -f1) 28 | FSINODE=$(roundup $(($sk*1024/$nf)) ${FSINODE}) 29 | FSSIZE=$(roundup $(($sk*12/10)) 1024) 30 | fi 31 | 32 | dofs_vn () { 33 | if [ "x$VNDEVICE" = "x" ] ; then 34 | VNDEVICE=vn0 35 | fi 36 | u=`expr $VNDEVICE : 'vn\([0-9]*\)' || true` 37 | VNDEVICE=vnn$u 38 | 39 | rm -f /dev/*vnn* 40 | mknod /dev/rvnn${u} c 43 `expr 65538 + $u '*' 8` 41 | mknod /dev/rvnn${u}a c 43 `expr 2 + $u '*' 8` 42 | mknod /dev/vnn${u} b 15 `expr 65538 + $u '*' 8` 43 | mknod /dev/vnn${u}a b 15 `expr 2 + $u '*' 8` 44 | 45 | umount /dev/${VNDEVICE} 2>/dev/null || true 46 | umount ${MNT} 2>/dev/null || true 47 | vnconfig -u /dev/r${VNDEVICE} 2>/dev/null || true 48 | 49 | vnconfig -s labels -c /dev/r${VNDEVICE} ${FSIMG} 50 | 51 | trap "umount ${MNT}; vnconfig -u /dev/r${VNDEVICE}; rm -f /dev/*vnn*" EXIT 52 | 53 | disklabel -w ${BOOT} ${VNDEVICE} ${FSLABEL} 54 | newfs -i ${FSINODE} -o space -m 0 /dev/r${VNDEVICE}a 55 | 56 | mount -o async /dev/${VNDEVICE}a ${MNT} 57 | } 58 | 59 | dofs_md () { 60 | if [ "x${MDDEVICE}" != "x" ] ; then 61 | umount /dev/${MDDEVICE} 2>/dev/null || true 62 | umount ${MNT} 2>/dev/null || true 63 | mdconfig -d -u ${MDDEVICE} 2>/dev/null || true 64 | fi 65 | 66 | MDDEVICE=`mdconfig -a -t vnode -f ${FSIMG}` 67 | if [ ! -c /dev/${MDDEVICE} ] ; then 68 | echo "No /dev/$MDDEVICE" 1>&2 69 | exit 1 70 | fi 71 | 72 | trap "umount ${MNT}; mdconfig -d -u ${MDDEVICE}" EXIT 73 | 74 | if [ "x${DISKLABEL}" != "x" ] ; then 75 | ${DISKLABEL} ${MACHINE} -w ${BOOT} ${MDDEVICE} ${FSLABEL} 76 | newfs -O2 -i ${FSINODE} -o space -m 0 /dev/${MDDEVICE}a 77 | mount -o async /dev/${MDDEVICE}a ${MNT} 78 | else 79 | newfs -O2 -i ${FSINODE} -o space -m 0 /dev/${MDDEVICE} 80 | mount -o async /dev/${MDDEVICE} ${MNT} 81 | fi 82 | } 83 | 84 | rm -f ${FSIMG} 85 | dd of=${FSIMG} if=/dev/zero count=${FSSIZE} bs=1k 2>/dev/null 86 | 87 | # 88 | # We don't have any bootblocks on ia64. Note that -B implies -r, 89 | # so we have to specifically specify -r when we don't have -B. 90 | # bsdlabel fails otherwise. 91 | # 92 | case `uname -r` in 93 | 4.*) 94 | if [ -f "${RD}/trees/base/boot/boot1" ]; then 95 | BOOT="-B -b ${RD}/trees/base/boot/boot1" 96 | if [ -f "${RD}/trees/base/boot/boot2" ]; then 97 | BOOT="${BOOT} -s ${RD}/trees/base/boot/boot2" 98 | fi 99 | else 100 | BOOT="-r" 101 | fi 102 | dofs_vn 103 | ;; 104 | *) 105 | if [ -f "${RD}/trees/base/boot/boot" ]; then 106 | BOOT="-B -b ${RD}/trees/base/boot/boot" 107 | else 108 | BOOT="-r" 109 | fi 110 | dofs_md 111 | ;; 112 | esac 113 | 114 | if [ -d ${FSPROTO} ]; then 115 | ABS=`cd ${MNT} && pwd` 116 | (set -e && cd ${FSPROTO} && find . -print | cpio -dump ${ABS}) 117 | else 118 | cp -p ${FSPROTO} ${MNT} 119 | fi 120 | 121 | df -ki ${MNT} 122 | 123 | set `df -ki ${MNT} | tail -1` 124 | 125 | echo "*** File system is ${FSSIZE} K, $4 left" 126 | echo "*** ${FSINODE} bytes/inode, $7 left" 127 | -------------------------------------------------------------------------------- /tools/do_gpt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | set -e 4 | 5 | FSIMG=$1 6 | FSPROTO=$2 7 | FSSIZE=$3 8 | BOOTDIR=$4 9 | EFIIMG=$5 10 | VERBOSE=$6 11 | 12 | FSLABEL="auto" 13 | 14 | 15 | exit_with() { 16 | local status="$1" 17 | shift 18 | 19 | if [ -n "$@" ]; then 20 | echo 21 | echo "$@" 22 | fi 23 | 24 | mdconfig -d -u ${unit} 25 | rm -f ${TMPIMG} 26 | 27 | exit ${status} 28 | } 29 | 30 | #Trap the killer signals so that we can exit with a good message. 31 | trap "exit_with 1 'Received signal SIGHUP'" SIGHUP 32 | trap "exit_with 1 'Received signal SIGINT'" SIGINT 33 | trap "exit_with 1 'Received signal SIGTERM'" SIGTERM 34 | 35 | if [ ${FSSIZE} -eq 0 -a ${FSLABEL} = "auto" ]; then 36 | roundup() echo $((($1+$2-1)-($1+$2-1)%$2)) 37 | nf=$(find ${FSPROTO} |wc -l) 38 | sk=$(du -skA ${FSPROTO} |cut -f1) 39 | FSSIZE=$(roundup $(($sk*12/10)) 1024) 40 | IMG_SIZE=$((${FSSIZE}+128)) 41 | fi 42 | 43 | if [ -n "$VERBOSE" ]; then 44 | echo "FSIMG ${FSIMG} FSPROTO ${FSPROTO} FSSIZE ${FSSIZE}" 45 | fi 46 | 47 | TMPIMG=`env TMPDIR=. mktemp -t ${FSIMG}` 48 | 49 | dd of=${FSIMG} if=/dev/zero count=${IMG_SIZE} bs=1k 50 | dd of=${TMPIMG} if=/dev/zero count=${FSSIZE} bs=1k 51 | 52 | export unit=`mdconfig -a -t vnode -f ${FSIMG}` 53 | if [ $? -ne 0 ]; then 54 | echo "mdconfig failed" 55 | exit 1 56 | fi 57 | 58 | if [ -n "$VERBOSE" ]; then 59 | TIME=time 60 | set -x 61 | else 62 | TIME= 63 | fi 64 | 65 | gpart create -s gpt ${unit} 66 | gpart add -t freebsd-boot -b 40 -l boot -s 472 ${unit} 67 | gpart bootcode -b ${BOOTDIR}/pmbr -p ${BOOTDIR}/gptboot -i 1 ${unit} 68 | if [ -n "${EFIIMG}" -a -f "${EFIIMG}" ]; then 69 | gpart add -t efi -s 2m ${unit} 70 | ${TIME} dd if=${EFIIMG} of=/dev/${unit}p2 bs=128k 71 | fi 72 | gpart add -t freebsd-ufs -l rootfs ${unit} 73 | ${TIME} makefs -B little ${TMPIMG} ${FSPROTO} 74 | if [ -f ${EFIIMG} ]; then 75 | ${TIME} dd if=${TMPIMG} of=/dev/${unit}p3 bs=128k 76 | else 77 | ${TIME} dd if=${TMPIMG} of=/dev/${unit}p2 bs=128k 78 | fi 79 | 80 | if [ -n "$VERBOSE" ]; then 81 | set +x 82 | fi 83 | if [ $? -ne 0 ]; then 84 | echo "makefs failed" 85 | exit_with 1 86 | fi 87 | 88 | exit_with 0 89 | 90 | -------------------------------------------------------------------------------- /tools/kern_exclude: -------------------------------------------------------------------------------- 1 | kernel.debug 2 | *.symbols 3 | *.ko 4 | -------------------------------------------------------------------------------- /tools/motd: -------------------------------------------------------------------------------- 1 | Welcome to mfsBSD, the memory based FreeBSD distribution. 2 | 3 | This is a stripped-down version of FreeBSD without: 4 | - manual pages, info pages, examples 5 | - include files, static library files, development tools 6 | - bind binaries (host, dig, named, etc.) 7 | 8 | Feel free to email me with any bug reports or feature suggestions. 9 | Martin Matuska 10 | http://mfsbsd.vx.sk/ 11 | -------------------------------------------------------------------------------- /tools/motd.se: -------------------------------------------------------------------------------- 1 | Welcome to mfsBSD SE, the memory based FreeBSD distribution. 2 | This is a special version intended for full-ZFS install of FreeBSD 3 | 4 | To make a full-ZFS FreeBSD install from this ISO: 5 | 6 | 1. Mount the CD device 7 | ( e.g. mount_cd9660 /dev/cd0 /cdrom ) 8 | 2. Run "zfsinstall" with path to release directory and your drive 9 | ( e.g. zfsinstall -d ada0 -u /cdrom/9.2-RELEASE-amd64 ) 10 | 11 | Run zfsinstall with the -h flag for help or without flags for options. 12 | I recommend creating a GPT swap partition (e.g. -s 2G for a 2GB swap). 13 | 14 | Feel free to email me with any bug reports or feature suggestions. 15 | Martin Matuska 16 | http://mfsbsd.vx.sk/ 17 | -------------------------------------------------------------------------------- /tools/packages-mini.sample: -------------------------------------------------------------------------------- 1 | dropbear 2 | -------------------------------------------------------------------------------- /tools/packages.sample: -------------------------------------------------------------------------------- 1 | cpdup-freebsd 2 | dmidecode 3 | indexinfo 4 | ipmitool 5 | libevent 6 | libiconv 7 | nano 8 | readline 9 | rsync 10 | smartmontools 11 | tmux 12 | utf8proc 13 | -------------------------------------------------------------------------------- /tools/prunelist: -------------------------------------------------------------------------------- 1 | usr/bin/c++ 2 | usr/bin/c++filt 3 | usr/bin/g++ 4 | usr/bin/c89 5 | usr/bin/c99 6 | usr/bin/CC 7 | usr/bin/cc 8 | usr/bin/clang 9 | usr/bin/clang++ 10 | usr/bin/clang-cpp 11 | usr/bin/clang-tblgen 12 | usr/bin/cpp 13 | usr/bin/gcc 14 | usr/bin/yacc 15 | usr/bin/f77 16 | usr/bin/byacc 17 | usr/bin/addr2line 18 | usr/bin/ar 19 | usr/bin/gnu-ar 20 | usr/bin/gnu-ranlib 21 | usr/bin/as 22 | usr/bin/gasp 23 | usr/bin/gcov 24 | usr/bin/gdb 25 | usr/bin/gdbreplay 26 | usr/bin/kyua 27 | usr/bin/ld 28 | usr/bin/ld.bfd 29 | usr/bin/ld.lld 30 | usr/bin/lldb 31 | usr/bin/lldb-tblgen 32 | usr/bin/llvm-addr2line 33 | usr/bin/llvm-ar 34 | usr/bin/llvm-cov 35 | usr/bin/llvm-cxxfilt 36 | usr/bin/llvm-nm 37 | usr/bin/llvm-objdump 38 | usr/bin/llvm-profdata 39 | usr/bin/llvm-ranlib 40 | usr/bin/llvm-symbolizer 41 | usr/bin/llvm-tblgen 42 | usr/bin/nm 43 | usr/bin/objcopy 44 | usr/bin/objdump 45 | usr/bin/ranlib 46 | usr/bin/readelf 47 | usr/bin/size 48 | usr/bin/strip 49 | usr/bin/svnlite 50 | usr/bin/svnliteadmin 51 | usr/bin/svnlitebench 52 | usr/bin/svnlitedumpfilter 53 | usr/bin/svnlitefsfs 54 | usr/bin/svnlitelook 55 | usr/bin/svnlitemucc 56 | usr/bin/svnliterdump 57 | usr/bin/svnliteserve 58 | usr/bin/svnlitesync 59 | usr/bin/svnliteversion 60 | usr/bin/gdbtui 61 | usr/bin/kgdb 62 | usr/games 63 | usr/include 64 | usr/lib32 65 | usr/lib/*.a 66 | usr/lib/clang 67 | usr/lib/private/*.a 68 | usr/lib/private/libunbound* 69 | usr/libexec/cc1 70 | usr/libexec/cc1obj 71 | usr/libexec/cc1plus 72 | usr/libexec/f771 73 | usr/sbin/unbound* 74 | usr/share/dict 75 | usr/share/doc 76 | usr/share/examples 77 | usr/share/info 78 | usr/share/games 79 | usr/share/man 80 | usr/share/openssl 81 | usr/share/nls 82 | -------------------------------------------------------------------------------- /tools/prunelist.9: -------------------------------------------------------------------------------- 1 | usr/bin/c++ 2 | usr/bin/c++filt 3 | usr/bin/g++ 4 | usr/bin/c89 5 | usr/bin/c99 6 | usr/bin/CC 7 | usr/bin/cc 8 | usr/bin/clang 9 | usr/bin/clang++ 10 | usr/bin/clang-cpp 11 | usr/bin/clang-tblgen 12 | usr/bin/cpp 13 | usr/bin/gcc 14 | usr/bin/yacc 15 | usr/bin/f77 16 | usr/bin/byacc 17 | usr/bin/addr2line 18 | usr/bin/ar 19 | usr/bin/gnu-ar 20 | usr/bin/gnu-ranlib 21 | usr/bin/as 22 | usr/bin/gasp 23 | usr/bin/gdb 24 | usr/bin/gdbreplay 25 | usr/bin/ld 26 | usr/bin/nm 27 | usr/bin/objcopy 28 | usr/bin/objdump 29 | usr/bin/ranlib 30 | usr/bin/readelf 31 | usr/bin/size 32 | usr/bin/strip 33 | usr/bin/gdbtui 34 | usr/bin/kgdb 35 | usr/include 36 | usr/games 37 | usr/lib32 38 | usr/lib/*.a 39 | usr/lib/private/*.a 40 | usr/libexec/cc1 41 | usr/libexec/cc1obj 42 | usr/libexec/cc1plus 43 | usr/libexec/f771 44 | usr/share/dict 45 | usr/share/doc 46 | usr/share/examples 47 | usr/share/info 48 | usr/share/games 49 | usr/share/man 50 | usr/share/openssl 51 | usr/share/nls 52 | usr/bin/dig 53 | usr/bin/host 54 | usr/bin/nslookup 55 | usr/bin/nsupdate 56 | usr/sbin/dnssec-dsfromkey 57 | usr/sbin/dnssec-signzone 58 | usr/sbin/lwresd 59 | usr/sbin/named 60 | usr/sbin/named-checkconf 61 | usr/sbin/named-checkzone 62 | usr/sbin/named-compilezone 63 | usr/sbin/dnssec-keygen 64 | usr/sbin/dnssec-keyfromlabel 65 | usr/sbin/rndc-confgen 66 | usr/sbin/named-reconfig 67 | usr/sbin/named-reload 68 | -------------------------------------------------------------------------------- /tools/roothack/Makefile: -------------------------------------------------------------------------------- 1 | PROG= roothack 2 | MAN= 3 | 4 | LDADD= -larchive -lbz2 -lz -llzma -lcrypto -lbsdxml -lmd -lprivatezstd 5 | 6 | NO_SHARED= 7 | 8 | WARNS= 6 9 | 10 | .include 11 | -------------------------------------------------------------------------------- /tools/roothack/roothack.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2010-2012 Ed Schouten 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | */ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | static void 43 | die(const char *msg) 44 | { 45 | int fd, serrno; 46 | 47 | serrno = errno; 48 | fd = open("/dev/console", O_RDWR); 49 | if (fd != -1 && fd != STDERR_FILENO) 50 | dup2(fd, STDERR_FILENO); 51 | errno = serrno; 52 | perror(msg); 53 | sleep(10); 54 | exit(1); 55 | } 56 | 57 | static void 58 | domount(const char * const list[], unsigned int elems) 59 | { 60 | struct iovec iov[elems]; 61 | unsigned int i; 62 | 63 | for (i = 0; i < elems; i++) { 64 | iov[i].iov_base = __DECONST(char *, list[i]); 65 | iov[i].iov_len = strlen(list[i]) + 1; 66 | } 67 | 68 | if (nmount(iov, elems, 0) != 0) 69 | die(list[1]); 70 | } 71 | 72 | static int 73 | copy_data(struct archive *ar, struct archive *aw) 74 | { 75 | int r; 76 | const void *buff; 77 | size_t size; 78 | off_t offset; 79 | 80 | for (;;) { 81 | r = archive_read_data_block(ar, &buff, &size, &offset); 82 | if (r == ARCHIVE_EOF) 83 | return (ARCHIVE_OK); 84 | if (r != ARCHIVE_OK) 85 | return (r); 86 | r = archive_write_data_block(aw, buff, size, offset); 87 | if (r != ARCHIVE_OK) { 88 | die(archive_error_string(aw)); 89 | return (r); 90 | } 91 | } 92 | } 93 | 94 | static void 95 | extract(const char *filename) 96 | { 97 | struct archive *a; 98 | struct archive *ext; 99 | struct archive_entry *entry; 100 | int flags; 101 | int r; 102 | 103 | flags = ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM; 104 | 105 | a = archive_read_new(); 106 | archive_read_support_format_all(a); 107 | #if ARCHIVE_VERSION_NUMBER < 3000000 108 | archive_read_support_compression_all(a); 109 | #else 110 | archive_read_support_filter_all(a); 111 | #endif 112 | ext = archive_write_disk_new(); 113 | archive_write_disk_set_options(ext, flags); 114 | archive_write_disk_set_standard_lookup(ext); 115 | #if ARCHIVE_VERSION_NUMBER < 3000000 116 | if ((r = archive_read_open_file(a, filename, 10240))) 117 | die("archive_read_open_file"); 118 | #else 119 | if ((r = archive_read_open_filename(a, filename, 10240))) 120 | die("archive_read_open_filename"); 121 | #endif 122 | for (;;) { 123 | r = archive_read_next_header(a, &entry); 124 | if (r == ARCHIVE_EOF) 125 | break; 126 | if (r < ARCHIVE_WARN) 127 | die(archive_error_string(a)); 128 | r = archive_write_header(ext, entry); 129 | if (r == ARCHIVE_OK && archive_entry_size(entry) > 0) { 130 | r = copy_data(a, ext); 131 | if (r < ARCHIVE_WARN) 132 | die(archive_error_string(a)); 133 | } 134 | r = archive_write_finish_entry(ext); 135 | if (r < ARCHIVE_WARN) 136 | die(archive_error_string(ext)); 137 | } 138 | archive_read_close(a); 139 | archive_read_free(a); 140 | archive_write_close(ext); 141 | archive_write_free(ext); 142 | } 143 | 144 | static char const * const tmpfs[] = { 145 | "fstype", "tmpfs", "fspath", "/rw" 146 | }; 147 | static char const * const devfs[] = { 148 | "fstype", "devfs", "fspath", "/rw/dev" 149 | }; 150 | 151 | int 152 | main(int argc __unused, char *argv[]) 153 | { 154 | 155 | /* Prevent foot shooting. */ 156 | if (getpid() != 1) 157 | return (1); 158 | 159 | if (modfind("tmpfs") == -1 && kldload("tmpfs") == -1) 160 | die("error loading tmpfs"); 161 | 162 | /* Extract FreeBSD installation in a tmpfs. */ 163 | domount(tmpfs, sizeof(tmpfs) / sizeof(char *)); 164 | extract("/root.txz"); 165 | domount(devfs, sizeof(devfs) / sizeof(char *)); 166 | 167 | /* chroot() into system and continue boot process. */ 168 | if (chroot("/rw") != 0) 169 | die("chroot"); 170 | chdir("/"); 171 | 172 | /* Execute the real /sbin/init. */ 173 | execv(argv[0], argv); 174 | die("execv"); 175 | return (1); 176 | } 177 | -------------------------------------------------------------------------------- /tools/zfsinstall: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # $Id$ 3 | # 4 | # mfsBSD ZFS install script 5 | # Copyright (c) 2018 Martin Matuska 6 | # 7 | FREEBSD_MIRROR="${FREEBSD_MIRROR:-ftp://ftp.freebsd.org/pub/FreeBSD}" 8 | FS_LIST="var tmp" 9 | RAID_TYPES="mirror raidz raidz1 raidz2 raidz3" 10 | 11 | usage() { 12 | echo "Usage: $0 [-h] -d geom_provider [-d geom_provider ...] [ -u dist_url ] [-r mirror|raidz[1|2|3]] [-m mount_point] [-p zfs_pool_name] [-s swap_partition_size] [-z zfs_partition_size] [-c] [-C] [-l] [-4] [-A]" 13 | } 14 | 15 | osarch() { 16 | /sbin/sysctl -n hw.machine_arch 17 | } 18 | 19 | osrelease() { 20 | /sbin/sysctl -n kern.osrelease | /usr/bin/sed -E -e 's,-p[0-9]+$,,g' 21 | } 22 | 23 | check_raid() { 24 | RAID_TYPE="$1" 25 | test -n "$RAID_TYPE" || return 1 26 | 27 | for raid_type in $RAID_TYPES; do 28 | if [ "$raid_type" = $RAID_TYPE ]; then 29 | return 0 30 | fi 31 | done 32 | 33 | return 1 34 | } 35 | 36 | help() { 37 | echo; echo "Install FreeBSD using ZFS from a compressed archive" 38 | echo; echo "Required flags:" 39 | echo "-d geom_provider : geom provider(s) to install to (e.g. da0)" 40 | echo; echo "Optional flags:" 41 | echo "-r raidz[1|2|3]|mirror : select raid mode if more than one -d provider given" 42 | echo " (must begin after -d)" 43 | echo "-u dist_url : URL or directory with base.txz and kernel.txz" 44 | echo " (defaults to FreeBSD FTP mirror)" 45 | echo "-s swap_part_size : create a swap partition with given size (default: no swap)" 46 | echo "-z zfs_part_size : create zfs parition of this size (default: all space left)" 47 | echo "-p pool_name : specify a name for the ZFS pool (default: tank)" 48 | echo "-C : compatibility mode with limited feature flags" 49 | echo " (enable only async_destroy, empty_bpobj and lz4_compress)" 50 | echo "-m mount_point : use this mount point for operations (default: /mnt)" 51 | echo "-c : enable compression for all datasets" 52 | echo "-l : use legacy mounts (via fstab) instead of ZFS mounts" 53 | echo "-4 : use fletcher4 as default checksum algorithm" 54 | echo "-A : align partitions to 4K blocks" 55 | echo; echo "Examples:" 56 | echo "Install on a single drive with 2GB swap:" 57 | echo "$0 -u /path/to/release -d da0 -s 2G" 58 | echo "Install on four-disk stripe:" 59 | echo "$0 -u /path/to/release -d da0 -d da1 -d da2 -d da3" 60 | echo "Install on an stripped mirror:" 61 | echo "$0 -u /path/to/release -d da0 -d da1 -r mirror -d da2 -d da3 -r mirror" 62 | echo "Install on a raidz2:" 63 | echo "$0 -u /path/to/release -d da0 -d da1 -d da2 -d da3 -r raidz2" 64 | echo "Install on a mirror without swap, pool name rpool:" 65 | echo "$0 -u /path/to/release -d da0 -d da1 -r mirror -p rpool" 66 | echo; echo "Notes:" 67 | echo "When using swap and raidz/mirror, the swap partition is created on all drives." 68 | echo "The /etc/fstab entry will contatin only the first drive's swap partition." 69 | echo "You can enable all swap partitions and/or make a gmirror-ed swap later." 70 | } 71 | 72 | while getopts d:u:t:r:p:s:z:m:V:Chcl4A o; do 73 | case "$o" in 74 | d) DEVS="$DEVS ${OPTARG##/dev/}"; ZDEVS="$ZDEVS ${OPTARG##/dev/}" ;; 75 | u) URL="${OPTARG}" ;; 76 | t) ARCHIVE="${OPTARG}" ;; 77 | p) POOL="${OPTARG}" ;; 78 | s) SWAP="${OPTARG}" ;; 79 | m) MNT="${OPTARG}" ;; 80 | r) 81 | if [ -z "${ZDEVS}" ]; then 82 | echo "Error: geom providers must be defined before using \ 83 | this option" 84 | usage 85 | exit 1 86 | fi 87 | 88 | if [ -n "${RAID}" -a "${RAID}" != "${OPTARG}" ]; then 89 | echo "Error: array types do not match" 90 | exit 1 91 | else 92 | RAID="${OPTARG}" 93 | fi 94 | 95 | if ! check_raid "$RAID"; then 96 | echo "Error: please choose raid mode with the -r switch (mirror or raidz[1|2|3])" 97 | exit 1 98 | fi 99 | 100 | COUNT=`echo ${ZDEVS} | /usr/bin/wc -w | /usr/bin/awk '{ print $1 }'` 101 | if [ "$COUNT" -lt "3" ] && [ "$RAID" = "raidz" -o "$RAID" = "raidz1" ]; then 102 | echo "Error: raidz needs at least three devices (-d switch)" 103 | exit 1 104 | elif [ "$COUNT" -lt "4" -a "$RAID" = "raidz2" ]; then 105 | echo "Error: raidz2 needs at least four devices (-d switch)" 106 | exit 1 107 | elif [ "$COUNT" -lt "5" -a "$RAID" = "raidz3" ]; then 108 | echo "Error: raidz3 needs at least five devices (-d switch)" 109 | exit 1 110 | elif [ "$COUNT" = "1" -a "$RAID" = "mirror" ]; then 111 | echo "Error: mirror needs at least two devices (-d switch)" 112 | exit 1 113 | fi 114 | 115 | ZARRAY="${ZARRAY} ${RAID} ${ZDEVS}" 116 | 117 | unset ZDEVS 118 | ;; 119 | z) ZPART="${OPTARG}" ;; 120 | V) VERSION="${OPTARG}" ;; 121 | C) COMPAT=1 ;; 122 | c) COMPRESS=1 ;; 123 | l) LEGACY=1 ;; 124 | 4) FLETCHER=1 ;; 125 | A) ALIGN=1 ;; 126 | h) help; exit 1;; 127 | [?]) usage; exit 1;; 128 | esac 129 | done 130 | 131 | if ! `/sbin/kldstat -m zfs >/dev/null 2>/dev/null`; then 132 | /sbin/kldload zfs >/dev/null 2>/dev/null 133 | fi 134 | 135 | ZFS_VERSION=`/sbin/sysctl -n vfs.zfs.version.spa 2>/dev/null` 136 | 137 | if [ -z "$ZFS_VERSION" ]; then 138 | echo "Error: failed to load ZFS module" 139 | exit 1 140 | elif [ "$ZFS_VERSION" -lt "13" ]; then 141 | echo "Error: ZFS module too old, version 13 or higher required" 142 | exit 1 143 | fi 144 | 145 | if [ -z "$DEVS" ]; then 146 | usage 147 | exit 1 148 | fi 149 | 150 | if [ -z "$POOL" ]; then 151 | POOL=tank 152 | fi 153 | 154 | if [ -z "$VERSION" ]; then 155 | VERSION=${ZFS_VERSION} 156 | elif [ "$VERSION" -gt "$ZFS_VERSION" ]; then 157 | echo "Error: invalid ZFS pool version (maximum: $ZFS_VERSION)" 158 | exit 1 159 | fi 160 | 161 | if [ "$VERSION" = "5000" ]; then 162 | VERSION= 163 | else 164 | VERSION="-o version=${VERSION}" 165 | fi 166 | 167 | if [ "$COMPAT" = "1" ]; then 168 | if [ "$ZFS_VERSION" != 5000 ]; then 169 | echo "Error: compatibility mode requires ZFS version 5000" 170 | exit 1 171 | fi 172 | COMPATFLAGS="-d -o feature@async_destroy=enabled -o feature@empty_bpobj=enabled -o feature@lz4_compress=enabled" 173 | fi 174 | 175 | if [ "$ALIGN" = "1" ]; then 176 | ALIGNMENT="-a 4096" 177 | fi 178 | 179 | if /sbin/zpool list $POOL > /dev/null 2> /dev/null; then 180 | echo Error: ZFS pool \"$POOL\" already exists 181 | echo Please choose another pool name or rename/destroy the existing pool. 182 | exit 1 183 | fi 184 | 185 | EXPOOLS=`/sbin/zpool import 2> /dev/null | /usr/bin/grep pool: | /usr/bin/awk '{ print $2 }'` 186 | 187 | if [ -n "${EXPOOLS}" ]; then 188 | for P in ${EXPOOLS}; do 189 | if [ "$P" = "$POOL" ]; then 190 | echo Error: An exported ZFS pool \"$POOL\" already exists 191 | echo Please choose another pool name or rename/destroy the exported pool. 192 | exit 1 193 | fi 194 | done 195 | fi 196 | 197 | if [ -z "${ZARRAY}" ]; then 198 | echo Notice: no raid type has been chosen, it will be \`stripe\` 199 | ZARRAY="${DEVS}" 200 | fi 201 | 202 | for DEV in ${DEVS}; do 203 | if ! [ -c "/dev/${DEV}" ]; then 204 | echo "Error: /dev/${DEV} is not a block device" 205 | exit 1 206 | fi 207 | if /sbin/gpart show $DEV > /dev/null 2> /dev/null; then 208 | echo "Error: /dev/${DEV} already contains a partition table." 209 | echo "" 210 | /sbin/gpart show $DEV 211 | echo "You may erase the partition table manually with the destroygeom command" 212 | exit 1 213 | fi 214 | done 215 | 216 | EXTRACT_FILES="/tmp/base.txz /tmp/kernel.txz" 217 | 218 | if [ -z "${URL}" ]; then 219 | if [ -z "${ARCHIVE}" ]; then 220 | URL="${FREEBSD_MIRROR}/releases/$(osarch)/$(osrelease)" 221 | elif ! [ -f "${ARCHIVE}" ]; then 222 | echo "Error: file $ARCHIVE does not exist" 223 | exit 1 224 | else 225 | EXTRACT_FILES=${ARCHIVE} 226 | fi 227 | else 228 | if [ -d "${URL}" ]; then 229 | for file in base.txz kernel.txz; do 230 | if ! [ -f "${URL}/${file}" ]; then 231 | echo "File not found: ${URL}/${file}" 232 | exit 1 233 | fi 234 | done 235 | EXTRACT_FILES="${URL}/base.txz ${URL}/kernel.txz" 236 | fi 237 | fi 238 | 239 | if [ -z "$MNT" ]; then 240 | MNT=/mnt 241 | fi 242 | 243 | if ! [ -d "${MNT}" ]; then 244 | echo "Error: $MNT is not a directory" 245 | exit 1 246 | fi 247 | 248 | if [ -n "${ZPART}" ]; then 249 | SZPART="-s ${ZPART}" 250 | fi 251 | 252 | if [ "${LEGACY}" = "1" ]; then 253 | ALTROOT= 254 | ROOTMNT=legacy 255 | else 256 | ALTROOT="-o altroot=${MNT} -o cachefile=/boot/zfs/zpool.cache" 257 | ROOTMNT=/ 258 | fi 259 | 260 | # Fetch base.txz and kernel.txz 261 | 262 | if [ -n "${URL}" -a ! -d "${URL}" ]; then 263 | echo "Fetching base files from: $URL" 264 | if ! /usr/bin/fetch -o /tmp/base.txz "${URL}/base.txz"; then 265 | echo "Error fetching ${URL}/base.txz" 266 | exit 1 267 | elif ! /usr/bin/fetch -o /tmp/kernel.txz "${URL}/kernel.txz"; then 268 | echo "Error fetching ${URL}/kernel.txz" 269 | exit 1 270 | fi 271 | fi 272 | 273 | # Create GPT 274 | 275 | for DEV in ${DEVS}; do 276 | echo -n "Creating GUID partitions on ${DEV} ..." 277 | if ! /sbin/gpart create -s GPT /dev/${DEV} > /dev/null; then 278 | echo " error" 279 | exit 1 280 | fi 281 | /bin/sleep 1 282 | if ! echo "a 1" | /sbin/fdisk -f - ${DEV} > /dev/null 2> /dev/null; then 283 | echo " error" 284 | exit 1 285 | fi 286 | if ! /sbin/gpart add -t freebsd-boot -b 40 -s 472 ${DEV} > /dev/null; then 287 | echo " error" 288 | exit 1 289 | fi 290 | if [ -n "${SWAP}" ]; then 291 | if ! /sbin/gpart add -t freebsd-swap ${ALIGNMENT} -s "${SWAP}" ${DEV} > /dev/null; then 292 | echo " error" 293 | exit 1 294 | fi 295 | SWAPPART=`/sbin/glabel status ${DEV}p2 | /usr/bin/grep gptid | /usr/bin/awk '{ print $1 }'` 296 | if [ -z "$SWAPPART" ]; then 297 | echo " error determining swap partition" 298 | fi 299 | if [ -z "$FSWAP" ]; then 300 | FSWAP=${SWAPPART} 301 | fi 302 | fi 303 | if ! /sbin/gpart add -t freebsd-zfs ${ALIGNMENT} ${SZPART} ${DEV} > /dev/null; then 304 | echo " error" 305 | exit 1 306 | fi 307 | /bin/dd if=/dev/zero of=/dev/${DEV}p2 bs=512 count=560 > /dev/null 2> /dev/null 308 | if [ -n "${SWAP}" ]; then 309 | /bin/dd if=/dev/zero of=/dev/${DEV}p3 bs=512 count=560 > /dev/null 2> /dev/null 310 | fi 311 | echo " done" 312 | 313 | echo -n "Configuring ZFS bootcode on ${DEV} ..." 314 | if ! /sbin/gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ${DEV} > /dev/null; then 315 | echo " error" 316 | exit 1 317 | fi 318 | echo " done" 319 | /sbin/gpart show ${DEV} 320 | done 321 | 322 | # Create zpool and zfs 323 | 324 | for DEV in ${ZARRAY}; do 325 | if check_raid "${DEV}"; then 326 | if [ -n "${_PARTS}" ]; then 327 | ZPARTS="${ZPARTS} ${RAID} ${_PARTS}" 328 | 329 | unset _PARTS 330 | fi 331 | continue 332 | fi 333 | 334 | PART=`/sbin/gpart show ${DEV} | /usr/bin/grep freebsd-zfs | /usr/bin/awk '{ print $3 }'` 335 | 336 | if [ -z "${PART}" ]; then 337 | echo Error: freebsd-zfs partition not found on /dev/$DEV 338 | exit 1 339 | fi 340 | 341 | GPART=`/sbin/glabel list ${DEV}p${PART} | /usr/bin/grep gptid | /usr/bin/awk -F"gptid/" '{ print "gptid/" $2 }'` 342 | 343 | GPARTS="${GPARTS} ${GPART}" 344 | PARTS="${PARTS} ${DEV}p${PART}" 345 | _PARTS="${_PARTS} ${DEV}p${PART}" 346 | done 347 | ZPARTS="${ZPARTS} ${RAID} ${_PARTS}" 348 | 349 | echo -n "Creating ZFS pool ${POOL} on ${PARTS} ..." 350 | if ! /sbin/zpool create -f -m none ${ALTROOT} ${COMPATFLAGS} ${VERSION} ${POOL} ${ZPARTS} > /dev/null 2> /dev/null; then 351 | echo " error" 352 | exit 1 353 | fi 354 | echo " done" 355 | 356 | if [ "${FLETCHER}" = "1" ]; then 357 | echo -n "Setting default checksum to fletcher4 for ${POOL} ..." 358 | if ! /sbin/zfs set checksum=fletcher4 ${POOL} > /dev/null 2> /dev/null; then 359 | echo " error" 360 | exit 1 361 | fi 362 | echo " done" 363 | fi 364 | 365 | if [ "${COMPRESS}" = "1" ]; then 366 | echo -n "Enabling default compression on ${POOL} ..." 367 | if ! /sbin/zfs set compression=on ${POOL} > /dev/null 2> /dev/null; then 368 | echo " error" 369 | exit 1 370 | fi 371 | echo " done" 372 | fi 373 | 374 | echo -n "Creating ${POOL} root partition:" 375 | if ! /sbin/zfs create -o mountpoint=${ROOTMNT} ${POOL}/root > /dev/null 2> /dev/null; then 376 | echo " error" 377 | exit 1 378 | fi 379 | echo " ... done" 380 | echo -n "Creating ${POOL} partitions:" 381 | for FS in ${FS_LIST}; do 382 | if [ "${LEGACY}" = 1 ]; then 383 | MNTPT="-o mountpoint=legacy" 384 | else 385 | MNTPT= 386 | fi 387 | if ! /sbin/zfs create ${MNTPT} ${POOL}/root/${FS} > /dev/null 2> /dev/null; then 388 | echo " error" 389 | exit 1 390 | fi 391 | echo -n " ${FS}" 392 | done 393 | echo " ... done" 394 | echo -n "Setting bootfs for ${POOL} to ${POOL}/root ..." 395 | if ! /sbin/zpool set bootfs=${POOL}/root ${POOL} > /dev/null 2> /dev/null; then 396 | echo " error" 397 | exit 1 398 | fi 399 | echo " done" 400 | /sbin/zfs list -r ${POOL} 401 | 402 | # Mount and populate zfs (if legacy) 403 | if [ "${LEGACY}" = "1" ]; then 404 | echo -n "Mounting ${POOL} on ${MNT} ..." 405 | /bin/mkdir -p ${MNT} 406 | if ! /sbin/mount -t zfs ${POOL}/root ${MNT} > /dev/null 2> /dev/null; then 407 | echo " error mounting pool/root" 408 | exit 1 409 | fi 410 | for FS in ${FS_LIST}; do 411 | /bin/mkdir -p ${MNT}/${FS} 412 | if ! /sbin/mount -t zfs ${POOL}/root/${FS} ${MNT}/${FS} > /dev/null 2> /dev/null; then 413 | echo " error mounting ${POOL}/root/${FS}" 414 | exit 1 415 | fi 416 | done 417 | echo " done" 418 | fi 419 | 420 | echo -n "Extracting FreeBSD distribution ..." 421 | for file in ${EXTRACT_FILES}; do 422 | if ! /usr/bin/tar -C ${MNT} -x -f ${file} > /dev/null 2> /dev/null; then 423 | echo " error" 424 | exit 1 425 | fi 426 | done 427 | echo " done" 428 | 429 | # Adjust configuration files 430 | 431 | echo -n "Writing /boot/loader.conf..." 432 | echo "zfs_load=\"YES\"" > ${MNT}/boot/loader.conf 433 | echo "vfs.root.mountfrom=\"zfs:${POOL}/root\"" >> ${MNT}/boot/loader.conf 434 | echo " done" 435 | 436 | # Write fstab if swap or legacy 437 | echo -n "Writing /etc/fstab..." 438 | rm -f ${MNT}/etc/fstab 439 | touch ${MNT}/etc/fstab 440 | if [ -n "${FSWAP}" -o "${LEGACY}" = "1" ]; then 441 | if [ -n "${FSWAP}" ]; then 442 | echo "/dev/${FSWAP} none swap sw 0 0" > ${MNT}/etc/fstab 443 | fi 444 | if [ "${LEGACY}" = "1" ]; then 445 | for FS in ${FS_LIST}; do 446 | echo ${POOL}/root/${FS} /${FS} zfs rw 0 0 >> ${MNT}/etc/fstab 447 | done 448 | fi 449 | fi 450 | if [ "${LEGACY}" != "1" ]; then 451 | echo -n "Writing /etc/rc.conf..." 452 | echo 'zfs_enable="YES"' >> ${MNT}/etc/rc.conf 453 | fi 454 | echo " done" 455 | 456 | echo -n "Copying /boot/zfs/zpool.cache ..." 457 | if [ -n "${LEGACY}" ]; then 458 | for FS in ${FS_LIST}; do 459 | /sbin/umount ${MNT}/${FS} > /dev/null 2> /dev/null 460 | done 461 | /sbin/umount ${MNT} > /dev/null 2> /dev/null 462 | fi 463 | if ! /sbin/zpool export ${POOL} > /dev/null 2> /dev/null; then 464 | echo " error exporting pool" 465 | exit 1 466 | fi 467 | if ! /sbin/zpool import ${ALTROOT} ${POOL} > /dev/null 2> /dev/null; then 468 | echo " error importing pool" 469 | exit 1 470 | fi 471 | if [ -n "${LEGACY}" ]; then 472 | if ! /sbin/mount -t zfs ${POOL}/root ${MNT} > /dev/null 2> /dev/null; then 473 | echo " error mounting ${POOL}/root" 474 | exit 1 475 | fi 476 | fi 477 | if ! /bin/cp /boot/zfs/zpool.cache ${MNT}/boot/zfs/ > /dev/null 2> /dev/null; then 478 | echo " error copying zpool.cache" 479 | exit 1 480 | fi 481 | if [ -n "${LEGACY}" ]; then 482 | for FS in ${FS_LIST}; do 483 | if ! /sbin/mount -t zfs ${POOL}/${FS} ${MNT}/${FS} > /dev/null 2> /dev/null; then 484 | echo " error mounting ${POOL}/${FS}" 485 | exit 1 486 | fi 487 | done 488 | fi 489 | echo " done" 490 | 491 | echo "" 492 | echo "Installation complete." 493 | echo "The system will boot from ZFS with clean install on next reboot" 494 | echo "" 495 | echo "You may make adjustments to the installed system using chroot:" 496 | echo "chroot ${MNT}" 497 | echo "" 498 | echo "Some adjustments may require a mounted devfs:" 499 | echo "mount -t devfs devfs ${MNT}/dev" 500 | echo "" 501 | echo "WARNING - Don't export ZFS pool \"${POOL}\"!" 502 | --------------------------------------------------------------------------------