-
Notifications
You must be signed in to change notification settings - Fork 1
/
mksetupliveimage.sh
146 lines (128 loc) · 3.72 KB
/
mksetupliveimage.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#! /bin/sh
#
# Copyright (c) 2012, 2013, 2014, 2015, 2019 Izumi Tsutsui.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
if [ -f REVISION ]; then
. ./REVISION
fi
if [ "${REVISION}"X = "X" ]; then
REVISION=`date +%C%y%m%d`
fi
err()
{
echo $1 failed!
exit 1
}
# source and target
INSTSH=inst.sh
FILESDIR=liveimagefiles
if [ "${OBJDIR}"X = "X" ]; then
OBJDIR=.
fi
WORKDIR=${OBJDIR}/work.setupliveimage
IMAGE=${WORKDIR}/setupliveimage-${REVISION}.fs
#
# tooldir settings
#
MACHINE_ARCH=i386
MACHINE=i386
#NETBSDSRCDIR=/usr/src
#TOOLDIR=/usr/tools/${MACHINE_ARCH}
if [ -z ${NETBSDSRCDIR} ]; then
NETBSDSRCDIR=/usr/src
fi
if [ -z ${TOOLDIR} ]; then
_HOST_OSNAME=`uname -s`
_HOST_OSREL=`uname -r`
_HOST_ARCH=`uname -p 2> /dev/null || uname -m`
TOOLDIRNAME=tooldir.${_HOST_OSNAME}-${_HOST_OSREL}-${_HOST_ARCH}
TOOLDIR=${NETBSDSRCDIR}/obj.${MACHINE}/${TOOLDIRNAME}
if [ ! -d ${TOOLDIR} ]; then
TOOLDIR=${NETBSDSRCDIR}/${TOOLDIRNAME}
fi
fi
if [ ! -d ${TOOLDIR} ]; then
echo 'set TOOLDIR first'; exit 1
fi
if [ ! -x ${TOOLDIR}/bin/nbmake-${MACHINE} ]; then
echo 'build tools in ${TOOLDIR} first'; exit 1
fi
# tools binaries
TOOL_DISKLABEL=${TOOLDIR}/bin/nbdisklabel
TOOL_MAKEFS=${TOOLDIR}/bin/nbmakefs
# host binaries
MKDIR=mkdir
RM=rm
#
# target image size settings
#
FSMB=1500
FSSECTORS=$((${FSMB} * 1024 * 1024 / 512))
FSSIZE=$((${FSSECTORS} * 512))
FSOFFSET=0
HEADS=64
SECTORS=32
CYLINDERS=$((${FSSECTORS} / ( ${HEADS} * ${SECTORS} ) ))
# makefs(8) parameters
TARGET_ENDIAN=le
BLOCKSIZE=16384
FRAGSIZE=4096
DENSITY=8192
echo Removing ${WORKDIR}...
${RM} -rf ${WORKDIR}
${MKDIR} -p ${WORKDIR}
echo Creating rootfs...
${TOOL_MAKEFS} -M ${FSSIZE} -m ${FSSIZE} \
-B ${TARGET_ENDIAN} \
-o bsize=${BLOCKSIZE},fsize=${FRAGSIZE},density=${DENSITY} \
${IMAGE} ${FILESDIR} \
|| err ${TOOL_MAKEFS}
echo Creating disklabel...
LABELPROTO=${WORKDIR}/labelproto
cat > ${LABELPROTO} <<EOF
type: ESDI
disk: SetupLiveImage
label:
flags:
bytes/sector: 512
sectors/track: ${SECTORS}
tracks/cylinder: ${HEADS}
sectors/cylinder: $((${HEADS} * ${SECTORS}))
cylinders: ${CYLINDERS}
total sectors: ${FSSECTORS}
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0 # microseconds
track-to-track seek: 0 # microseconds
drivedata: 0
8 partitions:
# size offset fstype [fsize bsize cpg/sgs]
a: ${FSSECTORS} ${FSOFFSET} 4.2BSD ${FRAGSIZE} ${BLOCKSIZE} 128
c: ${FSSECTORS} ${FSOFFSET} unused 0 0
EOF
${TOOL_DISKLABEL} -R -F -M ${MACHINE} ${IMAGE} ${LABELPROTO} \
|| err ${TOOL_DISKLABEL}
${RM} -f ${LABELPROTO}
echo Creating image \"${IMAGE}\" complete.