xref: /minix/releasetools/x86_hdimage.sh (revision 6c8f7fc3)
1#!/bin/bash
2set -e
3
4: ${ARCH=i386}
5: ${OBJ=../obj.${ARCH}}
6: ${CROSS_TOOLS=${OBJ}/"tooldir.`uname -s`-`uname -r`-`uname -m`"/bin}
7: ${CROSS_PREFIX=${CROSS_TOOLS}/i586-elf32-minix-}
8: ${JOBS=1}
9: ${DESTDIR=${OBJ}/destdir.$ARCH}
10: ${FSTAB=${DESTDIR}/etc/fstab}
11: ${BUILDVARS=}
12: ${BUILDSH=build.sh}
13
14# Where the kernel & boot modules will be
15MODDIR=${DESTDIR}/multiboot
16
17#
18# Directory where to store temporary file system images
19#
20: ${IMG_DIR=${OBJ}/img}
21
22CDFILES=${IMG_DIR}/cd
23
24if [ ! -f ${BUILDSH} ]
25then
26	echo "Please invoke me from the root source dir, where ${BUILDSH} is."
27	exit 1
28fi
29
30export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:${PATH}
31
32while getopts "i" c
33do
34	case "$c" in
35		i)	: ${IMG=minix_x86.iso}
36			ISOMODE=1
37			;;
38	esac
39done
40
41: ${IMG=minix_x86.img}
42
43#
44# Artifacts from this script are stored in the IMG_DIR
45#
46rm -rf ${IMG_DIR} ${IMG}
47mkdir -p ${IMG_DIR} ${CDFILES}
48
49#
50# Call build.sh using a sloppy file list so we don't need to remove the installed /etc/fstag
51#
52export CPPFLAGS=${FLAG}
53sh ${BUILDSH} -V SLOPPY_FLIST=yes -V MKBINUTILS=yes -V MKGCCCMDS=yes -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u distribution
54
55if [ "x${ISOMODE}" = "x1" ]
56then
57	cp ${DESTDIR}/usr/mdec/boot_monitor ${CDFILES}/boot
58	cp ${MODDIR}/* ${CDFILES}/
59	. ./releasetools/release.functions
60	cd_root_changes	# uses $CDFILES and writes $CDFILES/boot.cfg
61	# start the image off with the iso image; reduce root size to reserve
62	${CROSS_TOOLS}/nbwriteisofs -s0x0 -l MINIX -B ${DESTDIR}/usr/mdec/bootxx_cd9660 -n ${CDFILES} ${IMG}
63	ISO_SIZE=$((`stat -c %s ${IMG}` / 512))
64else
65	# just make an empty iso partition
66	ISO_SIZE=8
67fi
68
69#
70# create a fstab entry in /etc this is normally done during the
71# setup phase on x86
72#
73cat >${FSTAB} <<END_FSTAB
74/dev/c0d0p2   /usr    mfs     rw                      0       2
75/dev/c0d0p3   /home   mfs     rw                      0       2
76END_FSTAB
77
78rm -f ${DESTDIR}/SETS.*
79
80${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${DESTDIR} ${DESTDIR}/etc/master.passwd
81
82#
83# make the different file system. this part is *also* hacky. We first convert
84# the METALOG.sanitised using mtree into a input METALOG containing uids and
85# gids.
86# After that we do some magic processing to add device nodes (also missing from METALOG)
87# and convert the METALOG into a proto file that can be used by mkfs.mfs
88#
89echo "creating the file systems"
90
91#
92# read METALOG and use mtree to convert the user and group names into uid and gids
93# FIX put "input somewhere clean"
94#
95cat ${DESTDIR}/METALOG.sanitised | ${CROSS_TOOLS}/nbmtree -N ${DESTDIR}/etc -C -K device > ${IMG_DIR}/input
96
97# add fstab
98echo "./etc/fstab type=file uid=0 gid=0 mode=0755 size=747 time=1365060731.000000000" >> ${IMG_DIR}/input
99
100# fill root.img (skipping /usr entries while keeping the /usr directory)
101cat ${IMG_DIR}/input  | grep -v "^./usr/" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR} -o ${IMG_DIR}/root.proto
102
103#
104# Create proto files for /usr and /home using toproto.
105#
106cat ${IMG_DIR}/input  | grep  "^\./usr/\|^. "  | sed "s,\./usr,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/usr -o ${IMG_DIR}/usr.proto
107cat ${IMG_DIR}/input  | grep  "^\./home/\|^. "  | sed "s,\./home,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/home -o ${IMG_DIR}/home.proto
108
109#
110# This script creates a bootable image and should at some point in the future
111# be replaced by makefs.
112#
113# All sized are written in 512 byte blocks
114#
115# we create a disk image of about 2 gig's
116# for alignment reasons, prefer sizes which are multiples of 4096 bytes
117#
118: ${ROOT_SIZE=$((  64*(2**20) / 512))}
119: ${HOME_SIZE=$(( 128*(2**20) / 512))}
120: ${USR_SIZE=$(( 1536*(2**20) / 512))}
121
122if [ "x${ISOMODE}" = "x1" ]
123then
124	# In iso mode, make all FSes fit (i.e. as small as possible), but
125	# leave some space on /
126	ROOTSIZEARG="-x 5"
127else
128	# In hd image mode, FSes have fixed sizes
129	ROOTSIZEARG="-b $((${ROOT_SIZE} / 8))"
130	USRSIZEARG="-b $((${USR_SIZE} / 8))"
131	HOMESIZEARG="-b $((${HOME_SIZE} / 8))"
132fi
133
134echo "Writing Minix filesystem images"
135
136#
137# Do some math to determine the start addresses of the partitions.
138# Ensure the start of the partitions are always aligned, the end will
139# always be as we assume the sizes are multiples of 4096 bytes, which
140# is always true as soon as you have an integer multiple of 1MB.
141#
142ROOT_START=${ISO_SIZE}
143
144echo " - ROOT"
145ROOT_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $ROOTSIZEARG -I $(($ROOT_START*512)) ${IMG} ${IMG_DIR}/root.proto`/512))
146USR_START=$((${ROOT_START} + ${ROOT_SIZE}))
147echo " - USR"
148USR_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $USRSIZEARG  -I $(($USR_START*512))  ${IMG} ${IMG_DIR}/usr.proto`/512))
149HOME_START=$((${USR_START} + $USR_SIZE))
150echo " - HOME"
151HOME_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $HOMESIZEARG -I $(($HOME_START*512)) ${IMG} ${IMG_DIR}/home.proto`/512))
152
153${CROSS_TOOLS}/nbpartition -m ${IMG} 0 81:${ISO_SIZE} 81:${ROOT_SIZE} 81:${USR_SIZE} 81:${HOME_SIZE}
154
155mods="`( cd ${MODDIR}; echo mod* | tr ' ' ',' )`"
156if [ "x${ISOMODE}" = "x1" ]
157then
158	echo "CD image at `pwd`/${IMG}"
159else
160	echo "To boot this image on kvm:"
161	echo "cd ${MODDIR} && kvm -serial stdio -kernel kernel -append \"console=tty00 rootdevname=c0d0p1\" -initrd \"${mods}\" -hda `pwd`/${IMG}"
162fi
163