custom message type for VM_INFO
[minix3.git] / releasetools / x86_hdimage.sh
blob84759eee8e7e8afb5a124d6041d2dff5c7a65f5c
1 #!/bin/bash
2 set -e
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 : ${CREATE_IMAGE_ONLY=0}
15 # Where the kernel & boot modules will be
16 MODDIR=${DESTDIR}/multiboot
19 # Directory where to store temporary file system images
21 : ${IMG_DIR=${OBJ}/img}
23 CDFILES=${IMG_DIR}/cd
25 if [ ! -f ${BUILDSH} ]
26 then
27 echo "Please invoke me from the root source dir, where ${BUILDSH} is."
28 exit 1
31 export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:${PATH}
33 while getopts "i" c
35 case "$c" in
36 i) : ${IMG=minix_x86.iso}
37 ISOMODE=1
39 esac
40 done
42 : ${IMG=minix_x86.img}
43 : ${RC=minix_x86.rc}
46 # Are we going to build the minix sources?
49 if [ ${CREATE_IMAGE_ONLY} -eq 1 ]
50 then
51 if [ ! -d ${DESTDIR} ]
52 then
53 echo "Minix source code does'nt appear to have been built."
54 echo "Please try with \$CREATE_IMAGE_ONLY set to 0."
55 exit 1
60 # Artifacts from this script are stored in the IMG_DIR
62 rm -rf ${IMG_DIR} ${IMG}
63 mkdir -p ${IMG_DIR} ${CDFILES}
65 if [ ${CREATE_IMAGE_ONLY} -eq 0 ]
66 then
67 echo "Going to build Minix source code..."
69 # Remove the generated files to allow us call build.sh without '-V SLOPPY_FLIST=yes'.
71 rm -f ${FSTAB}
74 # Now start the build.
76 export CPPFLAGS=${FLAG}
77 sh ${BUILDSH} -j ${JOBS} -m ${ARCH} -O ${OBJ} -D ${DESTDIR} ${BUILDVARS} -U -u distribution
81 if [ "x${ISOMODE}" = "x1" ]
82 then
83 cp ${DESTDIR}/usr/mdec/boot_monitor ${CDFILES}/boot
84 cp ${MODDIR}/* ${CDFILES}/
85 . ./releasetools/release.functions
86 cd_root_changes # uses $CDFILES and writes $CDFILES/boot.cfg
87 # start the image off with the iso image; reduce root size to reserve
88 ${CROSS_TOOLS}/nbwriteisofs -s0x0 -l MINIX -B ${DESTDIR}/usr/mdec/bootxx_cd9660 -n ${CDFILES} ${IMG}
89 ISO_SIZE=$((`${CROSS_TOOLS}/nbstat -f %z ${IMG}` / 512))
90 else
91 # just make an empty iso partition
92 ISO_SIZE=8
96 # create a fstab entry in /etc this is normally done during the
97 # setup phase on x86
99 cat >${FSTAB} <<END_FSTAB
100 /dev/c0d0p2 /usr mfs rw 0 2
101 /dev/c0d0p3 /home mfs rw 0 2
102 none /sys devman rw,rslabel=devman 0 0
103 END_FSTAB
105 rm -f ${DESTDIR}/SETS.*
107 ${CROSS_TOOLS}/nbpwd_mkdb -V 0 -p -d ${DESTDIR} ${DESTDIR}/etc/master.passwd
110 # make the different file system. this part is *also* hacky. We first convert
111 # the METALOG.sanitised using mtree into a input METALOG containing uids and
112 # gids.
113 # After that we do some magic processing to add device nodes (also missing from METALOG)
114 # and convert the METALOG into a proto file that can be used by mkfs.mfs
116 echo "creating the file systems"
119 # read METALOG and use mtree to convert the user and group names into uid and gids
120 # FIX put "input somewhere clean"
122 cat ${DESTDIR}/METALOG.sanitised | ${CROSS_TOOLS}/nbmtree -N ${DESTDIR}/etc -C -K device > ${IMG_DIR}/input
124 # add rc (if any)
125 if [ -f ${RC} ]; then
126 cp ${RC} ${DESTDIR}/usr/etc/rc.local
127 echo "./usr/etc/rc.local type=file uid=0 gid=0 mode=0644" >> ${IMG_DIR}/input
130 # add fstab
131 echo "./etc/fstab type=file uid=0 gid=0 mode=0755 size=747 time=1365060731.000000000" >> ${IMG_DIR}/input
133 # fill root.img (skipping /usr entries while keeping the /usr directory)
134 cat ${IMG_DIR}/input | grep -v "^./usr/" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR} -o ${IMG_DIR}/root.proto
137 # Create proto files for /usr and /home using toproto.
139 cat ${IMG_DIR}/input | grep "^\./usr/\|^. " | sed "s,\./usr,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/usr -o ${IMG_DIR}/usr.proto
140 cat ${IMG_DIR}/input | grep "^\./home/\|^. " | sed "s,\./home,\.,g" | ${CROSS_TOOLS}/nbtoproto -b ${DESTDIR}/home -o ${IMG_DIR}/home.proto
143 # This script creates a bootable image and should at some point in the future
144 # be replaced by makefs.
146 # All sized are written in 512 byte blocks
148 # we create a disk image of about 2 gig's
149 # for alignment reasons, prefer sizes which are multiples of 4096 bytes
151 : ${ROOT_SIZE=$(( 64*(2**20) / 512))}
152 : ${HOME_SIZE=$(( 128*(2**20) / 512))}
153 : ${USR_SIZE=$(( 1536*(2**20) / 512))}
155 if [ "x${ISOMODE}" = "x1" ]
156 then
157 # In iso mode, make all FSes fit (i.e. as small as possible), but
158 # leave some space on /
159 ROOTSIZEARG="-x 5"
160 else
161 # In hd image mode, FSes have fixed sizes
162 ROOTSIZEARG="-b $((${ROOT_SIZE} / 8))"
163 USRSIZEARG="-b $((${USR_SIZE} / 8))"
164 HOMESIZEARG="-b $((${HOME_SIZE} / 8))"
167 echo "Writing Minix filesystem images"
170 # Do some math to determine the start addresses of the partitions.
171 # Ensure the start of the partitions are always aligned, the end will
172 # always be as we assume the sizes are multiples of 4096 bytes, which
173 # is always true as soon as you have an integer multiple of 1MB.
175 ROOT_START=${ISO_SIZE}
177 echo " - ROOT"
178 ROOT_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $ROOTSIZEARG -I $(($ROOT_START*512)) ${IMG} ${IMG_DIR}/root.proto`/512))
179 USR_START=$((${ROOT_START} + ${ROOT_SIZE}))
180 echo " - USR"
181 USR_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $USRSIZEARG -I $(($USR_START*512)) ${IMG} ${IMG_DIR}/usr.proto`/512))
182 HOME_START=$((${USR_START} + $USR_SIZE))
183 echo " - HOME"
184 HOME_SIZE=$((`${CROSS_TOOLS}/nbmkfs.mfs -d $HOMESIZEARG -I $(($HOME_START*512)) ${IMG} ${IMG_DIR}/home.proto`/512))
186 ${CROSS_TOOLS}/nbpartition -m ${IMG} 0 81:${ISO_SIZE} 81:${ROOT_SIZE} 81:${USR_SIZE} 81:${HOME_SIZE}
188 mods="`( cd ${MODDIR}; echo mod* | tr ' ' ',' )`"
189 if [ "x${ISOMODE}" = "x1" ]
190 then
191 echo "CD image at `pwd`/${IMG}"
192 else
193 echo "To boot this image on kvm:"
194 echo "cd ${MODDIR} && kvm -display none -serial stdio -kernel kernel -append \"console=tty00 rootdevname=c0d0p1\" -initrd \"${mods}\" -hda `pwd`/${IMG}"