Home | History | Annotate | Line # | Download | only in ramdisk
      1  1.1   lukem #!/bin/sh
      2  1.5  andvar # $NetBSD: upgrade.sh,v 1.5 2023/03/26 15:08:24 andvar Exp $
      3  1.1   lukem #
      4  1.1   lukem # Copyright (c) 1997 Perry E. Metzger
      5  1.1   lukem # Copyright (c) 1994 Christopher G. Demetriou
      6  1.1   lukem # All rights reserved.
      7  1.1   lukem # 
      8  1.1   lukem # Redistribution and use in source and binary forms, with or without
      9  1.1   lukem # modification, are permitted provided that the following conditions
     10  1.1   lukem # are met:
     11  1.1   lukem # 1. Redistributions of source code must retain the above copyright
     12  1.1   lukem #    notice, this list of conditions and the following disclaimer.
     13  1.1   lukem # 2. Redistributions in binary form must reproduce the above copyright
     14  1.1   lukem #    notice, this list of conditions and the following disclaimer in the
     15  1.1   lukem #    documentation and/or other materials provided with the distribution.
     16  1.1   lukem # 3. All advertising materials mentioning features or use of this software
     17  1.1   lukem #    must display the following acknowledgement:
     18  1.1   lukem #          This product includes software developed for the
     19  1.3    salo #          NetBSD Project.  See http://www.NetBSD.org/ for
     20  1.1   lukem #          information about NetBSD.
     21  1.1   lukem # 4. The name of the author may not be used to endorse or promote products
     22  1.1   lukem #    derived from this software without specific prior written permission.
     23  1.1   lukem # 
     24  1.1   lukem # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     25  1.1   lukem # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26  1.1   lukem # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  1.1   lukem # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     28  1.1   lukem # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     29  1.1   lukem # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     30  1.1   lukem # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31  1.1   lukem # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     32  1.1   lukem # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     33  1.1   lukem # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34  1.1   lukem # 
     35  1.1   lukem # <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
     36  1.1   lukem 
     37  1.1   lukem #	NetBSD upgrade script.
     38  1.1   lukem #	In a perfect world, this would be a nice C program, with a reasonable
     39  1.1   lukem #	user interface.
     40  1.1   lukem 
     41  1.1   lukem DT=/etc/disktab				# /etc/disktab
     42  1.1   lukem FSTABDIR=/mnt/etc			# /mnt/etc
     43  1.1   lukem #DONTDOIT=echo
     44  1.1   lukem UARGS="-c 2"
     45  1.1   lukem 
     46  1.1   lukem FSTAB=${FSTABDIR}/fstab
     47  1.1   lukem 
     48  1.1   lukem getresp() {
     49  1.1   lukem 	read resp
     50  1.1   lukem 	if [ "X$resp" = "X" ]; then
     51  1.1   lukem 		resp=$1
     52  1.1   lukem 	fi
     53  1.1   lukem }
     54  1.1   lukem 
     55  1.1   lukem echo	"Welcome to the original NetBSD/alpha upgrade program."
     56  1.1   lukem getresp
     57  1.1   lukem echo	"This version of the program has been largely replaced by the new
     58  1.1   lukem echo	"sysinst utility. Both programs are on this installation media set.
     59  1.1   lukem echo -n "Type the return key to continue..."
     60  1.1   lukem echo	""
     61  1.1   lukem echo	"This program is designed to help you put the new version of NetBSD"
     62  1.1   lukem echo	"on your hard disk, in a simple and rational way.  To upgrade, you"
     63  1.1   lukem echo	"must have plenty of free space on all partitions which will be"
     64  1.1   lukem echo	"upgraded.  If you have at least 1MB free on your root partition,"
     65  1.4  andvar echo	"and several free on your /usr partition, you should be fine."
     66  1.1   lukem echo	""
     67  1.1   lukem echo	"As with anything which modifies your hard drive's contents, this"
     68  1.1   lukem echo	"program can cause SIGNIFICANT data loss, and you are advised"
     69  1.1   lukem echo	"to make sure your hard drive is backed up before beginning the"
     70  1.1   lukem echo	"upgrade process."
     71  1.1   lukem echo	""
     72  1.5  andvar echo	"Default answers are displayed in brackets after the questions."
     73  1.1   lukem echo	"You can hit Control-C at any time to quit, but if you do so at a"
     74  1.1   lukem echo	"prompt, you may have to hit return.  Also, quitting in the middle of"
     75  1.1   lukem echo	"the upgrade may leave your system in an inconsistent (and unusable)"
     76  1.1   lukem echo	"state."
     77  1.1   lukem echo	""
     78  1.1   lukem echo -n "Proceed with upgrade? [n] "
     79  1.1   lukem getresp "n"
     80  1.1   lukem case "$resp" in
     81  1.1   lukem 	y*|Y*)
     82  1.1   lukem 		echo	"Cool!  Let's get to it..."
     83  1.1   lukem 		;;
     84  1.1   lukem 	*)
     85  1.1   lukem 		echo	""
     86  1.1   lukem 		echo	"OK, then.  Enter 'halt' at the prompt to halt the"
     87  1.1   lukem 		echo	"machine.  Once the machine has halted, remove the"
     88  1.1   lukem 		echo	"floppy and press any key to reboot."
     89  1.1   lukem 		exit
     90  1.1   lukem 		;;
     91  1.1   lukem esac
     92  1.1   lukem 
     93  1.1   lukem # find out what units are possible, and query the user.
     94  1.1   lukem driveunits=`echo /dev/[sw]d?a | sed -e 's,/dev/\(...\)a,\1,g'`
     95  1.1   lukem if [ "X${driveunits}" = "X" ]; then
     96  1.1   lukem 	echo	"FATAL ERROR:"
     97  1.1   lukem 	echo	"No disk devices."
     98  1.1   lukem 	echo	"This is probably a bug in the install disks."
     99  1.1   lukem 	echo	"Exiting install program."
    100  1.1   lukem 	exit
    101  1.1   lukem fi
    102  1.1   lukem 
    103  1.1   lukem echo	""
    104  1.1   lukem echo	"The following disks are supported by this upgrade procedure:"
    105  1.1   lukem echo	"	"${driveunits}
    106  1.1   lukem echo	"If your system was previously completely contained within the"
    107  1.1   lukem echo	"disks listed above (i.e. if your system didn't occupy any space"
    108  1.1   lukem echo	"on disks NOT listed above), this upgrade disk can upgrade your"
    109  1.1   lukem echo	"system.  If it cannot, hit Control-C at the prompt."
    110  1.1   lukem echo	""
    111  1.1   lukem while [ "X${drivename}" = "X" ]; do
    112  1.1   lukem 	echo -n	"Which disk contains your root partition? "
    113  1.1   lukem 	getresp
    114  1.1   lukem 	otherdrives=`echo "${driveunits}" | sed -e s,${resp},,`
    115  1.1   lukem 	if [ "X${driveunits}" = "X${otherdrives}" ]; then
    116  1.1   lukem 		echo	""
    117  1.1   lukem 		echo	"\"${resp}\" is an invalid drive name.  Valid choices"
    118  1.1   lukem 		echo	"are: "${driveunits}
    119  1.1   lukem 		echo	""
    120  1.1   lukem 	else
    121  1.1   lukem 		drivename=${resp}
    122  1.1   lukem 	fi
    123  1.1   lukem done
    124  1.1   lukem 
    125  1.1   lukem echo	""
    126  1.1   lukem echo	"Root partition is on ${drivename}a."
    127  1.1   lukem 
    128  1.1   lukem echo	""
    129  1.1   lukem echo	"If (and only if!) you are upgrading from NetBSD 0.9 or below,"
    130  1.1   lukem echo	"you should upgrade to the new file system format. Do not answer"
    131  1.1   lukem echo	"yes if you are upgrading from NetBSD 1.0 or above."
    132  1.1   lukem echo	"Would you like to upgrade your file systems to the new file system"
    133  1.1   lukem echo -n	"format? [y] "
    134  1.1   lukem getresp "y"
    135  1.1   lukem case "$resp" in
    136  1.1   lukem 	n*|N*)
    137  1.1   lukem 		echo	""
    138  1.1   lukem 		echo	"If you are upgrading from NetBSD 0.9 or below,"
    139  1.1   lukem 		echo	"you should upgrade your file systems with 'fsck -c 2'"
    140  1.1   lukem 		echo	"as soon as is feasible, because the new file system"
    141  1.1   lukem 		echo	"code is better-tested and more performant."
    142  1.1   lukem 		upgrargs=""
    143  1.1   lukem 		upgradefs=NO
    144  1.1   lukem 		;;
    145  1.1   lukem 	*)
    146  1.1   lukem 		upgrargs=$UARGS
    147  1.1   lukem 		upgradefs=YES
    148  1.1   lukem 		;;
    149  1.1   lukem esac
    150  1.1   lukem 
    151  1.1   lukem if [ $upgradefs = YES ]; then
    152  1.1   lukem 	echo	""
    153  1.1   lukem 	echo	"your file systems will be upgraded while they are checked"
    154  1.1   lukem fi
    155  1.1   lukem 
    156  1.1   lukem echo	"checking the file system on ${drivename}a..."
    157  1.1   lukem 	
    158  1.1   lukem fsck -f -p $upgrargs /dev/r${drivename}a
    159  1.1   lukem if [ $? != 0 ]; then
    160  1.1   lukem 	echo	"FATAL ERROR: FILE SYSTEM UPGRADE FAILED."
    161  1.1   lukem 	echo	"You should probably reboot the machine, fsck your"
    162  1.1   lukem 	echo	"disk(s), and try the upgrade procedure again."
    163  1.1   lukem 	exit 1
    164  1.1   lukem fi
    165  1.1   lukem 
    166  1.1   lukem echo	""
    167  1.1   lukem echo	"Mounting root partition on /mnt..."
    168  1.1   lukem mount /dev/${drivename}a /mnt
    169  1.1   lukem if [ $? != 0 ]; then
    170  1.1   lukem 	echo	"FATAL ERROR: MOUNT FAILED."
    171  1.1   lukem 	echo	"You should verify that your system is set up as you"
    172  1.1   lukem 	echo	"described, and re-attempt the upgrade procedure."
    173  1.1   lukem 	exit 1
    174  1.1   lukem fi
    175  1.1   lukem echo	"Done."
    176  1.1   lukem 
    177  1.1   lukem echo	""
    178  1.1   lukem echo -n	"Copying new fsck binary to your hard disk..."
    179  1.1   lukem if [ ! -d /mnt/sbin ]; then
    180  1.1   lukem 	mkdir /mnt/sbin
    181  1.1   lukem fi
    182  1.1   lukem cp /sbin/fsck /mnt/sbin/fsck
    183  1.1   lukem if [ $? != 0 ]; then
    184  1.1   lukem 	echo	"FATAL ERROR: COPY FAILED."
    185  1.1   lukem 	echo	"It in unclear why this error would occur.  It looks"
    186  1.1   lukem 	echo	"like you may end up having to upgrade by hand."
    187  1.1   lukem 	exit 1
    188  1.1   lukem fi
    189  1.1   lukem echo	" Done."
    190  1.1   lukem 
    191  1.1   lukem echo	""
    192  1.1   lukem echo    "Re-mounting root partition read-only..."
    193  1.1   lukem mount -u -o ro /dev/${drivename}a /mnt
    194  1.1   lukem if [ $? != 0 ]; then
    195  1.1   lukem 	echo	"FATAL ERROR: RE-MOUNT FAILED."
    196  1.1   lukem 	echo	"It in unclear why this error would occur.  It looks"
    197  1.1   lukem 	echo	"like you may end up having to upgrade by hand."
    198  1.1   lukem 	exit 1
    199  1.1   lukem fi
    200  1.1   lukem echo	"Done."
    201  1.1   lukem 
    202  1.1   lukem echo	""
    203  1.1   lukem echo	"checking the rest of your file systems..."
    204  1.1   lukem chroot /mnt fsck -f -p $upgrargs
    205  1.1   lukem if [ $? != 0 ]; then
    206  1.1   lukem 	echo	"FATAL ERROR: FILE SYSTEM UPGRADE(S) FAILED."
    207  1.1   lukem 	echo	"You should probably reboot the machine, fsck your"
    208  1.1   lukem 	echo	"file system(s), and try the upgrade procedure"
    209  1.1   lukem 	echo	"again."
    210  1.1   lukem 	exit 1
    211  1.1   lukem fi
    212  1.1   lukem 	echo	"Done."
    213  1.1   lukem 
    214  1.1   lukem echo	""
    215  1.1   lukem echo    "Re-mounting root partition read-write..."
    216  1.1   lukem mount -u -o rw /dev/${drivename}a /mnt
    217  1.1   lukem if [ $? != 0 ]; then
    218  1.1   lukem 	echo	"FATAL ERROR: RE-MOUNT FAILED."
    219  1.1   lukem 	echo	"It in unclear why this error would occur.  It looks"
    220  1.1   lukem 	echo	"like you may end up having to upgrade by hand."
    221  1.1   lukem 	exit 1
    222  1.1   lukem fi
    223  1.1   lukem echo	"Done."
    224  1.1   lukem 
    225  1.1   lukem echo	""
    226  1.1   lukem echo	"Updating boot blocks on ${drivename}..."
    227  1.1   lukem # shouldn't be needed, but...
    228  1.1   lukem $DONTDOIT rm -f /mnt/boot
    229  1.1   lukem $DONTDOIT cp /usr/mdec/boot /mnt/boot
    230  1.2   lukem $DONTDOIT /usr/sbin/installboot /dev/r${drivename}c /usr/mdec/bootxx_ffs
    231  1.1   lukem if [ $? != 0 ]; then
    232  1.1   lukem 	echo	"FATAL ERROR: UPDATE OF DISK LABEL FAILED."
    233  1.1   lukem 	echo	"It in unclear why this error would occur.  It looks"
    234  1.1   lukem 	echo	"like you may end up having to upgrade by hand."
    235  1.1   lukem 	exit 1
    236  1.1   lukem fi
    237  1.1   lukem echo	"Done."
    238  1.1   lukem 
    239  1.1   lukem echo	""
    240  1.1   lukem echo	"Copying bootstrapping binaries and config files to the hard drive..."
    241  1.1   lukem $DONTDOIT cp /mnt/.profile /mnt/.profile.bak
    242  1.1   lukem $DONTDOIT pax -s '#^\./etc/.*##' -Xrwpe . /mnt
    243  1.1   lukem $DONTDOIT mv /mnt/etc/rc /mnt/etc/rc.bak
    244  1.1   lukem $DONTDOIT cp /tmp/.hdprofile /mnt/.profile
    245  1.1   lukem 
    246  1.1   lukem echo	""
    247  1.1   lukem echo	"Mounting remaining partitions..."
    248  1.1   lukem chroot /mnt mount -at ffs > /dev/null 2>&1
    249  1.1   lukem echo	"Done."
    250  1.1   lukem 
    251  1.1   lukem echo    ""
    252  1.1   lukem echo    ""
    253  1.1   lukem echo	"OK!  The preliminary work of setting up your disk is now complete,"
    254  1.1   lukem echo	"and you can now upgrade the actual NetBSD software."
    255  1.1   lukem echo	""
    256  1.1   lukem echo	"Right now, your hard disk is mounted on /mnt.  You should consult"
    257  1.1   lukem echo	"the installation notes to determine how to load and install the new"
    258  1.1   lukem echo	"NetBSD distribution sets, and how to clean up after the upgrade"
    259  1.1   lukem echo	"software, when you are done."
    260  1.1   lukem echo	""
    261  1.1   lukem echo	"GOOD LUCK!"
    262  1.1   lukem echo	""
    263