install.c revision 8556
1/* 2 * The new sysinstall program. 3 * 4 * This is probably the last program in the `sysinstall' line - the next 5 * generation being essentially a complete rewrite. 6 * 7 * $Id: install.c,v 1.17 1995/05/16 02:53:11 jkh Exp $ 8 * 9 * Copyright (c) 1995 10 * Jordan Hubbard. All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer, 17 * verbatim and that no modifications are made prior to this 18 * point in the file. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. All advertising materials mentioning features or use of this software 23 * must display the following acknowledgement: 24 * This product includes software developed by Jordan Hubbard 25 * for the FreeBSD Project. 26 * 4. The name of Jordan Hubbard or the FreeBSD project may not be used to 27 * endorse or promote products derived from this software without specific 28 * prior written permission. 29 * 30 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND 31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 33 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE 34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 36 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) 37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 * SUCH DAMAGE. 41 * 42 */ 43 44#include "sysinstall.h" 45#include <sys/disklabel.h> 46#include <sys/errno.h> 47#include <sys/fcntl.h> 48#include <unistd.h> 49 50Boolean SystemWasInstalled; 51 52static void make_filesystems(void); 53static void cpio_extract(void); 54static void install_configuration_files(void); 55static void do_final_setup(void); 56 57int 58installCommit(char *str) 59{ 60 extern u_char boot1[], boot2[]; 61 extern u_char mbr[], bteasy17[]; 62 u_char *mbrContents; 63 Device **devs; 64 int i; 65 66 if (!getenv(DISK_PARTITIONED)) { 67 msgConfirm("You need to partition your disk before you can proceed with\nthe installation."); 68 69 return 0; 70 } 71 if (!getenv(DISK_LABELLED)) { 72 msgConfirm("You need to assign disk labels before you can proceed with\nthe installation."); 73 return 0; 74 } 75 if (!Dists) { 76 msgConfirm("You haven't told me what distributions to load yet!\nPlease select a distribution from the Distributions menu."); 77 return 0; 78 } 79 if (mediaVerify()) { 80 msgConfirm("Please correct installation media problems and try again!"); 81 return 0; 82 } 83 if (msgYesNo("Last Chance! Are you SURE you want continue the\ninstallation? If you're running this on an existing system, we STRONGLY\nencourage you to make proper backups before doing this.\nWe take no responsibility for lost disk contents!")) 84 return 0; 85 86 mbrContents = NULL; 87 if (!msgYesNo("Would you like to install a boot manager?\n\nThis will allow you to easily select between other operating systems\non the first disk, or boot from a disk other than the first.")) 88 mbrContents = bteasy17; 89 else { 90 if (!msgYesNo("Would you like to remove an existing boot manager?")) 91 mbrContents = mbr; 92 } 93 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 94 for (i = 0; devs[i]; i++) { 95 Disk *d = (Disk *)devs[i]->private; 96 97 if (mbrContents) { 98 Set_Boot_Mgr(d, mbrContents); 99 mbrContents = NULL; 100 } 101 Set_Boot_Blocks(d, boot1, boot2); 102 msgNotify("Writing partition information to drive %s", d->name); 103 Write_Disk(d); 104 } 105 make_filesystems(); 106 cpio_extract(); 107 install_configuration_files(); 108 do_final_setup(); 109 return 1; 110} 111 112/* Go newfs and/or mount all the filesystems we've been asked to */ 113static void 114make_filesystems(void) 115{ 116 int i; 117 Disk *disk; 118 Chunk *c1, *c2; 119 Device **devs; 120 121 command_clear(); 122 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 123 124 /* First look for the root device and mount it */ 125 for (i = 0; devs[i]; i++) { 126 disk = (Disk *)devs[i]->private; 127 if (!disk->chunks) 128 msgFatal("No chunk list found for %s!", disk->name); 129 c1 = disk->chunks->part; 130 while (c1) { 131 if (c1->type == freebsd) { 132 for (c2 = c1->part; c2; c2 = c2->next) { 133 if (c2->type == part && c2->subtype != FS_SWAP && 134 c2->private && c2->flags & CHUNK_IS_ROOT) { 135 char dname[40]; 136 PartInfo *p = (PartInfo *)c2->private; 137 138 if (strcmp(p->mountpoint, "/")) 139 continue; 140 sprintf(dname, "/dev/%sa", disk->name); 141 if (p->newfs) { 142 msgDebug("newfs %s", dname); 143 if (vsystem("newfs %s", dname)) { 144 msgConfirm("Unable to make new root filesystem!"); 145 return; 146 } 147 } 148 else 149 msgConfirm("Warning: You have selected a Read-Only root device\nand may be unable to find the appropriate device entries on it\nif it is from an older pre-slice version of FreeBSD."); 150 if (Mount(dname, NULL)) { 151 msgConfirm("Unable to mount the root file system! Giving up."); 152 return; 153 } 154 else 155 break; 156 } 157 } 158 } 159 } 160 } 161 162 /* Now buzz through the rest of the devices and mount them too */ 163 for (i = 0; devs[i]; i++) { 164 disk = (Disk *)devs[i]->private; 165 if (!disk->chunks) 166 msgFatal("No chunk list found for %s!", disk->name); 167 /* Make the proper device mount points in /mnt/dev */ 168 MakeDevDisk(disk, "/mnt/dev"); 169 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 170 if (c1->type == freebsd) { 171 for (c2 = c1->part; c2; c2 = c2->next) { 172 if (c2->type == part && c2->subtype != FS_SWAP && c2->private) { 173 PartInfo *tmp = (PartInfo *)c2->private; 174 175 if (!strcmp(tmp->mountpoint, "/")) 176 continue; 177 178 if (tmp->newfs) 179 command_shell_add(tmp->mountpoint, 180 "%s %s", tmp->newfs_cmd, c2->name); 181 command_func_add(tmp->mountpoint, Mount, c2->name); 182 } 183 } 184 } 185 } 186 } 187 command_sort(); 188 command_execute(); 189} 190 191static void 192cpio_extract(void) 193{ 194 int i, j, zpid, cpid, pfd[2]; 195 extern int wait(int *status); 196 197 while (CpioFD == -1) { 198 msgConfirm("Please Insert CPIO floppy in floppy drive 0"); 199 CpioFD = open("/dev/rfd0", O_RDONLY); 200 } 201 msgNotify("Extracting contents of CPIO floppy..."); 202 pipe(pfd); 203 zpid = fork(); 204 if (!zpid) { 205 close(0); dup(CpioFD); close(CpioFD); 206 close(1); dup(pfd[1]); close(pfd[1]); 207 close(pfd[0]); 208 i = execl("/stand/gunzip", "/stand/gunzip", 0); 209 msgDebug("/stand/gunzip command returns %d status\n", i); 210 exit(i); 211 } 212 cpid = fork(); 213 if (!cpid) { 214 close(0); dup(pfd[0]); close(pfd[0]); 215 close(CpioFD); 216 close(pfd[1]); 217 close(1); open("/dev/null", O_WRONLY); 218 i = execl("/stand/cpio", "/stand/cpio", "-iduvm", 0); 219 msgDebug("/stand/cpio command returns %d status\n", i); 220 exit(i); 221 } 222 close(pfd[0]); 223 close(pfd[1]); 224 close(CpioFD); 225 i = wait(&j); 226 if (i < 0 || j) 227 msgFatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s", 228 i, j, cpid, zpid, strerror(errno)); 229 i = wait(&j); 230 if (i < 0 || j) 231 msgFatal("Pid %d, status %d, cpio=%d, gunzip=%d.\nerror:%s", 232 i, j, cpid, zpid, strerror(errno)); 233} 234 235static void 236install_configuration_files(void) 237{ 238} 239 240static void 241do_final_setup(void) 242{ 243} 244