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