install.md revision 1.26 1 # $NetBSD: install.md,v 1.26 2022/05/28 21:57:39 andvar Exp $
2 #
3 #
4 # Copyright (c) 1996 The NetBSD Foundation, Inc.
5 # All rights reserved.
6 #
7 # This code is derived from software contributed to The NetBSD Foundation
8 # by Jason R. Thorpe.
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
12 # are met:
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30 #
31
32 #
33 # machine dependent section of installation/upgrade script.
34 #
35
36 # Machine-dependent install sets
37 MDSETS="kern xbase xcomp xfont xserver"
38
39 if [ "$MODE" = upgrade ]; then
40 RELOCATED_FILES_13="${RELOCATED_FILES_13} /usr/sbin/installboot /usr/mdec/installboot"
41 fi
42
43 md_set_term() {
44 if [ ! -z "$TERM" ]; then
45 return
46 fi
47 echo -n "Specify terminal type [vt100]: "
48 getresp "vt100"
49 TERM="$resp"
50 export TERM
51 }
52
53 md_makerootwritable() {
54 # Was: do_mfs_mount "/tmp" "2048"
55 # /tmp is the mount point
56 # 2048 is the size in DEV_BIZE blocks
57
58 umount /tmp > /dev/null 2>&1
59 if ! mount_mfs -s 2048 swap /tmp ; then
60 cat << \__mfs_failed_1
61
62 FATAL ERROR: Can't mount the memory filesystem.
63
64 __mfs_failed_1
65 exit
66 fi
67
68 # Bleh. Give mount_mfs a chance to DTRT.
69 sleep 2
70 }
71
72 md_get_diskdevs() {
73 # return available disk devices
74 mi_filter_dmesg | sed -n -e 's/^\(sd[0-9]\) .*/\1/p' -e 's/^\(x[dy][0-9]\) .*/\1/p' | sort -u
75 }
76
77 md_get_cddevs() {
78 # return available CDROM devices
79 mi_filter_dmesg | sed -n -e 's/^\(cd[0-9]\) .*/\1/p' | sort -u
80 }
81
82 md_get_ifdevs() {
83 # return available network devices
84 mi_filter_dmesg | sed -n -e 's/^\(le[0-9]\) .*/\1/p' -e 's/^\(ie[0-9]\) .*/\1/p' | sort -u
85 }
86
87 md_get_partition_range() {
88 # return range of valid partition letters
89 echo "[a-h]"
90 }
91
92 md_installboot() {
93 # $1 is the boot disk
94 echo "Installing boot block..."
95 cp -p /usr/mdec/boot /mnt/boot
96 /usr/sbin/installboot -v /dev/r${1}a /usr/mdec/bootxx /boot
97 }
98
99 md_native_fstype() {
100 }
101
102 md_native_fsopts() {
103 }
104
105 md_checkfordisklabel() {
106 # $1 is the disk to check
107 local rval
108 local cfdl
109
110 cfdl=$(disklabel $1 2>&1 > /dev/null | \
111 sed -n -e '/no disk label/{s/.*/ndl/p;q;}; \
112 /disk label corrupted/{s/.*/dlc/p;q;}; \
113 $s/.*/no/p')
114 if [ x$cfdl = xndl ]; then
115 rval=1
116 elif [ x$cfdl = xdlc ]; then
117 rval=2
118 else
119 rval=0
120 fi
121
122 return $rval
123 }
124
125 md_prep_disklabel()
126 {
127 local _disk
128
129 _disk=$1
130 md_checkfordisklabel $_disk
131 case $? in
132 0)
133 echo -n "Do you wish to edit the disklabel on $_disk? [y]"
134 ;;
135 1)
136 echo "WARNING: Disk $_disk has no label"
137 echo -n "Do you want to create one with the disklabel editor? [y]"
138 ;;
139 2)
140 echo "WARNING: Label on disk $_disk is corrupted"
141 echo -n "Do you want to try and repair the damage using the disklabel editor? [y]"
142 ;;
143 esac
144
145 getresp "y"
146 case "$resp" in
147 y*|Y*) ;;
148 *) return ;;
149 esac
150
151 # display example
152 cat << \__md_prep_disklabel_1
153
154 Here is an example of what the partition information will look like once
155 you have entered the disklabel editor. Disk partition sizes and offsets
156 are in sector (most likely 512 bytes) units. Make sure these size/offset
157 pairs are on cylinder boundaries (the number of sector per cylinder is
158 given in the 'sectors/cylinder' entry, which is not shown here).
159
160 Do not change any parameters except the partition layout and the label name.
161 It's probably also wisest not to touch the '8 partitions:' line, even
162 in case you have defined less than eight partitions.
163
164 [Example]
165 8 partitions:
166 # size offset fstype [fsize bsize cpg]
167 a: 50176 0 4.2BSD 1024 8192 16 # (Cyl. 0 - 111)
168 b: 64512 50176 swap # (Cyl. 112 - 255)
169 c: 640192 0 unknown # (Cyl. 0 - 1428)
170 d: 525504 114688 4.2BSD 1024 8192 16 # (Cyl. 256 - 1428)
171 [End of example]
172
173 __md_prep_disklabel_1
174 echo -n "Press [Enter] to continue "
175 getresp ""
176 disklabel -W ${_disk}
177 if [ -f /usr/bin/vi ]; then
178 disklabel -e ${_disk}
179 else
180 disklabel -i ${_disk}
181 fi
182 }
183
184 md_copy_kernel() {
185 if [ ! -f /mnt/netbsd ]; then
186 echo -n "WARNING: No kernel installed; "
187 if [ -f /netbsd ]; then
188 echo -n "copying miniroot kernel... "
189 cp -p /netbsd /mnt/netbsd
190 echo "done."
191 else
192 echo -n "install a kernel manually."
193 fi
194 fi
195 }
196
197 md_welcome_banner() {
198 {
199 if [ "$MODE" = "install" ]; then
200 echo ""
201 echo "Welcome to the NetBSD/sparc ${VERSION} installation program."
202 cat << \__welcome_banner_1
203
204 This program is designed to help you put NetBSD on your disk,
205 in a simple and rational way. You'll be asked several questions,
206 and it would probably be useful to have your disk's hardware
207 manual, the installation notes, and a calculator handy.
208 __welcome_banner_1
209
210 else
211 echo ""
212 echo "Welcome to the NetBSD/sparc ${VERSION} upgrade program."
213 cat << \__welcome_banner_2
214
215 This program is designed to help you upgrade your NetBSD system in a
216 simple and rational way.
217
218 As a reminder, installing the 'etc' binary set is NOT recommended.
219 Once the rest of your system has been upgraded, you should manually
220 merge any changes to files in the 'etc' set into those files which
221 already exist on your system.
222 __welcome_banner_2
223 fi
224
225 cat << \__welcome_banner_3
226
227 As with anything which modifies your disk's contents, this
228 program can cause SIGNIFICANT data loss, and you are advised
229 to make sure your data is backed up before beginning the
230 installation process.
231
232 Default answers are displayed in brackets after the questions.
233 You can hit Control-C at any time to quit, but if you do so at a
234 prompt, you may have to hit return. Also, quitting in the middle of
235 installation may leave your system in an inconsistent state.
236
237 __welcome_banner_3
238 } | more
239 }
240
241 md_not_going_to_install() {
242 cat << \__not_going_to_install_1
243
244 OK, then. Enter 'halt' at the prompt to halt the machine. Once the
245 machine has halted, power-cycle the system to load new boot code.
246
247 __not_going_to_install_1
248 }
249
250 md_congrats() {
251 local what;
252 if [ "$MODE" = "install" ]; then
253 what="installed";
254 else
255 what="upgraded";
256 fi
257 cat << __congratulations_1
258
259 CONGRATULATIONS! You have successfully $what NetBSD!
260 To boot the installed system, enter halt at the command prompt. Once the
261 system has halted, reset the machine and boot from the disk.
262
263 __congratulations_1
264 }
265
266 md_lib_is_aout() {
267 local r
268 test -h $1 && return 1
269 test -f $1 || return 1
270
271 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] && return 1
272 return 0
273 }
274
275
276 md_mv_usr_lib() {
277 local root
278 root=$1
279 for f in $root/usr/lib/lib*.so.[0-9]*.[0-9]* ; do
280 md_lib_is_aout $f || continue
281 mv -f $f $root/emul/aout/usr/lib || return 1
282 done
283 return 0
284 }
285
286 md_x_shlib_set_14=" \
287 libICE.so.6.3 \
288 libPEX5.so.6.0 \
289 libSM.so.6.0 \
290 libX11.so.6.1 \
291 libXIE.so.6.0 \
292 libXaw.so.6.1 \
293 libXext.so.6.3 \
294 libXi.so.6.0 \
295 libXmu.so.6.0 \
296 libXp.so.6.2 \
297 libXt.so.6.0 \
298 libXtst.so.6.1 \
299 liboldX.so.6.0"
300
301 md_mv_x_lib() {
302 local root xlibdir
303 root=$1
304 xlibdir=$2
305 for f in $md_x_shlib_set_14; do
306 md_lib_is_aout $root/$xlibdir/$f || continue
307 mv -f $root/$xlibdir/$f $root/emul/aout/$xlibdir || return 1
308 done
309 return 0
310 }
311
312 md_mv_aout_libs()
313 {
314 local root xlibdir
315
316 root=/mnt # XXX - should be global
317
318 if [ -d $root/emul/aout/. ]; then
319 echo "Using existing /emul/aout directory"
320 else
321 echo "Creating /emul/aout hierarchy"
322 mkdir -p $root/usr/aout || return 1
323
324 if [ ! -d $root/emul ]; then
325 mkdir $root/emul || return 1
326 fi
327
328 if [ -h $root/emul/aout ]; then
329 echo "Preserving existing symbolic link from /emul/aout"
330 mv -f $root/emul/aout $root/emul/aout.old || return 1
331 fi
332
333 ln -s ../usr/aout $root/emul/aout || return 1
334 fi
335
336 # Create /emul/aout/etc and /emul/aout/usr/lib
337 if [ ! -d $root/emul/aout/etc ]; then
338 mkdir $root/emul/aout/etc || return 1
339 fi
340 if [ ! -d $root/emul/aout/usr/lib ]; then
341 mkdir -p $root/emul/aout/usr/lib || return 1
342 fi
343
344 # Move ld.so.conf
345 if [ -f $root/etc/ld.so.conf ]; then
346 mv -f $root/etc/ld.so.conf $root/emul/aout/etc || return 1
347 fi
348
349 # Finally, move the aout shared libraries from /usr/lib
350 md_mv_usr_lib $root || return 1
351
352 # If X11 is installed, move the those libraries as well
353 xlibdir="/usr/X11R7/lib"
354 if [ -d $root/$xlibdir/. ]; then
355 mkdir -p $root/emul/aout/$xlibdir || return 1
356 md_mv_x_lib $root $xlibdir || return 1
357 fi
358
359 echo "a.out emulation environment setup completed."
360 }
361
362 md_prepare_upgrade()
363 {
364 cat << 'EOF'
365 This release uses the ELF binary object format. Existing (a.out) binaries
366 can still be used on your system after it has been upgraded, provided
367 that the shared libraries needed by those binaries are made available
368 in the filesystem hierarchy rooted at /emul/aout.
369
370 This upgrade procedure will now establish this hierarchy by moving all
371 shared libraries in a.out format found in /usr/lib to /emul/aout/usr/lib.
372 It will also move the X11 shared libraries in a.out format from previous
373 NetBSD/sparc X11 installation sets, if they are installed.
374
375 EOF
376 md_mv_aout_libs || {
377 echo "Failed to setup a.out emulation environment"
378 return 1
379 }
380 return 0
381 }
382
383 # Flag to notify upgrade.sh of the existence of md_prepare_upgrade()
384 md_upgrade_prep_needed=1
385