install.c revision 18650
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.123 1996/10/02 10:44:31 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 * 23 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 */ 36 37#include "sysinstall.h" 38#include "uc_main.h" 39#include <ctype.h> 40#include <sys/disklabel.h> 41#include <sys/errno.h> 42#include <sys/ioctl.h> 43#include <sys/fcntl.h> 44#include <sys/wait.h> 45#include <sys/param.h> 46#define MSDOSFS 47#include <sys/mount.h> 48#undef MSDOSFS 49#include <sys/stat.h> 50#include <unistd.h> 51#include <sys/mount.h> 52 53static void create_termcap(void); 54static void save_userconfig_to_kernel(char *); 55 56#define TERMCAP_FILE "/usr/share/misc/termcap" 57 58static void installConfigure(void); 59 60Boolean 61checkLabels(Boolean whinge, Chunk **rdev, Chunk **sdev, Chunk **udev, Chunk **vdev) 62{ 63 Device **devs; 64 Boolean status; 65 Disk *disk; 66 Chunk *c1, *c2, *rootdev, *swapdev, *usrdev, *vardev; 67 int i; 68 69 status = TRUE; 70 *rdev = *sdev = *udev = *vdev = rootdev = swapdev = usrdev = vardev = NULL; 71 72 /* We don't need to worry about root/usr/swap if we're already multiuser */ 73 if (!RunningAsInit) 74 return status; 75 76 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 77 /* First verify that we have a root device */ 78 for (i = 0; devs[i]; i++) { 79 if (!devs[i]->enabled) 80 continue; 81 disk = (Disk *)devs[i]->private; 82 msgDebug("Scanning disk %s for root filesystem\n", disk->name); 83 if (!disk->chunks) 84 msgFatal("No chunk list found for %s!", disk->name); 85 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 86 if (c1->type == freebsd) { 87 for (c2 = c1->part; c2; c2 = c2->next) { 88 if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) { 89 if (c2->flags & CHUNK_IS_ROOT) { 90 if (rootdev) { 91 if (whinge) 92 msgConfirm("WARNING: You have more than one root device set?!\n" 93 "Using the first one found."); 94 continue; 95 } 96 else { 97 rootdev = c2; 98 if (isDebug()) 99 msgDebug("Found rootdev at %s!\n", rootdev->name); 100 } 101 } 102 else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/usr")) { 103 if (usrdev) { 104 if (whinge) 105 msgConfirm("WARNING: You have more than one /usr filesystem.\n" 106 "Using the first one found."); 107 continue; 108 } 109 else { 110 usrdev = c2; 111 if (isDebug()) 112 msgDebug("Found usrdev at %s!\n", usrdev->name); 113 } 114 } 115 else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/var")) { 116 if (vardev) { 117 if (whinge) 118 msgConfirm("WARNING: You have more than one /var filesystem.\n" 119 "Using the first one found."); 120 continue; 121 } 122 else { 123 vardev = c2; 124 if (isDebug()) 125 msgDebug("Found vardev at %s!\n", vardev->name); 126 } 127 } 128 } 129 } 130 } 131 } 132 } 133 134 /* Now check for swap devices */ 135 for (i = 0; devs[i]; i++) { 136 if (!devs[i]->enabled) 137 continue; 138 disk = (Disk *)devs[i]->private; 139 msgDebug("Scanning disk %s for swap partitions\n", disk->name); 140 if (!disk->chunks) 141 msgFatal("No chunk list found for %s!", disk->name); 142 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 143 if (c1->type == freebsd) { 144 for (c2 = c1->part; c2; c2 = c2->next) { 145 if (c2->type == part && c2->subtype == FS_SWAP && !swapdev) { 146 swapdev = c2; 147 if (isDebug()) 148 msgDebug("Found swapdev at %s!\n", swapdev->name); 149 break; 150 } 151 } 152 } 153 } 154 } 155 156 /* Copy our values over */ 157 *rdev = rootdev; 158 *sdev = swapdev; 159 *udev = usrdev; 160 *vdev = vardev; 161 162 if (!rootdev && whinge) { 163 msgConfirm("No root device found - you must label a partition as /\n" 164 "in the label editor."); 165 status = FALSE; 166 } 167 if (!swapdev && whinge) { 168 msgConfirm("No swap devices found - you must create at least one\n" 169 "swap partition."); 170 status = FALSE; 171 } 172 if (!usrdev && whinge) { 173 msgConfirm("WARNING: No /usr filesystem found. This is not technically\n" 174 "an error if your root filesystem is big enough (or you later\n" 175 "intend to mount your /usr filesystem over NFS), but it may otherwise\n" 176 "cause you trouble if you're not exactly sure what you are doing!"); 177 } 178 if (!vardev && whinge) { 179 msgConfirm("WARNING: No /var filesystem found. This is not technically\n" 180 "an error if your root filesystem is big enough (or you later\n" 181 "intend to link /var to someplace else), but it may otherwise\n" 182 "cause your root filesystem to fill up if you receive lots of mail\n" 183 "or edit large temporary files."); 184 } 185 return status; 186} 187 188static int 189installInitial(void) 190{ 191 static Boolean alreadyDone = FALSE; 192 193 if (alreadyDone) 194 return DITEM_SUCCESS; 195 196 if (!variable_get(DISK_LABELLED)) { 197 msgConfirm("You need to assign disk labels before you can proceed with\n" 198 "the installation."); 199 return DITEM_FAILURE; 200 } 201 /* If it's labelled, assume it's also partitioned */ 202 if (!variable_get(DISK_PARTITIONED)) 203 variable_set2(DISK_PARTITIONED, "yes"); 204 205 /* If we refuse to proceed, bail. */ 206 dialog_clear_norefresh(); 207 if (msgYesNo("Last Chance! Are you SURE you want continue the installation?\n\n" 208 "If you're running this on a disk with data you wish to save\n" 209 "then WE STRONGLY ENCOURAGE YOU TO MAKE PROPER BACKUPS before\n" 210 "proceeding!\n\n" 211 "We can take no responsibility for lost disk contents!")) 212 return DITEM_FAILURE | DITEM_RESTORE; 213 214 if (DITEM_STATUS(diskLabelCommit(NULL)) != DITEM_SUCCESS) { 215 msgConfirm("Couldn't make filesystems properly. Aborting."); 216 return DITEM_FAILURE; 217 } 218 else if (isDebug()) 219 msgDebug("installInitial: Scribbled successfully on the disk(s)\n"); 220 221 if (!copySelf()) { 222 msgConfirm("Couldn't clone the boot floppy onto the root file system.\n" 223 "Aborting."); 224 return DITEM_FAILURE; 225 } 226 227 if (chroot("/mnt") == -1) { 228 msgConfirm("Unable to chroot to /mnt - this is bad!"); 229 return DITEM_FAILURE; 230 } 231 232 chdir("/"); 233 variable_set2(RUNNING_ON_ROOT, "yes"); 234 235 /* stick a helpful shell over on the 4th VTY */ 236 systemCreateHoloshell(); 237 238 alreadyDone = TRUE; 239 return DITEM_SUCCESS; 240} 241 242int 243installFixitCDROM(dialogMenuItem *self) 244{ 245 msgConfirm("Sorry, this feature is currently unimplemented but will,\n" 246 "at some point in the future, support the use of the live\n" 247 "filesystem CD (CD 2) in fixing your system."); 248 return DITEM_SUCCESS; 249} 250 251int 252installFixitFloppy(dialogMenuItem *self) 253{ 254 struct ufs_args args; 255 pid_t child; 256 int waitstatus; 257 258 variable_set2(SYSTEM_STATE, "fixit"); 259 memset(&args, 0, sizeof(args)); 260 args.fspec = "/dev/fd0"; 261 Mkdir("/mnt2"); 262 263 while (1) { 264 msgConfirm("Please insert a writable fixit floppy and press return"); 265 if (mount(MOUNT_UFS, "/mnt2", 0, (caddr_t)&args) != -1) 266 break; 267 if (msgYesNo("Unable to mount the fixit floppy - do you want to try again?")) 268 return DITEM_FAILURE; 269 } 270 dialog_clear(); 271 end_dialog(); 272 DialogActive = FALSE; 273 if (!directory_exists("/tmp")) 274 (void)symlink("/mnt2/tmp", "/tmp"); 275 if (!directory_exists("/var/tmp/vi.recover")) { 276 if (DITEM_STATUS(Mkdir("/var/tmp/vi.recover")) != DITEM_SUCCESS) { 277 msgConfirm("Warning: Was unable to create a /var/tmp/vi.recover directory.\n" 278 "vi will kvetch and moan about it as a result but should still\n" 279 "be essentially usable."); 280 } 281 } 282 /* Link the spwd.db file */ 283 if (DITEM_STATUS(Mkdir("/etc")) != DITEM_SUCCESS) 284 msgConfirm("Unable to create an /etc directory! Things are weird on this floppy.."); 285 else if (symlink("/mnt2/etc/spwd.db", "/etc/spwd.db") == -1 && errno != EEXIST) 286 msgConfirm("Couldn't symlink the /etc/spwd.db file! I'm not sure I like this.."); 287 if (!file_readable(TERMCAP_FILE)) 288 create_termcap(); 289 if (!(child = fork())) { 290 struct termios foo; 291 292 signal(SIGTTOU, SIG_IGN); 293 if (tcgetattr(0, &foo) != -1) { 294 foo.c_cc[VERASE] = '\010'; 295 if (tcsetattr(0, TCSANOW, &foo) == -1) 296 msgDebug("fixit shell: Unable to set erase character.\n"); 297 } 298 else 299 msgDebug("fixit shell: Unable to get terminal attributes!\n"); 300 printf("When you're finished with this shell, please type exit.\n"); 301 printf("The fixit floppy itself is mounted as /mnt2\n"); 302 setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/stand:/mnt2/stand", 1); 303 execlp("sh", "-sh", 0); 304 msgDebug("fixit shell: Failed to execute shell!\n"); 305 return -1; 306 } 307 else 308 (void)waitpid(child, &waitstatus, 0); 309 310 DialogActive = TRUE; 311 clear(); 312 dialog_clear(); 313 unmount("/mnt2", MNT_FORCE); 314 msgConfirm("Please remove the fixit floppy now."); 315 return DITEM_SUCCESS; 316} 317 318int 319installExpress(dialogMenuItem *self) 320{ 321 int i; 322 323 variable_set2(SYSTEM_STATE, "express"); 324 if (DITEM_STATUS((i = diskPartitionEditor(self))) == DITEM_FAILURE) 325 return i; 326 327 if (DITEM_STATUS((i = diskLabelEditor(self))) == DITEM_FAILURE) 328 return i; 329 330 if (!Dists) { 331 dialog_clear_norefresh(); 332 if (!dmenuOpenSimple(&MenuDistributions, FALSE) && !Dists) 333 return DITEM_FAILURE | DITEM_RECREATE; 334 } 335 336 if (!mediaDevice) { 337 dialog_clear_norefresh(); 338 if (!dmenuOpenSimple(&MenuMedia, FALSE) || !mediaDevice) 339 return DITEM_FAILURE | DITEM_RECREATE; 340 } 341 342 if (DITEM_STATUS((i = installCommit(self))) == DITEM_SUCCESS) { 343 i |= DITEM_LEAVE_MENU; 344 /* Give user the option of one last configuration spree */ 345 installConfigure(); 346 347 /* Now write out any changes .. */ 348 configResolv(); 349 configSysconfig("/etc/sysconfig"); 350 } 351 return i | DITEM_RECREATE; 352} 353 354/* Novice mode installation */ 355int 356installNovice(dialogMenuItem *self) 357{ 358 int i; 359 extern int cdromMounted; 360 361 variable_set2(SYSTEM_STATE, "novice"); 362 dialog_clear_norefresh(); 363 msgConfirm("In the next menu, you will need to set up a DOS-style (\"fdisk\") partitioning\n" 364 "scheme for your hard disk. If you simply wish to devote all disk space\n" 365 "to FreeBSD (overwritting anything else that might be on the disk(s) selected)\n" 366 "then use the (A)ll command to select the default partitioning scheme followed\n" 367 "by a (Q)uit. If you wish to allocate only free space to FreeBSD, move to a\n" 368 "partition marked \"unused\" and use the (C)reate command."); 369 370 if (DITEM_STATUS(diskPartitionEditor(self)) == DITEM_FAILURE) 371 return DITEM_FAILURE; 372 373 dialog_clear_norefresh(); 374 msgConfirm("Next, you need to create BSD partitions inside of the fdisk partition(s)\n" 375 "just created. If you have a reasonable amount of disk space (200MB or more)\n" 376 "and don't have any special requirements, simply use the (A)uto command to\n" 377 "allocate space automatically. If you have more specific needs or just don't\n" 378 "care for the layout chosen by (A)uto, press F1 for more information on\n" 379 "manual layout."); 380 381 if (DITEM_STATUS(diskLabelEditor(self)) == DITEM_FAILURE) 382 return DITEM_FAILURE; 383 384 while (1) { 385 dialog_clear_norefresh(); 386 if (!dmenuOpenSimple(&MenuDistributions, FALSE) && !Dists) 387 return DITEM_FAILURE | DITEM_RECREATE; 388 389 if (Dists || !msgYesNo("No distributions selected. Are you sure you wish to continue?")) 390 break; 391 } 392 393 if (!mediaDevice && !dmenuOpenSimple(&MenuMedia, FALSE)) 394 return DITEM_FAILURE | DITEM_RECREATE; 395 396 if (DITEM_STATUS((i = installCommit(self))) == DITEM_FAILURE) { 397 dialog_clear_norefresh(); 398 msgConfirm("Installation completed with some errors. You may wish to\n" 399 "scroll through the debugging messages on VTY1 with the\n" 400 "scroll-lock feature. You can also chose \"No\" at the next\n" 401 "prompt and go back into the installation menus to try and retry\n" 402 "whichever operations have failed."); 403 return i | DITEM_RECREATE; 404 405 } 406 else { 407 dialog_clear_norefresh(); 408 msgConfirm("Congratulations! You now have FreeBSD installed on your system.\n\n" 409 "We will now move on to the final configuration questions.\n" 410 "For any option you do not wish to configure, simply select\n" 411 "No.\n\n" 412 "If you wish to re-enter this utility after the system is up, you\n" 413 "may do so by typing: /stand/sysinstall."); 414 } 415 if (mediaDevice->type != DEVICE_TYPE_FTP && mediaDevice->type != DEVICE_TYPE_NFS) { 416 if (!msgYesNo("Would you like to configure any SLIP/PPP or network interface devices?")) { 417 Device *save = mediaDevice; 418 419 /* This will also set the media device, which we don't want */ 420 tcpDeviceSelect(); 421 /* so we restore our saved value below */ 422 mediaDevice = save; 423 dialog_clear_norefresh(); 424 } 425 } 426 427 dialog_clear_norefresh(); 428 if (!msgYesNo("Would you like to configure Samba for connecting NETBUI clients to this\n" 429 "machine? Windows 95, Windows NT and Windows for Workgroups\n" 430 "machines can use NETBUI transport for disk and printer sharing.")) 431 configSamba(self); 432 433 dialog_clear_norefresh(); 434 if (!msgYesNo("Will this machine be an IP gateway (e.g. will it forward packets\n" 435 "between interfaces)?")) 436 variable_set2("gateway", "YES"); 437 438 dialog_clear_norefresh(); 439 if (!msgYesNo("Do you want to allow anonymous FTP connections to this machine?")) 440 configAnonFTP(self); 441 442 dialog_clear_norefresh(); 443 if (!msgYesNo("Do you want to configure this machine as an NFS server?")) 444 configNFSServer(self); 445 446 dialog_clear_norefresh(); 447 if (!msgYesNo("Do you want to configure this machine as an NFS client?")) 448 variable_set2("nfs_client", "YES"); 449 450 dialog_clear_norefresh(); 451 if (!msgYesNo("Do you want to configure this machine as a WEB server?")) 452 configApache(self); 453 454 dialog_clear_norefresh(); 455 if (!msgYesNo("Would you like to customize your system console settings?")) { 456 WINDOW *w = savescr(); 457 458 dmenuOpenSimple(&MenuSyscons, FALSE); 459 restorescr(w); 460 } 461 462 dialog_clear_norefresh(); 463 if (!msgYesNo("Would you like to set this machine's time zone now?")) { 464 WINDOW *w = savescr(); 465 466 dialog_clear(); 467 systemExecute("rm -f /etc/wall_cmos_clock /etc/localtime; tzsetup"); 468 restorescr(w); 469 } 470 471 dialog_clear_norefresh(); 472 if (!msgYesNo("Does this system have a mouse attached to it?")) { 473 WINDOW *w = savescr(); 474 475 dmenuOpenSimple(&MenuMouse, FALSE); 476 restorescr(w); 477 } 478 479 if (directory_exists("/usr/X11R6")) { 480 dialog_clear_norefresh(); 481 if (!msgYesNo("Would you like to configure your X server at this time?")) 482 configXFree86(self); 483 } 484 485 if (cdromMounted) { 486 dialog_clear_norefresh(); 487 if (!msgYesNo("Would you like to link to the ports tree on your CDROM?\n\n" 488 "This will require that you have your FreeBSD CD in the CDROM\n" 489 "drive to use the ports collection, but at a substantial savings\n" 490 "in disk space (NOTE: This may take as long as 15 or 20 minutes\n" 491 "depending on the speed of your CDROM drive).")) 492 configPorts(self); 493 } 494 495 dialog_clear_norefresh(); 496 if (!msgYesNo("The FreeBSD package collection is a collection of over 550 ready-to-run\n" 497 "applications, from text editors to games to WEB servers. Would you like\n" 498 "to browse the collection now?")) 499 configPackages(self); 500 501 /* XXX Put whatever other nice configuration questions you'd like to ask the user here XXX */ 502 503 /* Give user the option of one last configuration spree */ 504 installConfigure(); 505 506 /* Now write out any changes .. */ 507 configResolv(); 508 configSysconfig("/etc/sysconfig"); 509 510 return DITEM_LEAVE_MENU | DITEM_RECREATE; 511} 512 513/* The version of commit we call from the Install Custom menu */ 514int 515installCustomCommit(dialogMenuItem *self) 516{ 517 int i; 518 519 i = installCommit(self); 520 if (DITEM_STATUS(i) == DITEM_SUCCESS) { 521 /* Give user the option of one last configuration spree */ 522 installConfigure(); 523 524 /* Now write out any changes .. */ 525 configResolv(); 526 configSysconfig("/etc/sysconfig"); 527 return i; 528 } 529 else 530 msgConfirm("The commit operation completed with errors. Not\n" 531 "updating /etc files."); 532 return i; 533} 534 535/* 536 * What happens when we finally decide to going ahead with the installation. 537 * 538 * This is broken into multiple stages so that the user can do a full 539 * installation but come back here again to load more distributions, 540 * perhaps from a different media type. This would allow, for 541 * example, the user to load the majority of the system from CDROM and 542 * then use ftp to load just the DES dist. 543 */ 544int 545installCommit(dialogMenuItem *self) 546{ 547 int i; 548 char *str; 549 550 if (!mediaVerify()) 551 return DITEM_FAILURE; 552 553 str = variable_get(SYSTEM_STATE); 554 if (isDebug()) 555 msgDebug("installCommit: System state is `%s'\n", str); 556 557 if (RunningAsInit) { 558 /* Do things we wouldn't do to a multi-user system */ 559 if (DITEM_STATUS((i = installInitial())) == DITEM_FAILURE) 560 return i; 561 if (DITEM_STATUS((i = configFstab())) == DITEM_FAILURE) 562 return i; 563 } 564 565 i = distExtractAll(self); 566 if (DITEM_STATUS(i) != DITEM_FAILURE) 567 i = installFixup(self); 568 else if (!(Dists & DIST_BIN)) 569 (void)installFixup(self); 570 571 variable_set2(SYSTEM_STATE, DITEM_STATUS(i) == DITEM_FAILURE ? "error-install" : "full-install"); 572 return i | DITEM_RECREATE; 573} 574 575static void 576installConfigure(void) 577{ 578 /* Final menu of last resort */ 579 dialog_clear_norefresh(); 580 if (!msgYesNo("Visit the general configuration menu for a chance to set\n" 581 "any last options?")) { 582 WINDOW *w = savescr(); 583 584 dmenuOpenSimple(&MenuConfigure, FALSE); 585 restorescr(w); 586 } 587} 588 589int 590installFixup(dialogMenuItem *self) 591{ 592 Device **devs; 593 int i; 594 595 if (!file_readable("/kernel")) { 596 if (file_readable("/kernel.GENERIC")) { 597 if (vsystem("cp -p /kernel.GENERIC /kernel")) { 598 msgConfirm("Unable to link /kernel into place!"); 599 return DITEM_FAILURE; 600 } 601 } 602 else { 603 msgConfirm("Can't find a kernel image to link to on the root file system!\n" 604 "You're going to have a hard time getting this system to\n" 605 "boot from the hard disk, I'm afraid!"); 606 return DITEM_FAILURE; 607 } 608 } 609 610 /* Snapshot any boot -c changes back to the GENERIC kernel */ 611 save_userconfig_to_kernel("/kernel"); 612 613 /* Resurrect /dev after bin distribution screws it up */ 614 if (RunningAsInit) { 615 msgNotify("Remaking all devices.. Please wait!"); 616 if (vsystem("cd /dev; sh MAKEDEV all")) { 617 msgConfirm("MAKEDEV returned non-zero status"); 618 return DITEM_FAILURE; 619 } 620 621 msgNotify("Resurrecting /dev entries for slices.."); 622 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 623 if (!devs) 624 msgFatal("Couldn't get a disk device list!"); 625 626 /* Resurrect the slices that the former clobbered */ 627 for (i = 0; devs[i]; i++) { 628 Disk *disk = (Disk *)devs[i]->private; 629 Chunk *c1; 630 631 if (!devs[i]->enabled) 632 continue; 633 if (!disk->chunks) 634 msgFatal("No chunk list found for %s!", disk->name); 635 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 636 if (c1->type == freebsd) { 637 msgNotify("Making slice entries for %s", c1->name); 638 if (vsystem("cd /dev; sh MAKEDEV %sh", c1->name)) { 639 msgConfirm("Unable to make slice entries for %s!", c1->name); 640 return DITEM_FAILURE; 641 } 642 } 643 } 644 } 645 /* XXX Do all the last ugly work-arounds here which we'll try and excise someday right?? XXX */ 646 647 msgNotify("Fixing permissions.."); 648 /* BOGON #1: XFree86 extracting /usr/X11R6 with root-only perms */ 649 if (directory_exists("/usr/X11R6")) { 650 vsystem("chmod -R a+r /usr/X11R6"); 651 vsystem("find /usr/X11R6 -type d | xargs chmod a+x"); 652 } 653 /* BOGON #2: We leave /etc in a bad state */ 654 chmod("/etc", 0755); 655 656 /* BOGON #3: No /var/db/mountdtab complains */ 657 Mkdir("/var/db"); 658 creat("/var/db/mountdtab", 0644); 659 660 /* Now run all the mtree stuff to fix things up */ 661 vsystem("mtree -deU -f /etc/mtree/BSD.root.dist -p /"); 662 vsystem("mtree -deU -f /etc/mtree/BSD.var.dist -p /var"); 663 vsystem("mtree -deU -f /etc/mtree/BSD.usr.dist -p /usr"); 664 } 665 return DITEM_SUCCESS; 666} 667 668/* Go newfs and/or mount all the filesystems we've been asked to */ 669int 670installFilesystems(dialogMenuItem *self) 671{ 672 int i; 673 Disk *disk; 674 Chunk *c1, *c2, *rootdev, *swapdev, *usrdev, *vardev; 675 Device **devs; 676 PartInfo *root; 677 char dname[80], *str; 678 extern int MakeDevChunk(Chunk *c, char *n); 679 Boolean upgrade = FALSE; 680 681 str = variable_get(SYSTEM_STATE); 682 683 if (!checkLabels(TRUE, &rootdev, &swapdev, &usrdev, &vardev)) 684 return DITEM_FAILURE; 685 686 if (rootdev) 687 root = (PartInfo *)rootdev->private_data; 688 else 689 root = NULL; 690 691 command_clear(); 692 upgrade = str && !strcmp(str, "upgrade"); 693 694 if (swapdev) { 695 /* As the very first thing, try to get ourselves some swap space */ 696 sprintf(dname, "/dev/%s", swapdev->name); 697 if (!Fake && (!MakeDevChunk(swapdev, "/dev") || !file_readable(dname))) { 698 msgConfirm("Unable to make device node for %s in /dev!\n" 699 "The creation of filesystems will be aborted.", dname); 700 return DITEM_FAILURE; 701 } 702 703 if (!Fake) { 704 if (!swapon(dname)) 705 msgNotify("Added %s as initial swap device", dname); 706 else 707 msgConfirm("WARNING! Unable to swap to %s: %s\n" 708 "This may cause the installation to fail at some point\n" 709 "if you don't have a lot of memory.", dname, strerror(errno)); 710 } 711 } 712 713 if (rootdev) { 714 /* Next, create and/or mount the root device */ 715 sprintf(dname, "/dev/r%sa", rootdev->disk->name); 716 if (!Fake && (!MakeDevChunk(rootdev, "/dev") || !file_readable(dname))) { 717 msgConfirm("Unable to make device node for %s in /dev!\n" 718 "The creation of filesystems will be aborted.", dname); 719 return DITEM_FAILURE; 720 } 721 if (strcmp(root->mountpoint, "/")) 722 msgConfirm("Warning: %s is marked as a root partition but is mounted on %s", rootdev->name, root->mountpoint); 723 724 if (root->newfs) { 725 int i; 726 727 msgNotify("Making a new root filesystem on %s", dname); 728 i = vsystem("%s %s", root->newfs_cmd, dname); 729 if (i) { 730 msgConfirm("Unable to make new root filesystem on %s!\n" 731 "Command returned status %d", dname, i); 732 return DITEM_FAILURE; 733 } 734 } 735 else { 736 if (!upgrade) { 737 msgConfirm("Warning: Using existing root partition. It will be assumed\n" 738 "that you have the appropriate device entries already in /dev."); 739 } 740 msgNotify("Checking integrity of existing %s filesystem.", dname); 741 i = vsystem("fsck -y %s", dname); 742 if (i) 743 msgConfirm("Warning: fsck returned status of %d for %s.\n" 744 "This partition may be unsafe to use.", i, dname); 745 } 746 747 /* Switch to block device */ 748 sprintf(dname, "/dev/%sa", rootdev->disk->name); 749 if (Mount("/mnt", dname)) { 750 msgConfirm("Unable to mount the root file system on %s! Giving up.", dname); 751 return DITEM_FAILURE; 752 } 753 } 754 755 /* Now buzz through the rest of the partitions and mount them too */ 756 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 757 for (i = 0; devs[i]; i++) { 758 if (!devs[i]->enabled) 759 continue; 760 761 disk = (Disk *)devs[i]->private; 762 if (!disk->chunks) { 763 msgConfirm("No chunk list found for %s!", disk->name); 764 return DITEM_FAILURE; 765 } 766 if (root && (root->newfs || upgrade)) { 767 Mkdir("/mnt/dev"); 768 if (!Fake) 769 MakeDevDisk(disk, "/mnt/dev"); 770 } 771 772 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 773 if (c1->type == freebsd) { 774 for (c2 = c1->part; c2; c2 = c2->next) { 775 if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) { 776 PartInfo *tmp = (PartInfo *)c2->private_data; 777 778 /* Already did root */ 779 if (c2 == rootdev) 780 continue; 781 782 if (tmp->newfs) 783 command_shell_add(tmp->mountpoint, "%s /mnt/dev/r%s", tmp->newfs_cmd, c2->name); 784 else 785 command_shell_add(tmp->mountpoint, "fsck -y /mnt/dev/r%s", c2->name); 786 command_func_add(tmp->mountpoint, Mount, c2->name); 787 } 788 else if (c2->type == part && c2->subtype == FS_SWAP) { 789 char fname[80]; 790 int i; 791 792 if (c2 == swapdev) 793 continue; 794 sprintf(fname, "/mnt/dev/%s", c2->name); 795 i = (Fake || swapon(fname)); 796 if (!i) 797 msgNotify("Added %s as an additional swap device", fname); 798 else 799 msgConfirm("Unable to add %s as a swap device: %s", fname, strerror(errno)); 800 } 801 } 802 } 803 else if (c1->type == fat && c1->private_data && (root->newfs || upgrade)) { 804 char name[FILENAME_MAX]; 805 806 sprintf(name, "/mnt%s", ((PartInfo *)c1->private_data)->mountpoint); 807 Mkdir(name); 808 } 809 } 810 } 811 812 msgNotify("Copying initial device files.."); 813 /* Copy the boot floppy's dev files */ 814 if ((root->newfs || upgrade) && vsystem("find -x /dev | cpio %s -pdum /mnt", cpioVerbosity())) { 815 msgConfirm("Couldn't clone the /dev files!"); 816 return DITEM_FAILURE; 817 } 818 819 command_sort(); 820 command_execute(); 821 return DITEM_SUCCESS; 822} 823 824/* Initialize various user-settable values to their defaults */ 825int 826installVarDefaults(dialogMenuItem *self) 827{ 828 char *cp; 829 830 /* Set default startup options */ 831 variable_set2(VAR_ROUTEDFLAGS, "-q"); 832 variable_set2(VAR_RELNAME, RELEASE_NAME); 833 variable_set2(VAR_CPIO_VERBOSITY, "high"); 834 variable_set2(VAR_TAPE_BLOCKSIZE, DEFAULT_TAPE_BLOCKSIZE); 835 variable_set2(VAR_INSTALL_ROOT, "/"); 836 cp = getenv("EDITOR"); 837 if (!cp) 838 cp = "/usr/bin/ee"; 839 variable_set2(VAR_EDITOR, cp); 840 variable_set2(VAR_FTP_USER, "ftp"); 841 variable_set2(VAR_BROWSER_PACKAGE, "lynx-2.5FM"); 842 variable_set2(VAR_BROWSER_BINARY, "/usr/local/bin/lynx"); 843 variable_set2(VAR_FTP_STATE, "passive"); 844 variable_set2(VAR_PKG_TMPDIR, "/usr/tmp"); 845 if (getpid() != 1) 846 variable_set2(SYSTEM_STATE, "update"); 847 else 848 variable_set2(SYSTEM_STATE, "init"); 849 return DITEM_SUCCESS; 850} 851 852/* Copy the boot floppy contents into /stand */ 853Boolean 854copySelf(void) 855{ 856 int i; 857 858 msgWeHaveOutput("Copying the boot floppy to /stand on root filesystem"); 859 i = vsystem("find -x /stand | cpio %s -pdum /mnt", cpioVerbosity()); 860 if (i) { 861 msgConfirm("Copy returned error status of %d!", i); 862 return FALSE; 863 } 864 865 /* Copy the /etc files into their rightful place */ 866 if (vsystem("cd /mnt/stand; find etc | cpio %s -pdum /mnt", cpioVerbosity())) { 867 msgConfirm("Couldn't copy up the /etc files!"); 868 return TRUE; 869 } 870 return TRUE; 871} 872 873static void 874create_termcap(void) 875{ 876 FILE *fp; 877 878 const char *caps[] = { 879 termcap_vt100, termcap_cons25, termcap_cons25_m, termcap_cons25r, 880 termcap_cons25r_m, termcap_cons25l1, termcap_cons25l1_m, NULL, 881 }; 882 const char **cp; 883 884 if (!file_readable(TERMCAP_FILE)) { 885 Mkdir("/usr/share/misc"); 886 fp = fopen(TERMCAP_FILE, "w"); 887 if (!fp) { 888 msgConfirm("Unable to initialize termcap file. Some screen-oriented\nutilities may not work."); 889 return; 890 } 891 cp = caps; 892 while (*cp) 893 fprintf(fp, "%s\n", *(cp++)); 894 fclose(fp); 895 } 896} 897 898static char *isa_list[] = { 899 "device", 900 "ioport", 901 "irq", 902 "drq", 903 "iomem", 904 "iosize", 905 "flags", 906 "alive", 907 "enabled", 908}; 909 910static void 911save_userconfig_to_kernel(char *kern) 912{ 913 struct kernel *core, *boot; 914 struct list *c_isa, *c_dev, *b_dev; 915 int i, d; 916 917 core = uc_open("-incore"); 918 if (!core) { 919 msgDebug("Can't read in-core information for kernel.\n"); 920 return; 921 } 922 923 boot = uc_open(kern); 924 if (!boot) { 925 msgDebug("Can't read device information for kernel image %s\n", kern); 926 return; 927 } 928 msgDebug("Kernel open, getting core ISA devices\n"); 929 c_isa = uc_getdev(core, "-isa"); 930 for (d = 0; d < c_isa->ac; d++) { 931 msgDebug("Outer loop, c_isa->av[%d] = %s\n", d, c_isa->av[d]); 932 if (strcmp(c_isa->av[d], "npx0")) { /* special case npx0, which 933 mucks with its id_irq member */ 934 c_dev = uc_getdev(core, c_isa->av[d]); 935 b_dev = uc_getdev(boot, c_isa->av[d]); 936 for (i = 0; i < c_dev->ac; i++) { 937 msgDebug("Inner loop, c_dev->av[%d] = %s\n", i, c_dev->av[i]); 938 if (strcmp(c_dev->av[i], b_dev->av[i])) { 939 msgDebug("%s %s changed: %s (boot) -> %s (core)\n", 940 c_dev->av[0], isa_list[i], b_dev->av[i], c_dev->av[i]); 941 isa_setdev(boot, c_dev); 942 } 943 } 944 } 945 else 946 msgDebug("skipping npx0\n"); 947 } 948 msgDebug("Closing kernels\n"); 949 uc_close(core, 0); 950 uc_close(boot, 1); 951} 952