1 #!/usr/bin/env bash 2 set -e 3 4 # 5 # This script creates a bootable image and should at some point in the future 6 # be replaced by the proper NetBSD infrastructure. 7 # 8 9 : ${ARCH=i386} 10 : ${OBJ=../obj.${ARCH}} 11 : ${TOOLCHAIN_TRIPLET=i586-elf32-minix-} 12 : ${BUILDSH=build.sh} 13 14 : ${SETS="minix-base"} 15 : ${IMG=minix_x86_usb.img} 16 17 if [ ! -f ${BUILDSH} ] 18 then 19 echo "Please invoke me from the root source dir, where ${BUILDSH} is." 20 exit 1 21 fi 22 23 #: ${RAMDISK_SIZE=$(( 200*(2**20) ))} 24 : ${BOOTXX_SECS=32} 25 26 # set up disk creation environment 27 . releasetools/image.defaults 28 . releasetools/image.functions 29 30 # where the kernel & boot modules will be 31 MODDIR=${DESTDIR}/boot/minix/.temp 32 33 echo "Building work directory..." 34 build_workdir "$SETS" 35 36 echo "Adding extra files..." 37 workdir_add_ramdisk_files 38 39 # set correct message of the day (log in and install tip) 40 cp releasetools/release/ramdisk/etc/issue ${ROOT_DIR}/etc/issue 41 add_file_spec "etc/issue" extra.cdfiles 42 43 echo "Bundling packages..." 44 bundle_packages "$BUNDLE_PACKAGES" 45 46 echo "Creating specification files..." 47 create_input_spec 48 create_protos 49 50 echo "Writing ramdisk image..." 51 # add the other modules for boot 52 cp ${MODDIR}/* ${WORK_DIR} 53 create_ramdisk_image ${RAMDISK_SIZE} 54 55 echo "Writing USB image..." 56 # clear ROOT_DIR 57 rm -rf ${ROOT_DIR}/* 58 echo ". type=dir uid=0 gid=0 mode=0755" > ${WORK_DIR}/extra.boot 59 60 # move all modules back to ROOT_DIR 61 mv ${WORK_DIR}/kernel ${WORK_DIR}/mod* ${ROOT_DIR}/ 62 add_file_spec "kernel" extra.boot 63 for i in ${ROOT_DIR}/mod*; do 64 add_file_spec $(basename $i) extra.boot 65 done 66 67 # add boot.cfg 68 cat >${ROOT_DIR}/boot.cfg <<END_BOOT_CFG 69 menu=Start MINIX 3:load_mods /mod*; multiboot /kernel bootramdisk=1 70 menu=Edit menu option:edit 71 menu=Drop to boot prompt:prompt 72 clear=1 73 timeout=5 74 default=1 75 END_BOOT_CFG 76 add_file_spec "boot.cfg" extra.boot 77 78 # add boot monitor 79 cp ${DESTDIR}/usr/mdec/boot_monitor ${ROOT_DIR}/boot_monitor 80 add_file_spec "boot_monitor" extra.boot 81 82 # create proto file 83 cat ${WORK_DIR}/extra.boot | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR} -o ${WORK_DIR}/proto.boot 84 85 ROOT_START=${BOOTXX_SECS} 86 _ROOT_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -I $((${ROOT_START} * 512)) ${IMG} ${WORK_DIR}/proto.boot) 87 _ROOT_SIZE=$(($_ROOT_SIZE / 512)) 88 89 # 90 # Write the partition table using the natively compiled 91 # minix partition utility 92 # 93 ${CROSS_TOOLS}/nbpartition -m ${IMG} ${BOOTXX_SECS} 81:${_ROOT_SIZE} 94 ${CROSS_TOOLS}/nbinstallboot -f -m ${ARCH} ${IMG} ${DESTDIR}/usr/mdec/bootxx_minixfs3 95 96 echo "" 97 echo "Universally Supported Boot disk image at `pwd`/${IMG}" 98 echo "" 99 echo "To boot this image on kvm using the bootloader:" 100 # This is really, really slow. 101 # echo "qemu-system-i386 --enable-kvm -m 1G -usbdevice disk:`pwd`/${IMG}" 102 echo "qemu-system-i386 --enable-kvm -m 1G -hda `pwd`/${IMG}" 103 echo "" 104 echo "To boot this image on kvm:" 105 echo "cd ${ROOT_DIR} && qemu-system-i386 --enable-kvm -m 1G -kernel kernel -append \"bootramdisk=1\" -initrd \"${mods}\"" 106