Fix OPSYS constant in pkg_install tools
[minix3.git] / releasetools / x86_hdimage.sh
blob32f69a1055988ce44945a64d545c913e53ae4e34
1 #!/usr/bin/env bash
2 set -e
5 # This script creates a bootable image and should at some point in the future
6 # be replaced by the proper NetBSD infrastructure.
9 : ${ARCH=i386}
10 : ${OBJ=../obj.${ARCH}}
11 : ${TOOLCHAIN_TRIPLET=i586-elf32-minix-}
12 : ${BUILDSH=build.sh}
14 : ${SETS="minix-base minix-comp minix-games minix-man minix-tests tests"}
15 : ${IMG=minix_x86.img}
17 if [ ! -f ${BUILDSH} ]
18 then
19 echo "Please invoke me from the root source dir, where ${BUILDSH} is."
20 exit 1
23 # we create a disk image of about 2 gig's
24 # for alignment reasons, prefer sizes which are multiples of 4096 bytes
25 : ${BOOTXX_SECS=32}
26 : ${ROOT_SIZE=$(( 128*(2**20) - ${BOOTXX_SECS} * 512 ))}
27 : ${HOME_SIZE=$(( 128*(2**20) ))}
28 : ${USR_SIZE=$(( 1792*(2**20) ))}
29 : ${EFI_SIZE=$(( 0 ))}
31 # set up disk creation environment
32 . releasetools/image.defaults
33 . releasetools/image.functions
35 echo "Building work directory..."
36 build_workdir "$SETS"
38 echo "Adding extra files..."
39 workdir_add_hdd_files
41 # add kernels
42 add_link_spec "boot/minix_latest" "minix_default" extra.kernel
43 workdir_add_kernel minix_default
44 workdir_add_kernel minix/$RELEASE_VERSION
46 # add boot.cfg
47 cat >${ROOT_DIR}/boot.cfg <<END_BOOT_CFG
48 menu=Start MINIX 3:load_mods /boot/minix_default/mod*; multiboot /boot/minix_default/kernel rootdevname=c0d0p0
49 menu=Start latest MINIX 3:load_mods /boot/minix_latest/mod*; multiboot /boot/minix_latest/kernel rootdevname=c0d0p0
50 menu=Start latest MINIX 3 in single user mode:load_mods /boot/minix_latest/mod*; multiboot /boot/minix_latest/kernel rootdevname=c0d0p0 bootopts=-s
51 menu=Start MINIX 3 ALIX:load_mods /boot/minix_default/mod*;multiboot /boot/minix_default/kernel rootdevname=c0d0p0 console=tty00 consdev=com0 ata_no_dma=1
52 menu=Edit menu option:edit
53 menu=Drop to boot prompt:prompt
54 clear=1
55 timeout=5
56 default=2
57 menu=Start MINIX 3 ($RELEASE_VERSION):load_mods /boot/minix/$RELEASE_VERSION/mod*; multiboot /boot/minix/$RELEASE_VERSION/kernel rootdevname=c0d0p0
58 END_BOOT_CFG
59 add_file_spec "boot.cfg" extra.boot
61 echo "Bundling packages..."
62 bundle_packages "$BUNDLE_PACKAGES"
64 echo "Creating specification files..."
65 create_input_spec
66 create_protos "usr home"
68 # Clean image
69 if [ -f ${IMG} ] # IMG might be a block device
70 then
71 rm -f ${IMG}
75 # Generate /root, /usr and /home partition images.
77 echo "Writing disk image..."
79 # all sizes are written in 512 byte blocks
80 ROOTSIZEARG="-b $((${ROOT_SIZE} / 512 / 8))"
81 USRSIZEARG="-b $((${USR_SIZE} / 512 / 8))"
82 HOMESIZEARG="-b $((${HOME_SIZE} / 512 / 8))"
84 if [ ${EFI_SIZE} -ge 512 ]
85 then
86 fetch_and_build_grub
88 : ${EFI_DIR=$OBJ/efi}
89 rm -rf ${EFI_DIR} && mkdir -p ${EFI_DIR}/boot/minix_default ${EFI_DIR}/boot/efi
90 create_grub_cfg
91 cp ${MODDIR}/* ${EFI_DIR}/boot/minix_default/
92 cp ${RELEASETOOLSDIR}/grub/grub-core/booti386.efi ${EFI_DIR}/boot/efi
93 cp ${RELEASETOOLSDIR}/grub/grub-core/*.mod ${EFI_DIR}/boot/efi
96 ROOT_START=${BOOTXX_SECS}
97 echo " * ROOT"
98 _ROOT_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${ROOTSIZEARG} -I $((${ROOT_START}*512)) ${IMG} ${WORK_DIR}/proto.root)
99 _ROOT_SIZE=$(($_ROOT_SIZE / 512))
100 USR_START=$((${ROOT_START} + ${_ROOT_SIZE}))
101 echo " * USR"
102 _USR_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${USRSIZEARG} -I $((${USR_START}*512)) ${IMG} ${WORK_DIR}/proto.usr)
103 _USR_SIZE=$(($_USR_SIZE / 512))
104 HOME_START=$((${USR_START} + ${_USR_SIZE}))
105 echo " * HOME"
106 _HOME_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${HOMESIZEARG} -I $((${HOME_START}*512)) ${IMG} ${WORK_DIR}/proto.home)
107 _HOME_SIZE=$(($_HOME_SIZE / 512))
110 # Write the partition table using the natively compiled
111 # minix partition utility
113 if [ ${EFI_SIZE} -ge 512 ]
114 then
115 dd if=/dev/zero bs=${EFI_SIZE} count=1 > ${OBJ}/efi.img
116 EFI_START=$((${HOME_START} + ${_HOME_SIZE}))
117 echo " * EFI"
118 ${CROSS_TOOLS}/nbmakefs -t msdos -s ${EFI_SIZE} -o "F=32,c=1" ${OBJ}/efi.img ${EFI_DIR}
119 dd if=${OBJ}/efi.img >> ${IMG}
120 ${CROSS_TOOLS}/nbpartition -m ${IMG} ${BOOTXX_SECS} 81:${_ROOT_SIZE}* 81:${_USR_SIZE} 81:${_HOME_SIZE} EF:1+
121 else
122 ${CROSS_TOOLS}/nbpartition -m ${IMG} ${BOOTXX_SECS} 81:${_ROOT_SIZE}* 81:${_USR_SIZE} 81:${_HOME_SIZE}
125 ${CROSS_TOOLS}/nbinstallboot -f -m ${ARCH} ${IMG} ${DESTDIR}/usr/mdec/bootxx_minixfs3
127 echo ""
128 echo "Disk image at `pwd`/${IMG}"
129 echo ""
130 echo "To boot this image on kvm using the bootloader:"
131 echo "qemu-system-i386 --enable-kvm -m 256 -hda `pwd`/${IMG}"
132 echo ""
133 echo "To boot this image on kvm:"
134 echo "cd ${MODDIR} && qemu-system-i386 --enable-kvm -m 256M -kernel kernel -append \"rootdevname=c0d0p0\" -initrd \"${mods}\" -hda `pwd`/${IMG}"
135 echo "To boot this image on kvm with EFI (tianocore OVMF):"
136 echo "qemu-system-i386 -L . -bios OVMF-i32.fd -m 256M -drive file=minix_x86.img,if=ide,format=raw"