xref: /minix/releasetools/x86_usbimage.sh (revision 045e0ed3)
1#!/usr/bin/env bash
2set -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
17if [ ! -f ${BUILDSH} ]
18then
19	echo "Please invoke me from the root source dir, where ${BUILDSH} is."
20	exit 1
21fi
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
31MODDIR=${DESTDIR}/boot/minix/.temp
32
33echo "Building work directory..."
34build_workdir "$SETS"
35
36echo "Adding extra files..."
37workdir_add_ramdisk_files
38
39# set correct message of the day (log in and install tip)
40cp releasetools/release/ramdisk/etc/issue ${ROOT_DIR}/etc/issue
41add_file_spec "etc/issue" extra.cdfiles
42
43echo "Bundling packages..."
44bundle_packages "$BUNDLE_PACKAGES"
45
46echo "Creating specification files..."
47create_input_spec
48create_protos
49
50echo "Writing ramdisk image..."
51# add the other modules for boot
52cp ${MODDIR}/* ${WORK_DIR}
53create_ramdisk_image ${RAMDISK_SIZE}
54
55echo "Writing USB image..."
56# clear ROOT_DIR
57rm -rf ${ROOT_DIR}/*
58echo ". type=dir uid=0 gid=0 mode=0755" > ${WORK_DIR}/extra.boot
59
60# move all modules back to ROOT_DIR
61mv ${WORK_DIR}/kernel ${WORK_DIR}/mod* ${ROOT_DIR}/
62add_file_spec "kernel" extra.boot
63for i in ${ROOT_DIR}/mod*; do
64	add_file_spec $(basename $i) extra.boot
65done
66
67# add boot.cfg
68cat >${ROOT_DIR}/boot.cfg <<END_BOOT_CFG
69menu=Start MINIX 3:load_mods /mod*; multiboot /kernel bootramdisk=1
70menu=Edit menu option:edit
71menu=Drop to boot prompt:prompt
72clear=1
73timeout=5
74default=1
75END_BOOT_CFG
76add_file_spec "boot.cfg" extra.boot
77
78# add boot monitor
79cp ${DESTDIR}/usr/mdec/boot_monitor ${ROOT_DIR}/boot_monitor
80add_file_spec "boot_monitor" extra.boot
81
82# create proto file
83cat ${WORK_DIR}/extra.boot | ${CROSS_TOOLS}/nbtoproto -b ${ROOT_DIR} -o ${WORK_DIR}/proto.boot
84
85ROOT_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
96echo ""
97echo "Universally Supported Boot disk image at `pwd`/${IMG}"
98echo ""
99echo "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}"
102echo "qemu-system-i386 --enable-kvm -m 1G -hda `pwd`/${IMG}"
103echo ""
104echo "To boot this image on kvm:"
105echo "cd ${ROOT_DIR} && qemu-system-i386 --enable-kvm -m 1G -kernel kernel -append \"bootramdisk=1\" -initrd \"${mods}\""
106