install.md revision 1.29 1 # $NetBSD: install.md,v 1.29 2019/04/04 21:00:19 christos Exp $
2 #
3 #
4 # Copyright (c) 1996,2006 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-GENERIC xbase xcomp xetc xfont xserver"
38
39 md_set_term() {
40 if [ ! -z "$TERM" ]; then
41 return
42 fi
43 echo -n "Specify terminal type [vt220]: "
44 getresp "vt220"
45 TERM="$resp"
46 export TERM
47 }
48
49 __mount_kernfs() {
50 #
51 # Force kern_fs to be mounted
52 #
53 if [ ! -d /kern ] || [ ! -e /kern/msgbuf ]; then
54 mkdir /kern > /dev/null 2>&1
55 /sbin/mount_kernfs /kern /kern >/dev/null 2>&1
56 fi
57 }
58
59 md_makerootwritable() {
60 # Mount root rw for convenience of the tester ;-)
61 if ! cp /dev/null /tmp/.root_writable >/dev/null 2>&1; then
62 __mount_kernfs
63 # XXX: Use /kern/rootdev instead?
64 mount -t ffs -u /kern/rootdev / > /dev/null 2>&1
65 fi
66 }
67
68 md_get_diskdevs() {
69 # return available disk devices
70 __mount_kernfs
71 sed -n -e '/^[sw]d[0-9] /s/ .*//p' \
72 < /kern/msgbuf | sort -u
73 }
74
75 md_get_cddevs() {
76 # return available CDROM devices
77 __mount_kernfs
78 sed -n -e '/^cd[0-9] /s/ .*//p' \
79 < /kern/msgbuf | sort -u
80 }
81
82 md_get_partition_range() {
83 # return an expression describing the valid partition id's
84 echo '[a-p]'
85 }
86
87 md_installboot() {
88 if [ -x /mnt/usr/sbin/installboot ]; then
89 echo -n "Should a boot block be installed? [y] "
90 getresp "y"
91 case "$resp" in
92 y*|Y*)
93 echo -n "Boot command? [netbsd -ASn2] "
94 getresp "netbsd -ASn2"
95 echo "Installing boot block..."
96 chroot /mnt /usr/sbin/installboot -o command="$resp" /dev/r${1}a /usr/mdec/bootxx_ffs
97 cp -p /mnt/usr/mdec/boot.amiga /mnt/
98 ;;
99 *)
100 echo "No bootblock installed."
101 ;;
102 esac
103 elif [ "$MODE" = "install" ]; then
104 cat << \__md_installboot_1
105 There is no installboot program found on the installed filesystems. No boot
106 programs are installed.
107 __md_installboot_1
108 else
109 cat << \__md_installboot_2
110 There is no installboot program found on the upgraded filesystems. No boot
111 programs are installed.
112 __md_installboot_2
113 fi
114 }
115
116 md_native_fstype() {
117 echo "ados"
118 }
119
120 md_native_fsopts() {
121 echo "ro"
122 }
123
124 md_prep_disklabel() {
125 }
126
127 md_view_labels_possible=1
128 md_view_labels() {
129 _DKDEVS=$(md_get_diskdevs)
130 echo "If you like, you can now examine the labels of your disks."
131 echo ""
132 echo -n "Available are "${_DKDEVS}". Look at which? [skip this step] "
133 getresp "done"
134 while [ "${resp:-done}" != "done" ]; do
135 echo ""
136 disklabel ${resp}
137 echo ""
138 echo -n "Available are "${_DKDEVS}". Look at which? [done] "
139 getresp "done"
140 done
141 cat << \__prep_disklabel_1
142
143 As a reminder: the 'c' partition is assigned to the whole disk and can't
144 normally be used for a any file system!
145
146 __prep_disklabel_1
147 }
148
149 md_labeldisk() {
150 }
151
152 md_welcome_banner() {
153 if [ "$MODE" = "install" ]; then
154 echo ""
155 echo "Welcome to the NetBSD/amiga ${VERSION} installation program."
156 cat << \__welcome_banner_1
157
158 This program is designed to help you put NetBSD on your disk,
159 in a simple and rational way. You'll be asked several questions,
160 and it would probably be useful to have your disk's hardware
161 manual, the installation notes, and a calculator handy.
162 __welcome_banner_1
163
164 else
165 echo ""
166 echo "Welcome to the NetBSD/amiga ${VERSION} upgrade program."
167 cat << \__welcome_banner_2
168
169 This program is designed to help you upgrade your NetBSD system in a
170 simple and rational way.
171
172 As a reminder, installing the 'etc' binary set is NOT recommended.
173 Once the rest of your system has been upgraded, you should manually
174 merge any changes to files in the 'etc' set into those files which
175 already exist on your system.
176 __welcome_banner_2
177 fi
178
179 cat << \__welcome_banner_3
180
181 As with anything which modifies your disk's contents, this
182 program can cause SIGNIFICANT data loss, and you are advised
183 to make sure your data is backed up before beginning the
184 installation process.
185
186 Default answers are displayed in brackets after the questions.
187 You can hit Control-C at any time to quit, but if you do so at a
188 prompt, you may have to hit return. Also, quitting in the middle of
189 installation may leave your system in an inconsistent state.
190
191 __welcome_banner_3
192 }
193
194 md_not_going_to_install() {
195 cat << \__not_going_to_install_1
196
197 OK, then. Enter 'halt' at the prompt to halt the machine. Once the
198 machine has halted, power-cycle the system to load new boot code.
199
200 Note: If you wish to have another try. Just type '^D' at the prompt. After
201 a moment, the installer will restart itself.
202
203 __not_going_to_install_1
204 }
205
206 md_congrats() {
207 local what;
208 if [ "$MODE" = "install" ]; then
209 what="installed";
210 else
211 what="upgraded";
212 fi
213 cat << __congratulations_1
214
215 CONGRATULATIONS! You have successfully $what NetBSD!
216 To boot the installed system, enter halt at the command prompt. Once the
217 system has halted, reset the machine and boot from the disk.
218
219 Note: If you wish to have another try. Just type '^D' at the prompt. After
220 a moment, the installer will restart itself.
221
222 __congratulations_1
223 }
224
225 md_copy_kernel() {
226 # This is largely a copy of install_disk and install_from_mounted_fs()
227 # with some special frobbing.
228
229 local _directory
230 local _sets
231 local _filename
232 local _f
233
234 if [ "$MODE" = "install" ]; then
235 echo -n "Adding keymap initialization to rc.local..."
236 echo /usr/sbin/loadkmap ${__keymap__} >> /mnt/etc/rc.local
237 echo "done."
238 fi
239
240 if [ -e /netbsd ]; then
241 if [ -e /mnt/netbsd ]; then
242 echo "On the installation filesystem there is this kernel: "
243 ls -l /netbsd
244 echo "The already installed kernel is: "
245 ls -l /mnt/netbsd
246 echo "Do you want to replace the already installed kernel by the kernel"
247 echo -n "on the installation filesystem? (y/n) [n] "
248 resp="n"
249 getresp ""
250 if [ "${resp}" != "y" ] && [ "${resp}" != "Y" ]; then
251 return
252 fi
253 fi
254
255 echo -n "Copying kernel..."
256 cp -p /netbsd /mnt/netbsd
257 echo "done."
258 return
259 fi
260
261 cat << \__md_copy_kernel_1
262 Your installation set did not include a netbsd kernel on the installation
263 filesystem. You are now given the opportunity install it from either the
264 kernel-floppy from the distribution or another location on one of your disks.
265
266 The following disk devices are installed on your system; please select
267 the disk device containing the partition with the netbsd kernel:
268 __md_copy_kernel_1
269
270 _DKDEVS=$(md_get_diskdevs)
271 echo "$_DKDEVS"
272 echo "fd0"
273 echo ""
274 _DKDEVS="$_DKDEVS fd0" # Might be on the kernel floppy!
275 echo -n "Which is the disk with the kernel? [abort] "
276
277 if mount_a_disk ; then
278 return # couldn't mount the disk
279 fi
280
281 # Get the directory where the file lives
282 resp="" # force one iteration
283 while [ -z "${resp}" ]; do
284 echo "Enter the directory relative to the mount point that"
285 echo -n "contains the file. [${_directory}] "
286 getresp "${_directory}"
287 done
288 _directory=$resp
289
290 _sets=$(cd /mnt2/$_directory; ls netbsd* 2> /dev/null)
291 if [ -z "$_sets" ]; then
292 echo "There are no NetBSD kernels available in \"$1\""
293 umount -f /mnt2 > /dev/null 2>&1
294 return
295 fi
296 while : ; do
297 echo "The following kernels are available:"
298 echo ""
299
300 for _f in $_sets ; do
301 echo " $_f"
302 done
303 echo ""
304 set -- $_sets
305 echo -n "File name [$1]? "
306 getresp "$1"
307 _f=$resp
308 _filename="/mnt2/$_directory/$_f"
309
310 # Ensure file exists
311 if [ ! -f $_filename ]; then
312 echo "File $_filename does not exist. Check to make"
313 echo "sure you entered the information properly."
314 echo -n "Do you want to retry [y]? "
315 getresp "y"
316 if [ "$resp" = "n" ]; then
317 break
318 fi
319 continue
320 fi
321
322 # Copy the kernel
323 cp $_filename /mnt
324 break
325 done
326 umount -f /mnt2 > /dev/null 2>&1
327 }
328
329 md_lib_is_aout() {
330 local r
331 test -h $1 && return 1
332 test -f $1 || return 1
333
334 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] && return 1
335 return 0
336 }
337
338
339 md_mv_usr_lib() {
340 local root
341 root=$1
342 for f in $root/usr/lib/lib*.so.[0-9]*.[0-9]* ; do
343 md_lib_is_aout $f || continue
344 mv -f $f $root/emul/aout/usr/lib || return 1
345 done
346 return 0
347 }
348
349 md_x_shlib_set_14=" \
350 libICE.so.6.3 \
351 libPEX5.so.6.0 \
352 libSM.so.6.0 \
353 libX11.so.6.1 \
354 libXIE.so.6.0 \
355 libXaw.so.6.1 \
356 libXext.so.6.3 \
357 libXi.so.6.0 \
358 libXmu.so.6.0 \
359 libXp.so.6.2 \
360 libXt.so.6.0 \
361 libXtst.so.6.1 \
362 liboldX.so.6.0"
363
364 md_mv_x_lib() {
365 local root xlibdir
366 root=$1
367 xlibdir=$2
368 for f in $md_x_shlib_set_14; do
369 md_lib_is_aout $root/$xlibdir/$f || continue
370 mv -f $root/$xlibdir/$f $root/emul/aout/$xlibdir || return 1
371 done
372 return 0
373 }
374
375 md_mv_aout_libs()
376 {
377 local root xlibdir
378
379 root=/mnt # XXX - should be global
380
381 if [ -d $root/emul/aout/. ]; then
382 echo "Using existing /emul/aout directory"
383 else
384 echo "Creating /emul/aout hierachy"
385 mkdir -p $root/usr/aout || return 1
386
387 if [ ! -d $root/emul ]; then
388 mkdir $root/emul || return 1
389 fi
390
391 if [ -h $root/emul/aout ]; then
392 echo "Preserving existing symbolic link from /emul/aout"
393 mv -f $root/emul/aout $root/emul/aout.old || return 1
394 fi
395
396 ln -s ../usr/aout $root/emul/aout || return 1
397 fi
398
399 # Create /emul/aout/etc and /emul/aout/usr/lib
400 if [ ! -d $root/emul/aout/etc ]; then
401 mkdir $root/emul/aout/etc || return 1
402 fi
403 if [ ! -d $root/emul/aout/usr/lib ]; then
404 mkdir -p $root/emul/aout/usr/lib || return 1
405 fi
406
407 # Move ld.so.conf
408 if [ -f $root/etc/ld.so.conf ]; then
409 mv -f $root/etc/ld.so.conf $root/emul/aout/etc || return 1
410 fi
411
412 # Finally, move the aout shared libraries from /usr/lib
413 md_mv_usr_lib $root || return 1
414
415 # If X11 is installed, move the those libraries as well
416 xlibdir="/usr/X11R6/lib"
417 if [ -d $root/$xlibdir/. ]; then
418 mkdir -p $root/emul/aout/$xlibdir || return 1
419 md_mv_x_lib $root $xlibdir || return 1
420 fi
421
422 echo "a.out emulation environment setup completed."
423 }
424
425 md_prepare_upgrade()
426 {
427 cat << 'EOF'
428 This release uses the ELF binary object format. Existing (a.out) binaries
429 can still be used on your system after it has been upgraded, provided
430 that the shared libraries needed by those binaries are made available
431 in the filesystem hierarchy rooted at /emul/aout.
432
433 This upgrade procedure will now establish this hierarchy by moving all
434 shared libraries in a.out format found in /usr/lib to /emul/aout/usr/lib.
435 It will also move the X11 shared libraries in a.out format from previous
436 NetBSD/amiga X11 installation sets, if they are installed.
437
438 EOF
439 md_mv_aout_libs || {
440 echo "Failed to setup a.out emulation environment"
441 return 1
442 }
443 return 0
444 }
445
446 # Flag to notify upgrade.sh of the existence of md_prepare_upgrade()
447 md_upgrade_prep_needed=1
448