1#!/bin/sh 2 3# $FreeBSD$ 4 5passphrase=passphrase 6iterations=50000 7 8# The smallest FAT32 filesystem is 33292 KB 9espsize=33292 10dev=vtbd0 11 12# 13# Builds all the bat-shit crazy combinations we support booting from, 14# at least for amd64. It assume you have a ~sane kernel in /boot/kernel 15# and copies that into the ~150MB root images we create (we create the du 16# size of the kernel + 20MB 17# 18# Sad panda sez: this runs as root, but could be userland if someone 19# creates userland geli and zfs tools. 20# 21# This assumes an external program install-boot.sh which will install 22# the appropriate boot files in the appropriate locations. 23# 24# These images assume ${dev} will be the root image. We should likely 25# use labels, but we don't. 26# 27# Assumes you've already rebuilt... maybe bad? Also maybe bad: the env 28# vars should likely be conditionally set to allow better automation. 29# 30 31. $(dirname $0)/install-boot.sh 32 33cpsys() { 34 src=$1 35 dst=$2 36 37 # Copy kernel + boot loader 38 (cd $src ; tar cf - .) | (cd $dst; tar xf -) 39} 40 41mk_nogeli_gpt_ufs_legacy() { 42 src=$1 43 img=$2 44 45 cat > ${src}/etc/fstab <<EOF 46/dev/${dev}p2 / ufs rw 1 1 47EOF 48 makefs -t ffs -B little -s 200m ${img}.p2 ${src} 49 mkimg -s gpt -b ${src}/boot/pmbr \ 50 -p freebsd-boot:=${src}/boot/gptboot \ 51 -p freebsd-ufs:=${img}.p2 -o ${img} 52 rm -f ${src}/etc/fstab 53} 54 55mk_nogeli_gpt_ufs_uefi() { 56 src=$1 57 img=$2 58 59 cat > ${src}/etc/fstab <<EOF 60/dev/${dev}p2 / ufs rw 1 1 61EOF 62 make_esp_file ${img}.p1 ${espsize} ${src}/boot/loader.efi 63 makefs -t ffs -B little -s 200m ${img}.p2 ${src} 64 mkimg -s gpt \ 65 -p efi:=${img}.p1 \ 66 -p freebsd-ufs:=${img}.p2 -o ${img} 67 rm -f ${src}/etc/fstab 68} 69 70mk_nogeli_gpt_ufs_both() { 71 src=$1 72 img=$2 73 74 cat > ${src}/etc/fstab <<EOF 75/dev/${dev}p3 / ufs rw 1 1 76EOF 77 make_esp_file ${img}.p1 ${espsize} ${src}/boot/loader.efi 78 makefs -t ffs -B little -s 200m ${img}.p3 ${src} 79 # p1 is boot for uefi, p2 is boot for gpt, p3 is / 80 mkimg -b ${src}/boot/pmbr -s gpt \ 81 -p efi:=${img}.p1 \ 82 -p freebsd-boot:=${src}/boot/gptboot \ 83 -p freebsd-ufs:=${img}.p3 \ 84 -o ${img} 85 rm -f ${src}/etc/fstab 86} 87 88mk_nogeli_gpt_zfs_legacy() { 89 src=$1 90 img=$2 91 mntpt=$3 92 geli=$4 93 scheme=$5 94 fs=$6 95 bios=$7 96 pool=nogeli-gpt-zfs-legacy 97 98 dd if=/dev/zero of=${img} count=1 seek=$((200 * 1024 * 1024 / 512)) 99 md=$(mdconfig -f ${img}) 100 gpart create -s gpt ${md} 101 gpart add -t freebsd-boot -s 400k -a 4k ${md} # <= ~540k 102 gpart add -t freebsd-zfs -l root $md 103 # install-boot will make this bootable 104 zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p2 105 zpool set bootfs=${pool} ${pool} 106 zfs create -po mountpoint=/ ${pool}/ROOT/default 107 # NB: The online guides go nuts customizing /var and other mountpoints here, no need 108 cpsys ${src} ${mntpt} 109 # need to make a couple of tweaks 110 cat >> ${mntpt}/boot/loader.conf <<EOF 111cryptodev_load=YES 112zfs_load=YES 113EOF 114 cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko 115 cp /boot/kernel/cryptodev.ko ${mntpt}/boot/kernel/cryptodev.ko 116 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko 117 # end tweaks 118 zfs umount -f ${pool}/ROOT/default 119 zfs set mountpoint=none ${pool}/ROOT/default 120 zpool set bootfs=${pool}/ROOT/default ${pool} 121 zpool set autoexpand=on ${pool} 122 zpool export ${pool} 123 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 124 mdconfig -d -u ${md} 125} 126 127mk_nogeli_gpt_zfs_uefi() { 128 src=$1 129 img=$2 130 mntpt=$3 131 geli=$4 132 scheme=$5 133 fs=$6 134 bios=$7 135 pool=nogeli-gpt-zfs-uefi 136 137 dd if=/dev/zero of=${img} count=1 seek=$((200 * 1024 * 1024 / 512)) 138 md=$(mdconfig -f ${img}) 139 gpart create -s gpt ${md} 140 gpart add -t efi -s ${espsize}k -a 4k ${md} 141 gpart add -t freebsd-zfs -l root $md 142 # install-boot will make this bootable 143 zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p2 144 zpool set bootfs=${pool} ${pool} 145 zfs create -po mountpoint=/ ${pool}/ROOT/default 146 # NB: The online guides go nuts customizing /var and other mountpoints here, no need 147 cpsys ${src} ${mntpt} 148 # need to make a couple of tweaks 149 cat >> ${mntpt}/boot/loader.conf <<EOF 150cryptodev_load=YES 151zfs_load=YES 152EOF 153 cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko 154 cp /boot/kernel/cryptodev.ko ${mntpt}/boot/kernel/cryptodev.ko 155 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko 156 # end tweaks 157 zfs umount -f ${pool}/ROOT/default 158 zfs set mountpoint=none ${pool}/ROOT/default 159 zpool set bootfs=${pool}/ROOT/default ${pool} 160 zpool set autoexpand=on ${pool} 161 zpool export ${pool} 162 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 163 mdconfig -d -u ${md} 164} 165 166mk_nogeli_gpt_zfs_both() { 167 src=$1 168 img=$2 169 mntpt=$3 170 geli=$4 171 scheme=$5 172 fs=$6 173 bios=$7 174 pool=nogeli-gpt-zfs-both 175 176 dd if=/dev/zero of=${img} count=1 seek=$((200 * 1024 * 1024 / 512)) 177 md=$(mdconfig -f ${img}) 178 gpart create -s gpt ${md} 179 gpart add -t efi -s ${espsize}k -a 4k ${md} 180 gpart add -t freebsd-boot -s 400k -a 4k ${md} # <= ~540k 181 gpart add -t freebsd-zfs -l root $md 182 # install-boot will make this bootable 183 zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p3 184 zpool set bootfs=${pool} ${pool} 185 zfs create -po mountpoint=/ ${pool}/ROOT/default 186 # NB: The online guides go nuts customizing /var and other mountpoints here, no need 187 cpsys ${src} ${mntpt} 188 # need to make a couple of tweaks 189 cat >> ${mntpt}/boot/loader.conf <<EOF 190cryptodev_load=YES 191zfs_load=YES 192EOF 193 cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko 194 cp /boot/kernel/cryptodev.ko ${mntpt}/boot/kernel/cryptodev.ko 195 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko 196 # end tweaks 197 zfs umount -f ${pool}/ROOT/default 198 zfs set mountpoint=none ${pool}/ROOT/default 199 zpool set bootfs=${pool}/ROOT/default ${pool} 200 zpool set autoexpand=on ${pool} 201 zpool export ${pool} 202 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 203 mdconfig -d -u ${md} 204} 205 206mk_nogeli_mbr_ufs_legacy() { 207 src=$1 208 img=$2 209 210 cat > ${src}/etc/fstab <<EOF 211/dev/${dev}s1a / ufs rw 1 1 212EOF 213 makefs -t ffs -B little -s 200m ${img}.s1a ${src} 214 mkimg -s bsd -b ${src}/boot/boot -p freebsd-ufs:=${img}.s1a -o ${img}.s1 215 mkimg -a 1 -s mbr -b ${src}/boot/boot0sio -p freebsd:=${img}.s1 -o ${img} 216 rm -f ${src}/etc/fstab 217} 218 219mk_nogeli_mbr_ufs_uefi() { 220 src=$1 221 img=$2 222 223 cat > ${src}/etc/fstab <<EOF 224/dev/${dev}s2a / ufs rw 1 1 225EOF 226 make_esp_file ${img}.s1 ${espsize} ${src}/boot/loader.efi 227 makefs -t ffs -B little -s 200m ${img}.s2a ${src} 228 mkimg -s bsd -p freebsd-ufs:=${img}.s2a -o ${img}.s2 229 mkimg -a 1 -s mbr -p efi:=${img}.s1 -p freebsd:=${img}.s2 -o ${img} 230 rm -f ${src}/etc/fstab 231} 232 233mk_nogeli_mbr_ufs_both() { 234 src=$1 235 img=$2 236 237 cat > ${src}/etc/fstab <<EOF 238/dev/${dev}s2a / ufs rw 1 1 239EOF 240 make_esp_file ${img}.s1 ${espsize} ${src}/boot/loader.efi 241 makefs -t ffs -B little -s 200m ${img}.s2a ${src} 242 mkimg -s bsd -b ${src}/boot/boot -p freebsd-ufs:=${img}.s2a -o ${img}.s2 243 mkimg -a 2 -s mbr -b ${src}/boot/mbr -p efi:=${img}.s1 -p freebsd:=${img}.s2 -o ${img} 244 rm -f ${src}/etc/fstab 245} 246 247mk_nogeli_mbr_zfs_legacy() { 248 src=$1 249 img=$2 250 mntpt=$3 251 geli=$4 252 scheme=$5 253 fs=$6 254 bios=$7 255 pool=nogeli-mbr-zfs-legacy 256 257 dd if=/dev/zero of=${img} count=1 seek=$((200 * 1024 * 1024 / 512)) 258 md=$(mdconfig -f ${img}) 259 gpart create -s mbr ${md} 260 gpart add -t freebsd ${md} 261 gpart set -a active -i 1 ${md} 262 gpart create -s bsd ${md}s1 263 gpart add -t freebsd-zfs ${md}s1 264 # install-boot will make this bootable 265 zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}s1a 266 zpool set bootfs=${pool} ${pool} 267 zfs create -po mountpoint=/ ${pool}/ROOT/default 268 # NB: The online guides go nuts customizing /var and other mountpoints here, no need 269 cpsys ${src} ${mntpt} 270 # need to make a couple of tweaks 271 cat >> ${mntpt}/boot/loader.conf <<EOF 272cryptodev_load=YES 273zfs_load=YES 274EOF 275 cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko 276 cp /boot/kernel/cryptodev.ko ${mntpt}/boot/kernel/cryptodev.ko 277 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko 278 # end tweaks 279 zfs umount -f ${pool}/ROOT/default 280 zfs set mountpoint=none ${pool}/ROOT/default 281 zpool set bootfs=${pool}/ROOT/default ${pool} 282 zpool set autoexpand=on ${pool} 283 zpool export ${pool} 284 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 285 mdconfig -d -u ${md} 286} 287 288mk_nogeli_mbr_zfs_uefi() { 289 src=$1 290 img=$2 291 mntpt=$3 292 geli=$4 293 scheme=$5 294 fs=$6 295 bios=$7 296 pool=nogeli-mbr-zfs-uefi 297 298 dd if=/dev/zero of=${img} count=1 seek=$((200 * 1024 * 1024 / 512)) 299 md=$(mdconfig -f ${img}) 300 gpart create -s mbr ${md} 301 gpart add -t efi -s ${espsize}k ${md} 302 gpart add -t freebsd ${md} 303 gpart set -a active -i 2 ${md} 304 gpart create -s bsd ${md}s2 305 gpart add -t freebsd-zfs ${md}s2 306 # install-boot will make this bootable 307 zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}s2a 308 zpool set bootfs=${pool} ${pool} 309 zfs create -po mountpoint=/ ${pool}/ROOT/default 310 # NB: The online guides go nuts customizing /var and other mountpoints here, no need 311 cpsys ${src} ${mntpt} 312 # need to make a couple of tweaks 313 cat >> ${mntpt}/boot/loader.conf <<EOF 314cryptodev_load=YES 315zfs_load=YES 316EOF 317 cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko 318 cp /boot/kernel/cryptodev.ko ${mntpt}/boot/kernel/cryptodev.ko 319 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko 320 # end tweaks 321 zfs umount -f ${pool}/ROOT/default 322 zfs set mountpoint=none ${pool}/ROOT/default 323 zpool set bootfs=${pool}/ROOT/default ${pool} 324 zpool set autoexpand=on ${pool} 325 zpool export ${pool} 326 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 327 mdconfig -d -u ${md} 328} 329 330mk_nogeli_mbr_zfs_both() { 331 src=$1 332 img=$2 333 mntpt=$3 334 geli=$4 335 scheme=$5 336 fs=$6 337 bios=$7 338 pool=nogeli-mbr-zfs-both 339 340 dd if=/dev/zero of=${img} count=1 seek=$((200 * 1024 * 1024 / 512)) 341 md=$(mdconfig -f ${img}) 342 gpart create -s mbr ${md} 343 gpart add -t efi -s ${espsize}k ${md} 344 gpart add -t freebsd ${md} 345 gpart set -a active -i 2 ${md} 346 gpart create -s bsd ${md}s2 347 gpart add -t freebsd-zfs ${md}s2 348 # install-boot will make this bootable 349 zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}s2a 350 zpool set bootfs=${pool} ${pool} 351 zfs create -po mountpoint=/ ${pool}/ROOT/default 352 # NB: The online guides go nuts customizing /var and other mountpoints here, no need 353 cpsys ${src} ${mntpt} 354 # need to make a couple of tweaks 355 cat >> ${mntpt}/boot/loader.conf <<EOF 356cryptodev_load=YES 357zfs_load=YES 358EOF 359 cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko 360 cp /boot/kernel/cryptodev.ko ${mntpt}/boot/kernel/cryptodev.ko 361 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko 362 # end tweaks 363 zfs umount -f ${pool}/ROOT/default 364 zfs set mountpoint=none ${pool}/ROOT/default 365 zpool set bootfs=${pool}/ROOT/default ${pool} 366 zpool set autoexpand=on ${pool} 367 zpool export ${pool} 368 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 369 mdconfig -d -u ${md} 370} 371 372mk_geli_gpt_ufs_legacy() { 373 src=$1 374 img=$2 375 mntpt=$3 376 geli=$4 377 scheme=$5 378 fs=$6 379 bios=$7 380 381 dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 )) 382 md=$(mdconfig -f ${img}) 383 gpart create -s gpt ${md} 384 gpart add -t freebsd-boot -s 400k -a 4k ${md} # <= ~540k 385 gpart add -t freebsd-ufs -l root $md 386 # install-boot will make this bootable 387 echo ${passphrase} | geli init -bg -e AES-XTS -i ${iterations} -J - -l 256 -s 4096 ${md}p2 388 echo ${passphrase} | geli attach -j - ${md}p2 389 newfs /dev/${md}p2.eli 390 mount /dev/${md}p2.eli ${mntpt} 391 cpsys ${src} ${mntpt} 392 # need to make a couple of tweaks 393 cat > ${mntpt}/boot/loader.conf <<EOF 394geom_eli_load=YES 395EOF 396 cat > ${mntpt}/etc/fstab <<EOF 397/dev/${dev}p2.eli / ufs rw 1 1 398EOF 399 400 cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko 401 # end tweaks 402 umount -f ${mntpt} 403 geli detach ${md}p2 404 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 405 mdconfig -d -u ${md} 406} 407 408mk_geli_gpt_ufs_uefi() { 409 src=$1 410 img=$2 411 mntpt=$3 412 geli=$4 413 scheme=$5 414 fs=$6 415 bios=$7 416 417 dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 )) 418 md=$(mdconfig -f ${img}) 419 gpart create -s gpt ${md} 420 gpart add -t efi -s ${espsize}k -a 4k ${md} 421 gpart add -t freebsd-ufs -l root $md 422 # install-boot will make this bootable 423 echo ${passphrase} | geli init -bg -e AES-XTS -i ${iterations} -J - -l 256 -s 4096 ${md}p2 424 echo ${passphrase} | geli attach -j - ${md}p2 425 newfs /dev/${md}p2.eli 426 mount /dev/${md}p2.eli ${mntpt} 427 cpsys ${src} ${mntpt} 428 # need to make a couple of tweaks 429 cat > ${mntpt}/boot/loader.conf <<EOF 430geom_eli_load=YES 431EOF 432 cat > ${mntpt}/etc/fstab <<EOF 433/dev/${dev}p2.eli / ufs rw 1 1 434EOF 435 436 cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko 437 # end tweaks 438 umount -f ${mntpt} 439 geli detach ${md}p2 440 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 441 mdconfig -d -u ${md} 442} 443 444mk_geli_gpt_ufs_both() { 445 src=$1 446 img=$2 447 mntpt=$3 448 geli=$4 449 scheme=$5 450 fs=$6 451 bios=$7 452 453 dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 )) 454 md=$(mdconfig -f ${img}) 455 gpart create -s gpt ${md} 456 gpart add -t efi -s ${espsize}k -a 4k ${md} 457 gpart add -t freebsd-boot -s 400k -a 4k ${md} # <= ~540k 458 gpart add -t freebsd-ufs -l root $md 459 # install-boot will make this bootable 460 echo ${passphrase} | geli init -bg -e AES-XTS -i ${iterations} -J - -l 256 -s 4096 ${md}p3 461 echo ${passphrase} | geli attach -j - ${md}p3 462 newfs /dev/${md}p3.eli 463 mount /dev/${md}p3.eli ${mntpt} 464 cpsys ${src} ${mntpt} 465 # need to make a couple of tweaks 466 cat > ${mntpt}/boot/loader.conf <<EOF 467geom_eli_load=YES 468EOF 469 cat > ${mntpt}/etc/fstab <<EOF 470/dev/${dev}p3.eli / ufs rw 1 1 471EOF 472 473 cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko 474 # end tweaks 475 umount -f ${mntpt} 476 geli detach ${md}p3 477 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 478 mdconfig -d -u ${md} 479} 480 481mk_geli_gpt_zfs_legacy() { 482 src=$1 483 img=$2 484 mntpt=$3 485 geli=$4 486 scheme=$5 487 fs=$6 488 bios=$7 489 pool=geli-gpt-zfs-legacy 490 491 # Note that in this flavor we create an empty p2 ufs partition, and put 492 # the bootable zfs stuff on p3, just to test the ability of the zfs probe 493 # probe routines to find a pool on a partition other than the first one. 494 495 dd if=/dev/zero of=${img} count=1 seek=$(( 300 * 1024 * 1024 / 512 )) 496 md=$(mdconfig -f ${img}) 497 gpart create -s gpt ${md} 498 gpart add -t freebsd-boot -s 400k -a 4k ${md} # <= ~540k 499 gpart add -t freebsd-ufs -s 100m ${md} 500 gpart add -t freebsd-zfs -l root $md 501 # install-boot will make this bootable 502 echo ${passphrase} | geli init -bg -e AES-XTS -i ${iterations} -J - -l 256 -s 4096 ${md}p3 503 echo ${passphrase} | geli attach -j - ${md}p3 504 zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p3.eli 505 zpool set bootfs=${pool} ${pool} 506 zfs create -po mountpoint=/ ${pool}/ROOT/default 507 # NB: The online guides go nuts customizing /var and other mountpoints here, no need 508 cpsys ${src} ${mntpt} 509 # need to make a couple of tweaks 510 cat >> ${mntpt}/boot/loader.conf <<EOF 511cryptodev_load=YES 512zfs_load=YES 513geom_eli_load=YES 514EOF 515 cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko 516 cp /boot/kernel/cryptodev.ko ${mntpt}/boot/kernel/cryptodev.ko 517 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko 518 cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko 519 # end tweaks 520 zfs umount -f ${pool}/ROOT/default 521 zfs set mountpoint=none ${pool}/ROOT/default 522 zpool set bootfs=${pool}/ROOT/default ${pool} 523 zpool set autoexpand=on ${pool} 524 zpool export ${pool} 525 geli detach ${md}p3 526 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 527 mdconfig -d -u ${md} 528} 529 530mk_geli_gpt_zfs_uefi() { 531 src=$1 532 img=$2 533 mntpt=$3 534 geli=$4 535 scheme=$5 536 fs=$6 537 bios=$7 538 pool=geli-gpt-zfs-uefi 539 540 # Note that in this flavor we create an empty p2 ufs partition, and put 541 # the bootable zfs stuff on p3, just to test the ability of the zfs probe 542 # probe routines to find a pool on a partition other than the first one. 543 544 dd if=/dev/zero of=${img} count=1 seek=$(( 300 * 1024 * 1024 / 512 )) 545 md=$(mdconfig -f ${img}) 546 gpart create -s gpt ${md} 547 gpart add -t efi -s ${espsize}k -a 4k ${md} 548 gpart add -t freebsd-ufs -s 100m ${md} 549 gpart add -t freebsd-zfs -l root $md 550 # install-boot will make this bootable 551 echo ${passphrase} | geli init -bg -e AES-XTS -i ${iterations} -J - -l 256 -s 4096 ${md}p3 552 echo ${passphrase} | geli attach -j - ${md}p3 553 zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p3.eli 554 zpool set bootfs=${pool} ${pool} 555 zfs create -po mountpoint=/ ${pool}/ROOT/default 556 # NB: The online guides go nuts customizing /var and other mountpoints here, no need 557 cpsys ${src} ${mntpt} 558 # need to make a couple of tweaks 559 cat >> ${mntpt}/boot/loader.conf <<EOF 560cryptodev_load=YES 561zfs_load=YES 562geom_eli_load=YES 563EOF 564 cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko 565 cp /boot/kernel/cryptodev.ko ${mntpt}/boot/kernel/cryptodev.ko 566 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko 567 cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko 568 # end tweaks 569 zfs umount -f ${pool}/ROOT/default 570 zfs set mountpoint=none ${pool}/ROOT/default 571 zpool set bootfs=${pool}/ROOT/default ${pool} 572 zpool set autoexpand=on ${pool} 573 zpool export ${pool} 574 geli detach ${md}p3 575 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 576 mdconfig -d -u ${md} 577} 578 579mk_geli_gpt_zfs_both() { 580 src=$1 581 img=$2 582 mntpt=$3 583 geli=$4 584 scheme=$5 585 fs=$6 586 bios=$7 587 pool=geli-gpt-zfs-both 588 589 dd if=/dev/zero of=${img} count=1 seek=$(( 200 * 1024 * 1024 / 512 )) 590 md=$(mdconfig -f ${img}) 591 gpart create -s gpt ${md} 592 gpart add -t efi -s ${espsize}k -a 4k ${md} 593 gpart add -t freebsd-boot -s 400k -a 4k ${md} # <= ~540k 594 gpart add -t freebsd-zfs -l root $md 595 # install-boot will make this bootable 596 echo ${passphrase} | geli init -bg -e AES-XTS -i ${iterations} -J - -l 256 -s 4096 ${md}p3 597 echo ${passphrase} | geli attach -j - ${md}p3 598 zpool create -O mountpoint=none -R ${mntpt} ${pool} ${md}p3.eli 599 zpool set bootfs=${pool} ${pool} 600 zfs create -po mountpoint=/ ${pool}/ROOT/default 601 # NB: The online guides go nuts customizing /var and other mountpoints here, no need 602 cpsys ${src} ${mntpt} 603 # need to make a couple of tweaks 604 cat > ${mntpt}/boot/loader.conf <<EOF 605cryptodev_load=YES 606zfs_load=YES 607geom_eli_load=YES 608EOF 609 cp /boot/kernel/acl_nfs4.ko ${mntpt}/boot/kernel/acl_nfs4.ko 610 cp /boot/kernel/cryptodev.ko ${mntpt}/boot/kernel/cryptodev.ko 611 cp /boot/kernel/zfs.ko ${mntpt}/boot/kernel/zfs.ko 612 cp /boot/kernel/geom_eli.ko ${mntpt}/boot/kernel/geom_eli.ko 613 # end tweaks 614 zfs umount -f ${pool}/ROOT/default 615 zfs set mountpoint=none ${pool}/ROOT/default 616 zpool set bootfs=${pool}/ROOT/default ${pool} 617 zpool set autoexpand=on ${pool} 618 zpool export ${pool} 619 geli detach ${md}p3 620 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 621 mdconfig -d -u ${md} 622} 623 624# GELI+MBR is not a valid configuration 625mk_geli_mbr_ufs_legacy() { 626} 627 628mk_geli_mbr_ufs_uefi() { 629} 630 631mk_geli_mbr_ufs_both() { 632} 633 634mk_geli_mbr_zfs_legacy() { 635} 636 637mk_geli_mbr_zfs_uefi() { 638} 639 640mk_geli_mbr_zfs_both() { 641} 642 643# iso 644# pxeldr 645# u-boot 646# powerpc 647 648mk_sparc64_nogeli_vtoc8_ufs_ofw() { 649 src=$1 650 img=$2 651 mntpt=$3 652 geli=$4 653 scheme=$5 654 fs=$6 655 bios=$7 656 657 cat > ${src}/etc/fstab <<EOF 658/dev/${dev}a / ufs rw 1 1 659EOF 660 makefs -t ffs -B big -s 200m ${img} ${src} 661 md=$(mdconfig -f ${img}) 662 # For non-native builds, ensure that geom_part(4) supports VTOC8. 663 kldload geom_part_vtoc8.ko 664 gpart create -s VTOC8 ${md} 665 gpart add -t freebsd-ufs ${md} 666 ${SRCTOP}/tools/boot/install-boot.sh -g ${geli} -s ${scheme} -f ${fs} -b ${bios} -d ${src} ${md} 667 mdconfig -d -u ${md} 668 rm -f ${src}/etc/fstab 669} 670 671qser="-serial telnet::4444,server -nographic" 672 673# https://wiki.freebsd.org/QemuRecipes 674# aarch64 675qemu_aarch64_uefi() 676{ 677 img=$1 678 sh=$2 679 680 echo "qemu-system-aarch64 -m 4096M -cpu cortex-a57 -M virt \ 681 -bios QEMU_EFI.fd ${qser} \ 682 -drive if=none,file=${img},id=hd0 \ 683 -device virtio-blk-device,drive=hd0" > $sh 684 chmod 755 $sh 685# https://wiki.freebsd.org/arm64/QEMU also has 686# -device virtio-net-device,netdev=net0 687# -netdev user,id=net0 688} 689 690# Amd64 qemu 691qemu_amd64_legacy() 692{ 693 img=$1 694 sh=$2 695 696 echo "qemu-system-x86_64 -m 256m --drive file=${img},format=raw ${qser}" > $sh 697 chmod 755 $sh 698} 699 700qemu_amd64_uefi() 701{ 702 img=$1 703 sh=$2 704 705 echo "qemu-system-x86_64 -m 256m -bios ~/bios/OVMF-X64.fd --drive file=${img},format=raw ${qser}" > $sh 706 chmod 755 $sh 707} 708 709qemu_amd64_both() 710{ 711 img=$1 712 sh=$2 713 714 echo "qemu-system-x86_64 -m 256m --drive file=${img},format=raw ${qser}" > $sh 715 echo "qemu-system-x86_64 -m 256m -bios ~/bios/OVMF-X64.fd --drive file=${img},format=raw ${qser}" >> $sh 716 chmod 755 $sh 717} 718 719# arm 720# nothing listed? 721 722# i386 723qemu_i386_legacy() 724{ 725 img=$1 726 sh=$2 727 728 echo "qemu-system-i386 --drive file=${img},format=raw ${qser}" > $sh 729 chmod 755 $sh 730} 731 732# Not yet supported 733qemu_i386_uefi() 734{ 735 img=$1 736 sh=$2 737 738 echo "qemu-system-i386 -bios ~/bios/OVMF-X32.fd --drive file=${img},format=raw ${qser}" > $sh 739 chmod 755 $sh 740} 741 742# Needs UEFI to be supported 743qemu_i386_both() 744{ 745 img=$1 746 sh=$2 747 748 echo "qemu-system-i386 --drive file=${img},format=raw ${qser}" > $sh 749 echo "qemu-system-i386 -bios ~/bios/OVMF-X32.fd --drive file=${img},format=raw ${qser}" >> $sh 750 chmod 755 $sh 751} 752 753make_one_image() 754{ 755 local arch=${1?} 756 local geli=${2?} 757 local scheme=${3?} 758 local fs=${4?} 759 local bios=${5?} 760 761 # Create sparse file and mount newly created filesystem(s) on it 762 img=${IMGDIR}/${arch}-${geli}-${scheme}-${fs}-${bios}.img 763 sh=${IMGDIR}/${arch}-${geli}-${scheme}-${fs}-${bios}.sh 764 echo "vvvvvvvvvvvvvv Creating $img vvvvvvvvvvvvvvv" 765 rm -f ${img}* 766 eval mk_${geli}_${scheme}_${fs}_${bios} ${DESTDIR} ${img} ${MNTPT} ${geli} ${scheme} ${fs} ${bios} 767 eval qemu_${arch}_${bios} ${img} ${sh} 768 [ -n "${SUDO_USER}" ] && chown ${SUDO_USER} ${img}* 769 echo "^^^^^^^^^^^^^^ Created $img ^^^^^^^^^^^^^^^" 770} 771 772# mips 773# qemu-system-mips -kernel /path/to/rootfs/boot/kernel/kernel -nographic -hda /path/to/disk.img -m 2048 774 775# Powerpc -- doesn't work but maybe it would enough for testing -- needs details 776# powerpc64 777# qemu-system-ppc64 -drive file=/path/to/disk.img,format=raw 778 779# sparc64 780# qemu-system-sparc64 -drive file=/path/to/disk.img,format=raw 781 782# Misc variables 783SRCTOP=$(make -v SRCTOP) 784cd ${SRCTOP}/stand 785OBJDIR=$(make -v .OBJDIR) 786IMGDIR=${OBJDIR}/boot-images 787mkdir -p ${IMGDIR} 788MNTPT=$(mktemp -d /tmp/stand-test.XXXXXX) 789 790# Setup the installed tree... 791DESTDIR=${OBJDIR}/boot-tree 792rm -rf ${DESTDIR} 793mkdir -p ${DESTDIR}/boot/defaults 794mkdir -p ${DESTDIR}/boot/kernel 795cp /boot/kernel/kernel ${DESTDIR}/boot/kernel 796echo -h -D -S115200 > ${DESTDIR}/boot.config 797cat > ${DESTDIR}/boot/loader.conf <<EOF 798comconsole_speed=115200 799EOF 800# XXX 801cp /boot/device.hints ${DESTDIR}/boot/device.hints 802# Assume we're already built 803make install DESTDIR=${DESTDIR} MK_MAN=no MK_INSTALL_AS_USER=yes WITHOUT_DEBUG_FILES=yes 804if [ $? -ne 0 ]; then 805 echo "make install failed" 806 exit 1 807fi 808# Copy init, /bin/sh, minimal libraries and testing /etc/rc 809mkdir -p ${DESTDIR}/sbin ${DESTDIR}/bin \ 810 ${DESTDIR}/lib ${DESTDIR}/libexec \ 811 ${DESTDIR}/etc ${DESTDIR}/dev 812for f in /sbin/halt /sbin/init /bin/sh /sbin/sysctl $(ldd /bin/sh | awk 'NF == 4 { print $3; }') /libexec/ld-elf.so.1; do 813 cp $f ${DESTDIR}/$f 814done 815cat > ${DESTDIR}/etc/rc <<EOF 816#!/bin/sh 817 818sysctl machdep.bootmethod 819echo "RC COMMAND RUNNING -- SUCCESS!!!!!" 820halt -p 821EOF 822 823# If we were given exactly 5 args, go make that one image. 824 825if [ $# -eq 5 ]; then 826 make_one_image $* 827 exit 828fi 829 830# OK. Let the games begin 831 832for arch in amd64; do 833 for geli in nogeli geli; do 834 for scheme in gpt mbr; do 835 for fs in ufs zfs; do 836 for bios in legacy uefi both; do 837 make_one_image ${arch} ${geli} ${scheme} ${fs} ${bios} 838 done 839 done 840 done 841 done 842done 843 844rmdir ${MNTPT} 845 846exit 0 847 848# Notes for the future 849 850for arch in i386; do 851 for geli in nogeli geli; do 852 for scheme in gpt mbr; do 853 for fs in ufs zfs; do 854 for bios in legacy; do 855 make_one_image ${arch} ${geli} ${scheme} ${fs} ${bios} 856 done 857 done 858 done 859 done 860done 861 862for arch in arm aarch64; do 863 for scheme in gpt mbr; do 864 fs=ufs 865 for bios in uboot efi; do 866 make_one_image ${arch} ${geli} ${scheme} ${fs} ${bios} 867 done 868 done 869done 870 871for arch in powerpc powerpc64; do 872 for scheme in ppc-wtf; do 873 fs=ufs 874 for bios in ofw uboot chrp; do 875 make_one_image ${arch} ${geli} ${scheme} ${fs} ${bios} 876 done 877 done 878done 879 880for arch in sparc64; do 881 for geli in nogeli; do 882 for scheme in vtoc8; do 883 for fs in ufs; do 884 for bios in ofw; do 885 make_one_image ${arch} ${geli} ${scheme} ${fs} ${bios} 886 done 887 done 888 done 889 done 890done 891