5 # This script creates a bootable image and should at some point in the future
6 # be replaced by makefs.
10 : ${OBJ=../obj.${ARCH}}
11 : ${CROSS_TOOLS=${OBJ}/"tooldir.`uname -s`-`uname -r`-`uname -m`"/bin}
12 : ${CROSS_PREFIX=${CROSS_TOOLS}/i586-elf32-minix-}
14 : ${DESTDIR=${OBJ}/destdir.$ARCH}
15 : ${RELEASETOOLSDIR=./releasetools/}
16 : ${FSTAB=${DESTDIR}/etc/fstab}
19 : ${CREATE_IMAGE_ONLY=0}
23 # Directory where to store temporary file system images
25 : ${IMG_DIR=${OBJ}/img}
26 : ${CDFILES=${IMG_DIR}/cd}
28 # All sized are written in 512 byte blocks
30 # we create a disk image of about 2 gig's
31 # for alignment reasons, prefer sizes which are multiples of 4096 bytes
33 : ${ROOT_SIZE=$(( 64*(2**20) / 512))}
34 : ${HOME_SIZE=$(( 128*(2**20) / 512))}
35 : ${USR_SIZE=$(( 1792*(2**20) / 512))}
38 # Do some math to determine the start addresses of the partitions.
39 # Don't leave holes so the 'partition' invocation later is easy.
43 # Where the kernel & boot modules will be
44 MODDIR
=${DESTDIR}/boot
/minix
/.temp
49 i
) : ${IMG=minix_x86.iso}
55 : ${IMG=minix_x86.img}
57 if [ "x${ISOMODE}" = "x1" ]
59 # In iso mode, make all FSes fit (i.e. as small as possible), but
60 # leave some space on /
63 # In hd image mode, FSes have fixed sizes
64 ROOTSIZEARG
="-b $((${ROOT_SIZE} / 8))"
65 USRSIZEARG
="-b $((${USR_SIZE} / 8))"
66 HOMESIZEARG
="-b $((${HOME_SIZE} / 8))"
69 if [ ! -f ${BUILDSH} ]
71 echo "Please invoke me from the root source dir, where ${BUILDSH} is."
75 export PATH
=/bin
:/sbin
:/usr
/bin
:/usr
/sbin
:/usr
/local
/bin
:/usr
/local
/sbin
:${PATH}
78 # Are we going to build the minix sources?
81 if [ ${CREATE_IMAGE_ONLY} -eq 1 ]
83 if [ ! -d ${DESTDIR} ]
85 echo "Minix source code does'nt appear to have been built."
86 echo "Please try with \$CREATE_IMAGE_ONLY set to 0."
92 # Artifacts from this script are stored in the IMG_DIR
94 rm -rf ${IMG_DIR} ${IMG}
95 mkdir
-p ${IMG_DIR} ${CDFILES}
97 if [ ${CREATE_IMAGE_ONLY} -eq 0 ]
99 echo "Going to build Minix source code..."
101 # Remove the generated files to allow us call build.sh without '-V SLOPPY_FLIST=yes'.
106 # Now start the build.
108 sh
${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u distribution
113 # create a fstab entry in /etc this is normally done during the
116 cat >${FSTAB} <<END_FSTAB
117 /dev/c0d0p2 /usr mfs rw 0 2
118 /dev/c0d0p3 /home mfs rw 0 2
119 none /sys devman rw,rslabel=devman 0 0
122 rm -f ${DESTDIR}/SETS.
*
124 ${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${DESTDIR} ${DESTDIR}/etc
/master.passwd
127 # make the different file system. this part is *also* hacky. We first convert
128 # the METALOG.sanitised using mtree into a input METALOG containing uids and
130 # After that we do some magic processing to add device nodes (also missing from METALOG)
131 # and convert the METALOG into a proto file that can be used by mkfs.mfs
133 echo "Creating the file systems"
136 # read METALOG and use mtree to convert the user and group names into uid and gids
137 # FIX put "input somewhere clean"
139 cat ${DESTDIR}/METALOG.sanitised | ${CROSS_TOOLS}/nbmtree -N ${DESTDIR}/etc -C -K device > ${IMG_DIR}/input
142 if [ -f ${RC} ]; then
143 cp ${RC} ${DESTDIR}/usr
/etc
/rc.
local
144 echo "./usr/etc/rc.local type=file uid=0 gid=0 mode=0644" >> ${IMG_DIR}/input
148 echo "./etc/fstab type=file uid=0 gid=0 mode=0755 size=747 time=1365060731.000000000" >> ${IMG_DIR}/input
150 # fill root.img (skipping /usr entries while keeping the /usr directory)
151 cat ${IMG_DIR}/input | grep -v "^./usr/" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR} -o ${IMG_DIR}/root.proto
154 # Create proto files for /usr and /home using toproto.
156 cat ${IMG_DIR}/input | grep "^\./usr/\|^. " | sed "s,\./usr,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/usr -o ${IMG_DIR}/usr.proto
157 cat ${IMG_DIR}/input | grep "^\./home/\|^. " | sed "s,\./home,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/home -o ${IMG_DIR}/home.proto
159 if [ "x${ISOMODE}" = "x1" ]
161 cp ${DESTDIR}/usr
/mdec
/boot_monitor
${CDFILES}/boot
162 cp ${MODDIR}/* ${CDFILES}/
163 .
${RELEASETOOLSDIR}/release.functions
164 cd_root_changes
# uses $CDFILES and writes $CDFILES/boot.cfg
165 # start the image off with the iso image; reduce root size to reserve
166 ${CROSS_TOOLS}/nbwriteisofs -s0x0 -l MINIX -B ${DESTDIR}/usr/mdec/bootxx_cd9660 -n ${CDFILES} ${IMG}
167 ISO_SIZE
=$
((`${CROSS_TOOLS}/nbstat -f %z ${IMG}` / 512))
169 # just make an empty iso partition
174 # Generate /root, /usr and /home partition images.
176 echo "Writing Minix filesystem images"
177 ROOT_START
=${ISO_SIZE}
179 _ROOT_SIZE
=$
((`${CROSS_TOOLS}/nbmkfs.mfs -d ${ROOTSIZEARG} -I $((${ROOT_START}*512)) ${IMG} ${IMG_DIR}/root.proto`/512))
180 USR_START
=$
((${ROOT_START} + ${_ROOT_SIZE}))
182 _USR_SIZE
=$
((`${CROSS_TOOLS}/nbmkfs.mfs -d ${USRSIZEARG} -I $((${USR_START}*512)) ${IMG} ${IMG_DIR}/usr.proto`/512))
183 HOME_START
=$
((${USR_START} + ${_USR_SIZE}))
185 _HOME_SIZE
=$
((`${CROSS_TOOLS}/nbmkfs.mfs -d ${HOMESIZEARG} -I $((${HOME_START}*512)) ${IMG} ${IMG_DIR}/home.proto`/512))
188 # Write the partition table using the natively compiled
189 # minix partition utility
191 ${CROSS_TOOLS}/nbpartition -m ${IMG} 0 81:${ISO_SIZE} \
192 81:${_ROOT_SIZE} 81:${_USR_SIZE} 81:${_HOME_SIZE}
194 mods
="`( cd ${MODDIR}; echo mod* | tr ' ' ',' )`"
195 if [ "x${ISOMODE}" = "x1" ]
197 echo "CD image at `pwd`/${IMG}"
199 echo "To boot this image on kvm:"
200 echo "cd ${MODDIR} && qemu-system-i386 -display none -serial stdio -kernel kernel -append \"console=tty00 rootdevname=c0d0p1\" -initrd \"${mods}\" -hda `pwd`/${IMG} --enable-kvm"