Boot-to-ramdisk image generation scripts
[minix3.git] / releasetools / x86_hdimage.sh
blob58c758886f5f4374e0cd22eb2ffff99fda818d23
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) ))}
30 # set up disk creation environment
31 . releasetools/image.defaults
32 . releasetools/image.functions
34 echo "Building work directory..."
35 build_workdir "$SETS"
37 echo "Adding extra files..."
38 workdir_add_hdd_files
40 # add kernels
41 add_link_spec "boot/minix_latest" "minix_default" extra.kernel
42 workdir_add_kernel minix_default
43 workdir_add_kernel minix/$RELEASE_VERSION
45 # add boot.cfg
46 cat >${ROOT_DIR}/boot.cfg <<END_BOOT_CFG
47 menu=Start MINIX 3:load_mods /boot/minix_default/mod*; multiboot /boot/minix_default/kernel rootdevname=c0d0p0
48 menu=Start latest MINIX 3:load_mods /boot/minix_latest/mod*; multiboot /boot/minix_latest/kernel rootdevname=c0d0p0
49 menu=Start latest MINIX 3 in single user mode:load_mods /boot/minix_latest/mod*; multiboot /boot/minix_latest/kernel rootdevname=c0d0p0 bootopts=-s
50 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
51 menu=Edit menu option:edit
52 menu=Drop to boot prompt:prompt
53 clear=1
54 timeout=5
55 default=2
56 menu=Start MINIX 3 ($RELEASE_VERSION):load_mods /boot/minix/$RELEASE_VERSION/mod*; multiboot /boot/minix/$RELEASE_VERSION/kernel rootdevname=c0d0p0
57 END_BOOT_CFG
58 add_file_spec "boot.cfg" extra.boot
60 echo "Bundling packages..."
61 bundle_packages "$BUNDLE_PACKAGES"
63 echo "Creating specification files..."
64 create_input_spec
65 create_protos "usr home"
67 # Clean image
68 if [ -f ${IMG} ] # IMG might be a block device
69 then
70 rm -f ${IMG}
74 # Generate /root, /usr and /home partition images.
76 echo "Writing disk image..."
78 # all sizes are written in 512 byte blocks
79 ROOTSIZEARG="-b $((${ROOT_SIZE} / 512 / 8))"
80 USRSIZEARG="-b $((${USR_SIZE} / 512 / 8))"
81 HOMESIZEARG="-b $((${HOME_SIZE} / 512 / 8))"
83 ROOT_START=${BOOTXX_SECS}
84 echo " * ROOT"
85 _ROOT_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${ROOTSIZEARG} -I $((${ROOT_START}*512)) ${IMG} ${WORK_DIR}/proto.root)
86 _ROOT_SIZE=$(($_ROOT_SIZE / 512))
87 USR_START=$((${ROOT_START} + ${_ROOT_SIZE}))
88 echo " * USR"
89 _USR_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${USRSIZEARG} -I $((${USR_START}*512)) ${IMG} ${WORK_DIR}/proto.usr)
90 _USR_SIZE=$(($_USR_SIZE / 512))
91 HOME_START=$((${USR_START} + ${_USR_SIZE}))
92 echo " * HOME"
93 _HOME_SIZE=$(${CROSS_TOOLS}/nbmkfs.mfs -d ${HOMESIZEARG} -I $((${HOME_START}*512)) ${IMG} ${WORK_DIR}/proto.home)
94 _HOME_SIZE=$(($_HOME_SIZE / 512))
97 # Write the partition table using the natively compiled
98 # minix partition utility
100 ${CROSS_TOOLS}/nbpartition -m ${IMG} ${BOOTXX_SECS} 81:${_ROOT_SIZE} 81:${_USR_SIZE} 81:${_HOME_SIZE}
101 ${CROSS_TOOLS}/nbinstallboot -f -m ${ARCH} ${IMG} ${DESTDIR}/usr/mdec/bootxx_minixfs3
103 echo ""
104 echo "Disk image at `pwd`/${IMG}"
105 echo ""
106 echo "To boot this image on kvm using the bootloader:"
107 echo "qemu-system-i386 --enable-kvm -m 256 -hda `pwd`/${IMG}"
108 echo ""
109 echo "To boot this image on kvm:"
110 echo "cd ${MODDIR} && qemu-system-i386 --enable-kvm -m 256M -kernel kernel -append \"rootdevname=c0d0p0\" -initrd \"${mods}\" -hda `pwd`/${IMG}"