-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathastlinux-makeimage
More file actions
executable file
·272 lines (213 loc) · 5.66 KB
/
Copy pathastlinux-makeimage
File metadata and controls
executable file
·272 lines (213 loc) · 5.66 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/bash
#
# astlinux-makeimage [imagesize in MB] [dos partition size in MB] [ASTURW partition size in MB]
#
# astlinux-makeimage -z 256 256 0
#
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
HOST_BIN="./output/host/usr/sbin"
REQUIRED_HOST_CMDS="fdisk"
REQUIRED_CMDS="which sudo mkdosfs mkfs losetup gzip"
RUNNIX_VER="$(awk -F'=' '/^RUNNIX_VER/ { print $2; exit }' boot/runnix/runnix.mk)"
RUNNIX_DIR="output/build/runnix-${RUNNIX_VER// /}"
RUNFS_DIR="output/build/runfs"
#
# put whatever edits you need to make to the VFAT filesystem here.
#
# it will be run with that as the current working directory.
#
editConf()
{
# stuff here... example:
# sed -i -r -e '/^ append /{s/,19200n8/,38400n8/}' syslinux.cfg
return 0
}
ASTRW_FORMAT=
DUMP_PARTITIONS=
GZIP=
while [ $# -ge 1 ]; do
case "$1" in
-A)
ASTRW_FORMAT=1
;;
-p)
DUMP_PARTITIONS=1
;;
-z)
GZIP=1
;;
*)
break
;;
esac
shift
done
if [ $# -ne 3 ]; then
echo "Usage: astlinux-makeimage [imagesize in MB] [dos partition size in MB] [ASTURW partition size in MB]" >&2
exit 1
fi
for i in $REQUIRED_HOST_CMDS; do
if [ ! -x "$HOST_BIN/$i" ]; then
make host-$i
fi
done
error=0
for i in $REQUIRED_HOST_CMDS; do
if [ ! -x "$HOST_BIN/$i" ]; then
error=1
echo "astlinux-makeimage: Required HOST command \"$i\" is missing." >&2
fi
done
for i in $REQUIRED_CMDS; do
if ! which $i >/dev/null 2>&1; then
error=1
echo "astlinux-makeimage: Required command \"$i\" is missing in your build environment." >&2
if [ "$i" = "which" ]; then # no use proceeding
break
fi
fi
done
if [ $error -ne 0 ]; then
echo "Missing Required Command(s)." >&2
exit 1
fi
DISK_SIZE=$1
DOS_SIZE=$2
AST_SIZE=$3
if [ $(($DOS_SIZE + $AST_SIZE)) -gt $DISK_SIZE ]; then
echo "astlinux-makeimage: Partition sizes exceed disk size." >&2
exit 1
fi
if [ ! -f output/target/etc/rc ]; then
echo "It doesn't look like you have built AstLinux yet.
You need to run ./scripts/build first. For more help please visit
https://www.astlinux-project.org/
" >&2
exit 1
fi
if [ ! -d $RUNNIX_DIR ] || [ ! -d $RUNFS_DIR ]; then
echo "astlinux-makeimage: This image wasn't built with RUNNIX enabled." >&2
exit 1
fi
ASTVER="$(cat ${RUNFS_DIR}/os/ver)"
if [ -z "$ASTVER" ]; then
echo "astlinux-makeimage: missing runfs version file." >&2
exit 1
fi
if ! sudo /bin/true; then
echo "astlinux-makeimage: You need to be a sudo group member to run this script" >&2
exit 1
fi
rm -f runnix.img bximage.out
# dd if=/dev/zero of=runnix.img bs=1024 count=$(($DISK_SIZE*1024))
./scripts/bximage -q -hd -mode=flat -size=$DISK_SIZE runnix.img > bximage.out
LOOP0="$(sudo losetup -f --show runnix.img)"
if [ -z "$LOOP0" ]; then
exit 1
fi
CYL=`awk -F\= '/^ cyl=/ {print $2}' bximage.out`
HEADS=`awk -F\= '/^ heads=/ {print $2}' bximage.out`
SECTORS=`awk -F\= '/^ sectors per track=/ {print $2}' bximage.out`
rm -f bximage.out
# bximage insists on H=16... but most CF is H=64/S=63
# Make sure CYL is a multiple of 4
if [ $HEADS -eq 16 ] && [ $(($CYL % 4)) -eq 0 ]; then
CYL=$(($CYL / 4))
HEADS=$(($HEADS * 4))
fi
if [ -z "$CYL" -o -z "$HEADS" -o -z "$SECTORS" ]; then
echo "Unable to parse geometry; automation failed."
sudo losetup -d $LOOP0
exit 1
fi
echo "Disk Geometry: CYL=$CYL HEADS=$HEADS SECTORS=$SECTORS"
( if [ $AST_SIZE -gt 0 ]; then
echo -e "n\np\n1\n\n+${DOS_SIZE}M\nt\n6\na"
echo -e "n\np\n2\n\n+${AST_SIZE}M\nt\n2\n83"
elif [ $DOS_SIZE -lt $DISK_SIZE ]; then
echo -e "n\np\n1\n\n+${DOS_SIZE}M\nt\n6\na"
else
echo -e "n\np\n1\n\n\nt\n6\na"
fi
echo "w"
) | sudo $HOST_BIN/fdisk -c=dos -u=cylinders -C $CYL -H $HEADS -S $SECTORS $LOOP0
temp="$LOOP0"
PREFIXLEN=${#temp}
PREFIX="^${temp//\//\\/}"
# need to filter out bootable marker ('*') so it doesn't show up as $2
eval $(sudo $HOST_BIN/fdisk -c=dos -u=sectors -l $LOOP0 | tr '*' ' ' | awk "/${PREFIX}/ { printf \"%s=%s\\n\", substr(\$1, $PREFIXLEN+1), \$2; }")
sudo losetup -d $LOOP0
if [ -z "$p1" -o \( $AST_SIZE -gt 0 -a -z "$p2" \) ]; then
echo "Couldn't extract partition offsets." >&2
exit 1
fi
## Work around "Resource temporarily unavailable" errors
sleep 5
LOOP1="$(sudo losetup -f --show -o $(($p1*512)) runnix.img)"
if [ -z "$LOOP1" ]; then
sleep 10
LOOP1="$(sudo losetup -f --show -o $(($p1*512)) runnix.img)"
if [ -z "$LOOP1" ]; then
exit 1
fi
fi
LABEL="RUNNIX"
sudo mkdosfs -F 16 -n $LABEL $LOOP1
echo "
##
## AstLinux Image Release: Version = \"$ASTVER\"
##
"
# install syslinux
(
cd ${RUNNIX_DIR}
sudo ./syslinux --install $LOOP1
)
sudo mkdir -p /mnt/runnix
sudo mount -t vfat $LOOP1 /mnt/runnix
sudo cp -r -P --preserve=mode,timestamps ${RUNFS_DIR}/. /mnt/runnix
# run this in a subshell, since we change subdirectory
(
cd /mnt/runnix
editConf
)
# Some systems take a second or two before /mnt/runnix is not busy
cnt=5
while [ $cnt -gt 0 ]; do
cnt=$((cnt - 1))
sleep 2
if sudo umount /mnt/runnix; then
echo "/mnt/runnix is un-mounted"
break
fi
done
sudo rmdir /mnt/runnix
sudo losetup -d $LOOP1
# allow an argument of 0 to skip creating this partition.
if [ $AST_SIZE -gt 0 -a -n "$ASTRW_FORMAT" ]; then
LOOP2="$(sudo losetup -f --show -o $(($p2*512)) runnix.img)"
if [ -z "$LOOP2" ]; then
exit 1
fi
sudo mkfs -t ext2 -O extra_isize -L ASTURW $LOOP2
sudo losetup -d $LOOP2
fi
LOOP0="$(sudo losetup -f --show runnix.img)"
if [ -z "$LOOP0" ]; then
exit 1
fi
# copy the master boot record
(
cd ${RUNNIX_DIR}
sudo bash -c "cat mbr.bin > $LOOP0"
)
if [ -n "$DUMP_PARTITIONS" ]; then
sudo $HOST_BIN/fdisk -c=dos -u=sectors -l $LOOP0
fi
sudo losetup -d $LOOP0
IMG_NAME="$ASTVER.img"
mv -f runnix.img $IMG_NAME
if [ -n "$GZIP" ]; then
gzip -f $IMG_NAME
fi
echo "Done."