install.c revision 129041
1230557Sjimharris/* 2230557Sjimharris * The new sysinstall program. 3230557Sjimharris * 4230557Sjimharris * This is probably the last program in the `sysinstall' line - the next 5230557Sjimharris * generation being essentially a complete rewrite. 6230557Sjimharris * 7230557Sjimharris * $FreeBSD: head/usr.sbin/sade/install.c 129041 2004-05-07 19:15:56Z jhb $ 8230557Sjimharris * 9230557Sjimharris * Copyright (c) 1995 10230557Sjimharris * Jordan Hubbard. All rights reserved. 11230557Sjimharris * 12230557Sjimharris * Redistribution and use in source and binary forms, with or without 13230557Sjimharris * modification, are permitted provided that the following conditions 14230557Sjimharris * are met: 15230557Sjimharris * 1. Redistributions of source code must retain the above copyright 16230557Sjimharris * notice, this list of conditions and the following disclaimer, 17230557Sjimharris * verbatim and that no modifications are made prior to this 18230557Sjimharris * point in the file. 19230557Sjimharris * 2. Redistributions in binary form must reproduce the above copyright 20230557Sjimharris * notice, this list of conditions and the following disclaimer in the 21230557Sjimharris * documentation and/or other materials provided with the distribution. 22230557Sjimharris * 23230557Sjimharris * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND 24230557Sjimharris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25230557Sjimharris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26230557Sjimharris * ARE DISCLAIMED. IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE 27230557Sjimharris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28230557Sjimharris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29230557Sjimharris * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION) 30230557Sjimharris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31230557Sjimharris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32230557Sjimharris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33230557Sjimharris * SUCH DAMAGE. 34230557Sjimharris * 35230557Sjimharris */ 36230557Sjimharris 37230557Sjimharris#include "sysinstall.h" 38230557Sjimharris#include <ctype.h> 39230557Sjimharris#include <sys/disklabel.h> 40230557Sjimharris#include <sys/errno.h> 41230557Sjimharris#include <sys/ioctl.h> 42230557Sjimharris#include <sys/fcntl.h> 43230557Sjimharris#include <sys/wait.h> 44230557Sjimharris#include <sys/uio.h> 45230557Sjimharris#include <sys/param.h> 46230557Sjimharris#define MSDOSFS 47230557Sjimharris#include <sys/mount.h> 48230557Sjimharris#include <ufs/ufs/ufsmount.h> 49230557Sjimharris#include <fs/msdosfs/msdosfsmount.h> 50230557Sjimharris#undef MSDOSFS 51230557Sjimharris#include <sys/stat.h> 52230557Sjimharris#include <sys/sysctl.h> 53230557Sjimharris#include <limits.h> 54230557Sjimharris#include <unistd.h> 55230557Sjimharris#include <termios.h> 56230557Sjimharris 57230557Sjimharris/* Hack for rsaref package add, which displays interactive license. 58230557Sjimharris * Used by package.c 59230557Sjimharris */ 60230557Sjimharrisint _interactiveHack; 61230557Sjimharrisint FixItMode = 0; 62230557Sjimharris 63230557Sjimharrisstatic void create_termcap(void); 64230557Sjimharrisstatic void fixit_common(void); 65230557Sjimharris 66230557Sjimharris#define TERMCAP_FILE "/usr/share/misc/termcap" 67230557Sjimharris 68230557Sjimharrisstatic void installConfigure(void); 69230557Sjimharris 70230557SjimharrisBoolean 71230557SjimharrischeckLabels(Boolean whinge, Chunk **rdev, Chunk **sdev, Chunk **udev, Chunk **vdev, Chunk **tdev, Chunk **hdev) 72230557Sjimharris{ 73230557Sjimharris Device **devs; 74230557Sjimharris Boolean status; 75230557Sjimharris Disk *disk; 76230557Sjimharris Chunk *c1, *c2, *rootdev, *swapdev, *usrdev, *vardev, *tmpdev, *homedev; 77230557Sjimharris int i; 78230557Sjimharris 79230557Sjimharris /* Don't allow whinging if noWarn is set */ 80230557Sjimharris if (variable_get(VAR_NO_WARN)) 81230557Sjimharris whinge = FALSE; 82230557Sjimharris 83230557Sjimharris status = TRUE; 84230557Sjimharris if (rdev) 85230557Sjimharris *rdev = NULL; 86230557Sjimharris if (sdev) 87230557Sjimharris *sdev = NULL; 88230557Sjimharris if (udev) 89230557Sjimharris *udev = NULL; 90230557Sjimharris if (vdev) 91230557Sjimharris *vdev = NULL; 92230557Sjimharris if (tdev) 93230557Sjimharris *tdev = NULL; 94230557Sjimharris if (hdev) 95230557Sjimharris *hdev = NULL; 96230557Sjimharris rootdev = swapdev = usrdev = vardev = tmpdev = homedev = NULL; 97230557Sjimharris 98230557Sjimharris /* We don't need to worry about root/usr/swap if we're already multiuser */ 99230557Sjimharris if (!RunningAsInit) 100230557Sjimharris return status; 101230557Sjimharris 102230557Sjimharris devs = deviceFind(NULL, DEVICE_TYPE_DISK); 103230557Sjimharris /* First verify that we have a root device */ 104230557Sjimharris for (i = 0; devs[i]; i++) { 105230557Sjimharris if (!devs[i]->enabled) 106230557Sjimharris continue; 107230557Sjimharris disk = (Disk *)devs[i]->private; 108230557Sjimharris msgDebug("Scanning disk %s for root filesystem\n", disk->name); 109230557Sjimharris if (!disk->chunks) 110230557Sjimharris msgFatal("No chunk list found for %s!", disk->name); 111230557Sjimharris for (c1 = disk->chunks->part; c1; c1 = c1->next) { 112230557Sjimharris#ifndef __ia64__ 113230557Sjimharris if (c1->type == freebsd) { 114230557Sjimharris for (c2 = c1->part; c2; c2 = c2->next) { 115230557Sjimharris#else 116230557Sjimharris c2 = c1; 117230557Sjimharris#endif 118230557Sjimharris if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) { 119230557Sjimharris if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/")) { 120230557Sjimharris if (rootdev) { 121230557Sjimharris if (whinge) 122230557Sjimharris msgConfirm("WARNING: You have more than one root device set?!\n" 123230557Sjimharris "Using the first one found."); 124230557Sjimharris continue; 125230557Sjimharris } 126230557Sjimharris else { 127230557Sjimharris rootdev = c2; 128230557Sjimharris if (isDebug()) 129230557Sjimharris msgDebug("Found rootdev at %s!\n", rootdev->name); 130230557Sjimharris } 131230557Sjimharris } 132230557Sjimharris else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/usr")) { 133230557Sjimharris if (usrdev) { 134230557Sjimharris if (whinge) 135230557Sjimharris msgConfirm("WARNING: You have more than one /usr filesystem.\n" 136230557Sjimharris "Using the first one found."); 137230557Sjimharris continue; 138230557Sjimharris } 139230557Sjimharris else { 140230557Sjimharris usrdev = c2; 141230557Sjimharris if (isDebug()) 142230557Sjimharris msgDebug("Found usrdev at %s!\n", usrdev->name); 143230557Sjimharris } 144230557Sjimharris } 145230557Sjimharris else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/var")) { 146230557Sjimharris if (vardev) { 147230557Sjimharris if (whinge) 148230557Sjimharris msgConfirm("WARNING: You have more than one /var filesystem.\n" 149230557Sjimharris "Using the first one found."); 150230557Sjimharris continue; 151230557Sjimharris } 152230557Sjimharris else { 153230557Sjimharris vardev = c2; 154230557Sjimharris if (isDebug()) 155230557Sjimharris msgDebug("Found vardev at %s!\n", vardev->name); 156230557Sjimharris } 157230557Sjimharris } else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/tmp")) { 158230557Sjimharris if (tmpdev) { 159230557Sjimharris if (whinge) 160230557Sjimharris msgConfirm("WARNING: You have more than one /tmp filesystem.\n" 161230557Sjimharris "Using the first one found."); 162230557Sjimharris continue; 163230557Sjimharris } 164230557Sjimharris else { 165230557Sjimharris tmpdev = c2; 166230557Sjimharris if (isDebug()) 167230557Sjimharris msgDebug("Found tmpdev at %s!\n", tmpdev->name); 168230557Sjimharris } 169230557Sjimharris } else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/home")) { 170230557Sjimharris if (homedev) { 171230557Sjimharris if (whinge) 172230557Sjimharris msgConfirm("WARNING: You have more than one /home filesystem.\n" 173230557Sjimharris "Using the first one found."); 174239545Sjimharris continue; 175239545Sjimharris } 176230557Sjimharris else { 177230557Sjimharris homedev = c2; 178230557Sjimharris if (isDebug()) 179230557Sjimharris msgDebug("Found homedev at %s!\n", homedev->name); 180230557Sjimharris } 181230557Sjimharris } 182230557Sjimharris } 183230557Sjimharris#ifndef __ia64__ 184230557Sjimharris } 185230557Sjimharris } 186230557Sjimharris#endif 187230557Sjimharris } 188230557Sjimharris } 189230557Sjimharris 190230557Sjimharris /* Now check for swap devices */ 191230557Sjimharris for (i = 0; devs[i]; i++) { 192230557Sjimharris if (!devs[i]->enabled) 193230557Sjimharris continue; 194230557Sjimharris disk = (Disk *)devs[i]->private; 195230557Sjimharris msgDebug("Scanning disk %s for swap partitions\n", disk->name); 196230557Sjimharris if (!disk->chunks) 197230557Sjimharris msgFatal("No chunk list found for %s!", disk->name); 198230557Sjimharris for (c1 = disk->chunks->part; c1; c1 = c1->next) { 199230557Sjimharris#ifndef __ia64__ 200230557Sjimharris if (c1->type == freebsd) { 201230557Sjimharris for (c2 = c1->part; c2; c2 = c2->next) { 202230557Sjimharris#else 203230557Sjimharris c2 = c1; 204230557Sjimharris#endif 205230557Sjimharris if (c2->type == part && c2->subtype == FS_SWAP && !swapdev) { 206230557Sjimharris swapdev = c2; 207230557Sjimharris if (isDebug()) 208230557Sjimharris msgDebug("Found swapdev at %s!\n", swapdev->name); 209230557Sjimharris break; 210230557Sjimharris } 211230557Sjimharris#ifndef __ia64__ 212230557Sjimharris } 213230557Sjimharris } 214230557Sjimharris#endif 215230557Sjimharris } 216230557Sjimharris } 217230557Sjimharris 218230557Sjimharris /* Copy our values over */ 219230557Sjimharris if (rdev) 220230557Sjimharris *rdev = rootdev; 221230557Sjimharris if (sdev) 222230557Sjimharris *sdev = swapdev; 223230557Sjimharris if (udev) 224230557Sjimharris *udev = usrdev; 225230557Sjimharris if (vdev) 226230557Sjimharris *vdev = vardev; 227230557Sjimharris if (tdev) 228230557Sjimharris *tdev = tmpdev; 229230557Sjimharris if (hdev) 230230557Sjimharris *hdev = homedev; 231230557Sjimharris 232230557Sjimharris if (!rootdev && whinge) { 233230557Sjimharris msgConfirm("No root device found - you must label a partition as /\n" 234230557Sjimharris "in the label editor."); 235230557Sjimharris status = FALSE; 236230557Sjimharris } 237230557Sjimharris if (!swapdev && whinge) { 238230557Sjimharris if (msgYesNo("No swap devices found - you should create at least one\n" 239230557Sjimharris "swap partition. Without swap, the install will fail\n" 240230557Sjimharris "if you do not have enough RAM. Continue anyway?")) 241230557Sjimharris status = FALSE; 242230557Sjimharris } 243230557Sjimharris return status; 244230557Sjimharris} 245230557Sjimharris 246230557Sjimharrisstatic int 247230557SjimharrisinstallInitial(void) 248230557Sjimharris{ 249230557Sjimharris static Boolean alreadyDone = FALSE; 250230557Sjimharris int status = DITEM_SUCCESS; 251230557Sjimharris 252230557Sjimharris if (alreadyDone) 253230557Sjimharris return DITEM_SUCCESS; 254230557Sjimharris 255230557Sjimharris if (!variable_get(DISK_LABELLED)) { 256230557Sjimharris msgConfirm("You need to assign disk labels before you can proceed with\n" 257230557Sjimharris "the installation."); 258230557Sjimharris return DITEM_FAILURE; 259230557Sjimharris } 260230557Sjimharris /* If it's labelled, assume it's also partitioned */ 261230557Sjimharris if (!variable_get(DISK_PARTITIONED)) 262230557Sjimharris variable_set2(DISK_PARTITIONED, "yes", 0); 263230557Sjimharris 264230557Sjimharris /* If we refuse to proceed, bail. */ 265230557Sjimharris dialog_clear_norefresh(); 266230557Sjimharris if (!variable_get(VAR_NO_WARN)) { 267230557Sjimharris if (msgYesNo( 268230557Sjimharris "Last Chance! Are you SURE you want continue the installation?\n\n" 269230557Sjimharris "If you're running this on a disk with data you wish to save\n" 270230557Sjimharris "then WE STRONGLY ENCOURAGE YOU TO MAKE PROPER BACKUPS before\n" 271230557Sjimharris "proceeding!\n\n" 272230557Sjimharris "We can take no responsibility for lost disk contents!") != 0) 273230557Sjimharris return DITEM_FAILURE; 274230557Sjimharris } 275230557Sjimharris 276230557Sjimharris if (DITEM_STATUS(diskLabelCommit(NULL)) != DITEM_SUCCESS) { 277230557Sjimharris msgConfirm("Couldn't make filesystems properly. Aborting."); 278230557Sjimharris return DITEM_FAILURE; 279230557Sjimharris } 280230557Sjimharris 281230557Sjimharris if (!copySelf()) { 282230557Sjimharris msgConfirm("installInitial: Couldn't clone the boot floppy onto the\n" 283230557Sjimharris "root file system. Aborting!"); 284230557Sjimharris return DITEM_FAILURE; 285230557Sjimharris } 286230557Sjimharris 287230557Sjimharris if (!Restarting && chroot("/mnt") == -1) { 288230557Sjimharris msgConfirm("installInitial: Unable to chroot to %s - this is bad!", 289230557Sjimharris "/mnt"); 290230557Sjimharris return DITEM_FAILURE; 291230557Sjimharris } 292230557Sjimharris 293230557Sjimharris chdir("/"); 294230557Sjimharris variable_set2(RUNNING_ON_ROOT, "yes", 0); 295230557Sjimharris 296230557Sjimharris /* Configure various files in /etc */ 297230557Sjimharris if (DITEM_STATUS(configResolv(NULL)) == DITEM_FAILURE) 298230557Sjimharris status = DITEM_FAILURE; 299230557Sjimharris if (DITEM_STATUS(configFstab(NULL)) == DITEM_FAILURE) 300230557Sjimharris status = DITEM_FAILURE; 301230557Sjimharris 302230557Sjimharris /* stick a helpful shell over on the 4th VTY */ 303230557Sjimharris if (!variable_get(VAR_NO_HOLOSHELL)) 304230557Sjimharris systemCreateHoloshell(); 305230557Sjimharris 306230557Sjimharris alreadyDone = TRUE; 307230557Sjimharris return status; 308230557Sjimharris} 309230557Sjimharris 310230557Sjimharrisint 311230557SjimharrisinstallFixitHoloShell(dialogMenuItem *self) 312230557Sjimharris{ 313230557Sjimharris FixItMode = 1; 314230557Sjimharris systemCreateHoloshell(); 315230557Sjimharris return DITEM_SUCCESS; 316230557Sjimharris FixItMode = 0; 317230557Sjimharris} 318230557Sjimharris 319230557Sjimharrisint 320230557SjimharrisinstallFixitCDROM(dialogMenuItem *self) 321230557Sjimharris{ 322230557Sjimharris struct stat sb; 323230557Sjimharris 324230557Sjimharris if (!RunningAsInit) 325230557Sjimharris return DITEM_SUCCESS; 326230557Sjimharris 327230557Sjimharris variable_set2(SYSTEM_STATE, "fixit", 0); 328230557Sjimharris (void)unlink("/mnt2"); 329230557Sjimharris (void)rmdir("/mnt2"); 330230557Sjimharris 331230557Sjimharris while (1) { 332230557Sjimharris msgConfirm("Please insert a FreeBSD live filesystem CD/DVD and press return"); 333230557Sjimharris if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS 334230557Sjimharris || !DEVICE_INIT(mediaDevice)) { 335230557Sjimharris /* If we can't initialize it, it's probably not a FreeBSD CDROM so punt on it */ 336230557Sjimharris mediaClose(); 337230557Sjimharris if (msgYesNo("Unable to mount the disc - do you want to try again?") != 0) 338230557Sjimharris return DITEM_FAILURE; 339230557Sjimharris } 340230557Sjimharris else 341230557Sjimharris break; 342230557Sjimharris } 343230557Sjimharris 344230557Sjimharris /* Since the fixit code expects everything to be in /mnt2, and the CDROM mounting stuff /dist, do 345230557Sjimharris * a little kludge dance here.. 346230557Sjimharris */ 347230557Sjimharris if (symlink("/dist", "/mnt2")) { 348230557Sjimharris msgConfirm("Unable to symlink /mnt2 to the disc mount point. Please report this\n" 349230557Sjimharris "unexpected failure to freebsd-bugs@FreeBSD.org."); 350230557Sjimharris return DITEM_FAILURE; 351230557Sjimharris } 352230557Sjimharris 353230557Sjimharris /* 354230557Sjimharris * If /tmp points to /mnt2/tmp from a previous fixit floppy session, it's 355230557Sjimharris * not very good for us if we point it to the CDROM now. Rather make it 356230557Sjimharris * a directory in the root MFS then. Experienced admins will still be 357230557Sjimharris * able to mount their disk's /tmp over this if they need. 358230557Sjimharris */ 359230557Sjimharris if (lstat("/tmp", &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFLNK) 360230557Sjimharris (void)unlink("/tmp"); 361230557Sjimharris Mkdir("/tmp"); 362230557Sjimharris 363230557Sjimharris /* 364230557Sjimharris * Since setuid binaries ignore LD_LIBRARY_PATH, we indeed need the 365230557Sjimharris * ld.so.hints file. Fortunately, it's fairly small (~ 3 KB). 366230557Sjimharris */ 367230557Sjimharris if (!file_readable("/var/run/ld.so.hints")) { 368230557Sjimharris Mkdir("/var/run"); 369230557Sjimharris if (vsystem("/mnt2/rescue/ldconfig -s /mnt2/lib /mnt2/usr/lib")) { 370230557Sjimharris msgConfirm("Warning: ldconfig could not create the ld.so hints file.\n" 371230557Sjimharris "Dynamic executables from the disc likely won't work."); 372230557Sjimharris } 373230557Sjimharris } 374230557Sjimharris 375230557Sjimharris /* Yet more iggly hardcoded pathnames. */ 376230557Sjimharris Mkdir("/libexec"); 377230557Sjimharris if (!file_readable("/libexec/ld.so") && file_readable("/mnt2/libexec/ld.so")) { 378230557Sjimharris if (symlink("/mnt2/libexec/ld.so", "/libexec/ld.so")) 379230557Sjimharris msgDebug("Couldn't link to ld.so - not necessarily a problem for ELF\n"); 380230557Sjimharris } 381230557Sjimharris if (!file_readable("/libexec/ld-elf.so.1")) { 382230557Sjimharris if (symlink("/mnt2/libexec/ld-elf.so.1", "/libexec/ld-elf.so.1")) { 383230557Sjimharris msgConfirm("Warning: could not create the symlink for ld-elf.so.1\n" 384230557Sjimharris "Dynamic executables from the disc likely won't work."); 385230557Sjimharris } 386230557Sjimharris } 387230557Sjimharris /* optional nicety */ 388230557Sjimharris if (!file_readable("/usr/bin/vi")) 389230557Sjimharris symlink("/mnt2/usr/bin/vi", "/usr/bin/vi"); 390230557Sjimharris fixit_common(); 391230557Sjimharris mediaClose(); 392230557Sjimharris msgConfirm("Please remove the FreeBSD fixit CDROM/DVD now."); 393230557Sjimharris return DITEM_SUCCESS; 394230557Sjimharris} 395230557Sjimharris 396230557Sjimharrisint 397230557SjimharrisinstallFixitFloppy(dialogMenuItem *self) 398230557Sjimharris{ 399230557Sjimharris struct ufs_args args; 400230557Sjimharris extern char *distWanted; 401231296Sjimharris 402230557Sjimharris if (!RunningAsInit) 403230557Sjimharris return DITEM_SUCCESS; 404230557Sjimharris 405230557Sjimharris /* Try to open the floppy drive */ 406230557Sjimharris if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE || !mediaDevice) { 407230557Sjimharris msgConfirm("Unable to set media device to floppy."); 408230557Sjimharris mediaClose(); 409230557Sjimharris return DITEM_FAILURE; 410230557Sjimharris } 411230557Sjimharris 412230557Sjimharris memset(&args, 0, sizeof(args)); 413230557Sjimharris args.fspec = mediaDevice->devname; 414230557Sjimharris mediaDevice->private = "/mnt2"; 415230557Sjimharris distWanted = NULL; 416230557Sjimharris Mkdir("/mnt2"); 417230557Sjimharris 418230557Sjimharris variable_set2(SYSTEM_STATE, "fixit", 0); 419230557Sjimharris 420230557Sjimharris while (1) { 421230557Sjimharris if (!DEVICE_INIT(mediaDevice)) { 422230557Sjimharris if (msgYesNo("The attempt to mount the fixit floppy failed, bad floppy\n" 423230557Sjimharris "or unclean filesystem. Do you want to try again?")) 424230557Sjimharris return DITEM_FAILURE; 425230557Sjimharris } 426230557Sjimharris else 427230557Sjimharris break; 428230557Sjimharris } 429230557Sjimharris if (!directory_exists("/tmp")) 430230557Sjimharris (void)symlink("/mnt2/tmp", "/tmp"); 431230557Sjimharris fixit_common(); 432230557Sjimharris mediaClose(); 433230557Sjimharris msgConfirm("Please remove the fixit floppy now."); 434230557Sjimharris return DITEM_SUCCESS; 435230557Sjimharris} 436230557Sjimharris 437230557Sjimharris/* 438230557Sjimharris * The common code for both fixit variants. 439230557Sjimharris */ 440230557Sjimharrisstatic void 441230557Sjimharrisfixit_common(void) 442230557Sjimharris{ 443230557Sjimharris pid_t child; 444230557Sjimharris int waitstatus; 445230557Sjimharris 446230557Sjimharris if (!directory_exists("/var/tmp/vi.recover")) { 447230557Sjimharris if (DITEM_STATUS(Mkdir("/var/tmp/vi.recover")) != DITEM_SUCCESS) { 448230557Sjimharris msgConfirm("Warning: Was unable to create a /var/tmp/vi.recover directory.\n" 449230557Sjimharris "vi will kvetch and moan about it as a result but should still\n" 450230557Sjimharris "be essentially usable."); 451230557Sjimharris } 452230557Sjimharris } 453230557Sjimharris if (!directory_exists("/bin")) 454230557Sjimharris (void)Mkdir("/bin"); 455230557Sjimharris (void)symlink("/stand/sh", "/bin/sh"); 456230557Sjimharris /* Link the /etc/ files */ 457230557Sjimharris if (DITEM_STATUS(Mkdir("/etc")) != DITEM_SUCCESS) 458230557Sjimharris msgConfirm("Unable to create an /etc directory! Things are weird on this floppy.."); 459230557Sjimharris else if ((symlink("/mnt2/etc/spwd.db", "/etc/spwd.db") == -1 && errno != EEXIST) || 460230557Sjimharris (symlink("/mnt2/etc/protocols", "/etc/protocols") == -1 && errno != EEXIST) || 461230557Sjimharris (symlink("/mnt2/etc/group", "/etc/group") == -1 && errno != EEXIST) || 462230557Sjimharris (symlink("/mnt2/etc/services", "/etc/services") == -1 && errno != EEXIST)) 463230557Sjimharris msgConfirm("Couldn't symlink the /etc/ files! I'm not sure I like this.."); 464230557Sjimharris if (!file_readable(TERMCAP_FILE)) 465230557Sjimharris create_termcap(); 466230557Sjimharris if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) 467230557Sjimharris systemSuspendDialog(); /* must be before the fork() */ 468230557Sjimharris if (!(child = fork())) { 469230557Sjimharris int i, fd; 470230557Sjimharris struct termios foo; 471230557Sjimharris extern int login_tty(int); 472230557Sjimharris 473230557Sjimharris ioctl(0, TIOCNOTTY, NULL); 474230557Sjimharris for (i = getdtablesize(); i >= 0; --i) 475230557Sjimharris close(i); 476230557Sjimharris 477230557Sjimharris if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) 478230557Sjimharris fd = open("/dev/console", O_RDWR); 479230557Sjimharris else 480230557Sjimharris fd = open("/dev/ttyv3", O_RDWR); 481230557Sjimharris ioctl(0, TIOCSCTTY, &fd); 482230557Sjimharris dup2(0, 1); 483230557Sjimharris dup2(0, 2); 484230557Sjimharris DebugFD = 2; 485230557Sjimharris if (login_tty(fd) == -1) 486230557Sjimharris msgDebug("fixit: I can't set the controlling terminal.\n"); 487230557Sjimharris 488230557Sjimharris signal(SIGTTOU, SIG_IGN); 489230557Sjimharris if (tcgetattr(0, &foo) != -1) { 490230557Sjimharris foo.c_cc[VERASE] = '\010'; 491230557Sjimharris if (tcsetattr(0, TCSANOW, &foo) == -1) 492230557Sjimharris msgDebug("fixit shell: Unable to set erase character.\n"); 493230557Sjimharris } 494230557Sjimharris else 495230557Sjimharris msgDebug("fixit shell: Unable to get terminal attributes!\n"); 496230557Sjimharris setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/stand:" 497230557Sjimharris "/mnt2/stand:/mnt2/bin:/mnt2/sbin:/mnt2/usr/bin:/mnt2/usr/sbin", 1); 498230557Sjimharris if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) { 499230557Sjimharris printf("Waiting for fixit shell to exit.\n" 500230557Sjimharris "When you are done, type ``exit'' to exit\n" 501230557Sjimharris "the fixit shell and be returned here.\n\n"); 502230557Sjimharris fflush(stdout); 503230557Sjimharris } 504230557Sjimharris 505230557Sjimharris /* use the .profile from the fixit medium */ 506230557Sjimharris setenv("HOME", "/mnt2", 1); 507230557Sjimharris chdir("/mnt2"); 508230557Sjimharris execlp("sh", "-sh", (char *)0); 509230557Sjimharris msgDebug("fixit shell: Failed to execute shell!\n"); 510230557Sjimharris _exit(1);; 511230557Sjimharris } 512230557Sjimharris else { 513230557Sjimharris if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) { 514230557Sjimharris dialog_clear_norefresh(); 515230557Sjimharris msgNotify("Waiting for fixit shell to exit. Go to VTY4 now by\n" 516230557Sjimharris "typing ALT-F4. When you are done, type ``exit'' to exit\n" 517230557Sjimharris "the fixit shell and be returned here\n."); 518230557Sjimharris } 519230557Sjimharris (void)waitpid(child, &waitstatus, 0); 520230557Sjimharris if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) 521230557Sjimharris systemResumeDialog(); 522230557Sjimharris } 523230557Sjimharris dialog_clear(); 524230557Sjimharris} 525230557Sjimharris 526230557Sjimharris 527230557Sjimharrisint 528230557SjimharrisinstallExpress(dialogMenuItem *self) 529230557Sjimharris{ 530230557Sjimharris int i; 531230557Sjimharris 532230557Sjimharris dialog_clear_norefresh(); 533230557Sjimharris variable_set2(SYSTEM_STATE, "express", 0); 534230557Sjimharris#ifdef WITH_SLICES 535230557Sjimharris if (DITEM_STATUS((i = diskPartitionEditor(self))) == DITEM_FAILURE) 536230557Sjimharris return i; 537230557Sjimharris#endif 538230557Sjimharris 539230557Sjimharris if (DITEM_STATUS((i = diskLabelEditor(self))) == DITEM_FAILURE) 540230557Sjimharris return i; 541230557Sjimharris 542230557Sjimharris if (DITEM_STATUS((i = installCommit(self))) == DITEM_SUCCESS) { 543230557Sjimharris i |= DITEM_LEAVE_MENU; 544230557Sjimharris 545230557Sjimharris /* Give user the option of one last configuration spree */ 546230557Sjimharris installConfigure(); 547230557Sjimharris } 548230557Sjimharris return i; 549230557Sjimharris} 550230557Sjimharris 551230557Sjimharris/* Standard mode installation */ 552230557Sjimharrisint 553230557SjimharrisinstallStandard(dialogMenuItem *self) 554230557Sjimharris{ 555230557Sjimharris int i, tries = 0; 556230557Sjimharris Device **devs; 557230557Sjimharris 558230557Sjimharris variable_set2(SYSTEM_STATE, "standard", 0); 559230557Sjimharris dialog_clear_norefresh(); 560230557Sjimharris#ifdef WITH_SLICES 561230557Sjimharris msgConfirm("In the next menu, you will need to set up a DOS-style (\"fdisk\") partitioning\n" 562230557Sjimharris "scheme for your hard disk. If you simply wish to devote all disk space\n" 563230557Sjimharris "to FreeBSD (overwriting anything else that might be on the disk(s) selected)\n" 564230557Sjimharris "then use the (A)ll command to select the default partitioning scheme followed\n" 565230557Sjimharris "by a (Q)uit. If you wish to allocate only free space to FreeBSD, move to a\n" 566230557Sjimharris "partition marked \"unused\" and use the (C)reate command."); 567230557Sjimharris 568230557Sjimharrisnodisks: 569230557Sjimharris if (DITEM_STATUS(diskPartitionEditor(self)) == DITEM_FAILURE) 570230557Sjimharris return DITEM_FAILURE; 571230557Sjimharris 572230557Sjimharris if (diskGetSelectCount(&devs) <= 0 && tries < 3) { 573230557Sjimharris msgConfirm("You need to select some disks to operate on! Be sure to use SPACE\n" 574230557Sjimharris "instead of RETURN in the disk selection menu when selecting a disk."); 575230557Sjimharris ++tries; 576230557Sjimharris goto nodisks; 577230557Sjimharris } 578230557Sjimharris 579230557Sjimharris msgConfirm("Now you need to create BSD partitions inside of the fdisk partition(s)\n" 580230557Sjimharris "just created. If you have a reasonable amount of disk space (200MB or more)\n" 581230557Sjimharris "and don't have any special requirements, simply use the (A)uto command to\n" 582230557Sjimharris "allocate space automatically. If you have more specific needs or just don't\n" 583230557Sjimharris "care for the layout chosen by (A)uto, press F1 for more information on\n" 584230557Sjimharris "manual layout."); 585230557Sjimharris#else 586230557Sjimharris msgConfirm("First you need to create BSD partitions on the disk which you are\n" 587230557Sjimharris "installing to. If you have a reasonable amount of disk space (200MB or more)\n" 588230557Sjimharris "and don't have any special requirements, simply use the (A)uto command to\n" 589230557Sjimharris "allocate space automatically. If you have more specific needs or just don't\n" 590230557Sjimharris "care for the layout chosen by (A)uto, press F1 for more information on\n" 591230557Sjimharris "manual layout."); 592230557Sjimharris#endif 593230557Sjimharris 594230557Sjimharris if (DITEM_STATUS(diskLabelEditor(self)) == DITEM_FAILURE) 595230557Sjimharris return DITEM_FAILURE; 596230557Sjimharris 597230557Sjimharris if (DITEM_STATUS((i = installCommit(self))) == DITEM_FAILURE) { 598230557Sjimharris dialog_clear(); 599230557Sjimharris msgConfirm("Installation completed with some errors. You may wish to\n" 600230557Sjimharris "scroll through the debugging messages on VTY1 with the\n" 601230557Sjimharris "scroll-lock feature. You can also choose \"No\" at the next\n" 602230557Sjimharris "prompt and go back into the installation menus to retry\n" 603230557Sjimharris "whichever operations have failed."); 604230557Sjimharris return i; 605230557Sjimharris 606230557Sjimharris } 607230557Sjimharris else { 608230557Sjimharris dialog_clear(); 609230557Sjimharris msgConfirm("Congratulations! You now have FreeBSD installed on your system.\n\n" 610230557Sjimharris "We will now move on to the final configuration questions.\n" 611230557Sjimharris "For any option you do not wish to configure, simply select\n" 612230557Sjimharris "No.\n\n" 613230557Sjimharris "If you wish to re-enter this utility after the system is up, you\n" 614230557Sjimharris "may do so by typing: /usr/sbin/sysinstall."); 615230557Sjimharris } 616230557Sjimharris if (mediaDevice->type != DEVICE_TYPE_FTP && mediaDevice->type != DEVICE_TYPE_NFS) { 617230557Sjimharris if (!msgYesNo("Would you like to configure any Ethernet or SLIP/PPP network devices?")) { 618230557Sjimharris Device *tmp = tcpDeviceSelect(); 619230557Sjimharris 620230557Sjimharris if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name)) 621230557Sjimharris if (!DEVICE_INIT(tmp)) 622230557Sjimharris msgConfirm("Initialization of %s device failed.", tmp->name); 623230557Sjimharris } 624230557Sjimharris dialog_clear_norefresh(); 625230557Sjimharris } 626 627 if (!msgNoYes("Do you want this machine to function as a network gateway?")) 628 variable_set2("gateway_enable", "YES", 1); 629 630 dialog_clear_norefresh(); 631 if (!msgNoYes("Do you want to configure inetd and the network services that it provides?")) 632 configInetd(self); 633 634 dialog_clear_norefresh(); 635 if (!msgNoYes("Would you like to enable SSH login?")) 636 variable_set2("sshd_enable", "YES", 1); 637 638 dialog_clear_norefresh(); 639 if (!msgNoYes("Do you want to have anonymous FTP access to this machine?")) 640 configAnonFTP(self); 641 642 dialog_clear_norefresh(); 643 if (!msgNoYes("Do you want to configure this machine as an NFS server?")) 644 configNFSServer(self); 645 646 dialog_clear_norefresh(); 647 if (!msgNoYes("Do you want to configure this machine as an NFS client?")) 648 variable_set2("nfs_client_enable", "YES", 1); 649 650#ifdef WITH_SYSCONS 651 dialog_clear_norefresh(); 652 if (!msgNoYes("Would you like to customize your system console settings?")) 653 dmenuOpenSimple(&MenuSyscons, FALSE); 654#endif 655 656 dialog_clear_norefresh(); 657 if (!msgYesNo("Would you like to set this machine's time zone now?")) 658 systemExecute("tzsetup"); 659 660#ifdef WITH_LINUX 661 dialog_clear_norefresh(); 662 if (!msgYesNo("Would you like to enable Linux binary compatibility?")) 663 (void)configLinux(self); 664#endif 665 666#ifdef __alpha__ 667 dialog_clear_norefresh(); 668 if (!msgYesNo("Would you like to enable OSF/1 binary compatibility?")) 669 (void)configOSF1(self); 670#endif 671 672#ifdef WITH_MICE 673 dialog_clear_norefresh(); 674 if (!msgNoYes("Does this system have a PS/2, serial, or bus mouse?")) 675 dmenuOpenSimple(&MenuMouse, FALSE); 676#endif 677 678#ifdef __i386__ 679 if (checkLoaderACPI() != 0) { 680 dialog_clear_norefresh(); 681 if (!msgNoYes("ACPI was disabled during boot.\n" 682 "Would you like to disable it permanently?")) 683 (void)configLoaderACPI(1 /*disable*/); 684 } 685#endif 686 687 /* Now would be a good time to checkpoint the configuration data */ 688 configRC_conf(); 689 sync(); 690 691 if (directory_exists("/usr/X11R6")) { 692 dialog_clear_norefresh(); 693 if (!msgYesNo("Would you like to configure your X server at this time?")) 694 (void)configXSetup(self); 695 } 696 697 dialog_clear_norefresh(); 698 if (!msgYesNo("The FreeBSD package collection is a collection of thousands of ready-to-run\n" 699 "applications, from text editors to games to WEB servers and more. Would you\n" 700 "like to browse the collection now?")) { 701 (void)configPackages(self); 702 } 703 704 if (!msgYesNo("Would you like to add any initial user accounts to the system?\n" 705 "Adding at least one account for yourself at this stage is suggested\n" 706 "since working as the \"root\" user is dangerous (it is easy to do\n" 707 "things which adversely affect the entire system).")) 708 (void)configUsers(self); 709 710 msgConfirm("Now you must set the system manager's password.\n" 711 "This is the password you'll use to log in as \"root\"."); 712 if (!systemExecute("passwd root")) 713 variable_set2("root_password", "YES", 0); 714 715 /* XXX Put whatever other nice configuration questions you'd like to ask the user here XXX */ 716 717 /* Give user the option of one last configuration spree */ 718 dialog_clear_norefresh(); 719 installConfigure(); 720 return DITEM_LEAVE_MENU; 721} 722 723/* The version of commit we call from the Install Custom menu */ 724int 725installCustomCommit(dialogMenuItem *self) 726{ 727 int i; 728 729 i = installCommit(self); 730 if (DITEM_STATUS(i) == DITEM_SUCCESS) { 731 /* Give user the option of one last configuration spree */ 732 installConfigure(); 733 return i; 734 } 735 else 736 msgConfirm("The commit operation completed with errors. Not\n" 737 "updating /etc files."); 738 return i; 739} 740 741/* 742 * What happens when we finally decide to going ahead with the installation. 743 * 744 * This is broken into multiple stages so that the user can do a full 745 * installation but come back here again to load more distributions, 746 * perhaps from a different media type. This would allow, for 747 * example, the user to load the majority of the system from CDROM and 748 * then use ftp to load just the CRYPTO dist. 749 */ 750int 751installCommit(dialogMenuItem *self) 752{ 753 int i; 754 char *str; 755 756 dialog_clear_norefresh(); 757 if (!Dists) 758 distConfig(NULL); 759 760 if (!Dists) { 761 (void)dmenuOpenSimple(&MenuDistributions, FALSE); 762 /* select reasonable defaults if necessary */ 763 if (!Dists) 764 Dists = _DIST_USER; 765 } 766 767 if (!mediaVerify()) 768 return DITEM_FAILURE; 769 770 str = variable_get(SYSTEM_STATE); 771 if (isDebug()) 772 msgDebug("installCommit: System state is `%s'\n", str); 773 774 /* Installation stuff we wouldn't do to a running system */ 775 if (RunningAsInit && DITEM_STATUS((i = installInitial())) == DITEM_FAILURE) 776 return i; 777 778try_media: 779 if (!DEVICE_INIT(mediaDevice)) { 780 if (!msgYesNo("Unable to initialize selected media. Would you like to\n" 781 "adjust your media configuration and try again?")) { 782 mediaDevice = NULL; 783 if (!mediaVerify()) 784 return DITEM_FAILURE; 785 else 786 goto try_media; 787 } 788 else 789 return DITEM_FAILURE; 790 } 791 792 /* Now go get it all */ 793 i = distExtractAll(self); 794 795 /* When running as init, *now* it's safe to grab the rc.foo vars */ 796 installEnvironment(); 797 798 variable_set2(SYSTEM_STATE, DITEM_STATUS(i) == DITEM_FAILURE ? "error-install" : "full-install", 0); 799 800 return i; 801} 802 803static void 804installConfigure(void) 805{ 806 /* Final menu of last resort */ 807 if (!msgNoYes("Visit the general configuration menu for a chance to set\n" 808 "any last options?")) 809 dmenuOpenSimple(&MenuConfigure, FALSE); 810 configRC_conf(); 811 sync(); 812} 813 814int 815installFixupBase(dialogMenuItem *self) 816{ 817 FILE *fp; 818 int kstat = 1; 819 820 /* All of this is done only as init, just to be safe */ 821 if (RunningAsInit) { 822#if defined(__i386__) || defined(__amd64__) 823 if ((fp = fopen("/boot/loader.conf", "a")) != NULL) { 824 if (!kstat || !OnVTY) 825 fprintf(fp, "# -- sysinstall generated deltas -- #\n"); 826 if (!kstat) 827 fprintf(fp, "userconfig_script_load=\"YES\"\n"); 828 if (!OnVTY) 829 fprintf(fp, "console=\"comconsole\"\n"); 830 fclose(fp); 831 } 832#endif 833 834 /* BOGON #2: We leave /etc in a bad state */ 835 chmod("/etc", 0755); 836 837 /* BOGON #3: No /var/db/mountdtab complains */ 838 Mkdir("/var/db"); 839 creat("/var/db/mountdtab", 0644); 840 841 /* BOGON #4: /compat created by default in root fs */ 842 Mkdir("/usr/compat"); 843 vsystem("ln -s usr/compat /compat"); 844 845 /* BOGON #5: aliases database not build for bin */ 846 vsystem("newaliases"); 847 848 /* Now run all the mtree stuff to fix things up */ 849 vsystem("mtree -deU -f /etc/mtree/BSD.root.dist -p /"); 850 vsystem("mtree -deU -f /etc/mtree/BSD.var.dist -p /var"); 851 vsystem("mtree -deU -f /etc/mtree/BSD.usr.dist -p /usr"); 852 853 /* Do all the last ugly work-arounds here */ 854 } 855 return DITEM_SUCCESS | DITEM_RESTORE; 856} 857 858#define QUEUE_YES 1 859#define QUEUE_NO 0 860static int 861performNewfs(PartInfo *pi, char *dname, int queue) 862{ 863 char buffer[LINE_MAX]; 864 865 if (pi->do_newfs) { 866 switch(pi->newfs_type) { 867 case NEWFS_UFS: 868 snprintf(buffer, LINE_MAX, "%s %s %s %s %s", 869 NEWFS_UFS_CMD, 870 pi->newfs_data.newfs_ufs.softupdates ? "-U" : "", 871 pi->newfs_data.newfs_ufs.ufs1 ? "-O1" : "-O2", 872 pi->newfs_data.newfs_ufs.user_options, 873 dname); 874 break; 875 876 case NEWFS_MSDOS: 877 snprintf(buffer, LINE_MAX, "%s %s", NEWFS_MSDOS_CMD, 878 dname); 879 break; 880 881 case NEWFS_CUSTOM: 882 snprintf(buffer, LINE_MAX, "%s %s", 883 pi->newfs_data.newfs_custom.command, dname); 884 break; 885 } 886 887 if (queue == QUEUE_YES) { 888 command_shell_add(pi->mountpoint, buffer); 889 return (0); 890 } else 891 return (vsystem(buffer)); 892 } 893 return (0); 894} 895 896/* Go newfs and/or mount all the filesystems we've been asked to */ 897int 898installFilesystems(dialogMenuItem *self) 899{ 900 int i; 901 Disk *disk; 902 Chunk *c1, *c2, *rootdev, *swapdev; 903 Device **devs; 904 PartInfo *root; 905 char dname[80]; 906 Boolean upgrade = FALSE; 907#if defined(__ia64__) 908 char efi_bootdir[FILENAME_MAX]; 909#endif 910 911 /* If we've already done this, bail out */ 912 if (!variable_cmp(DISK_LABELLED, "written")) 913 return DITEM_SUCCESS; 914 915 upgrade = !variable_cmp(SYSTEM_STATE, "upgrade"); 916 if (!checkLabels(TRUE, &rootdev, &swapdev, NULL, NULL, NULL, NULL)) 917 return DITEM_FAILURE; 918 919 if (rootdev) 920 root = (PartInfo *)rootdev->private_data; 921 else 922 root = NULL; 923 924 command_clear(); 925 if (swapdev && RunningAsInit) { 926 /* As the very first thing, try to get ourselves some swap space */ 927 sprintf(dname, "/dev/%s", swapdev->name); 928 if (!Fake && !file_readable(dname)) { 929 msgConfirm("Unable to find device node for %s in /dev!\n" 930 "The creation of filesystems will be aborted.", dname); 931 return DITEM_FAILURE; 932 } 933 934 if (!Fake) { 935 if (!swapon(dname)) { 936 dialog_clear_norefresh(); 937 msgNotify("Added %s as initial swap device", dname); 938 } 939 else { 940 msgConfirm("WARNING! Unable to swap to %s: %s\n" 941 "This may cause the installation to fail at some point\n" 942 "if you don't have a lot of memory.", dname, strerror(errno)); 943 } 944 } 945 } 946 947 if (rootdev && RunningAsInit) { 948 /* Next, create and/or mount the root device */ 949 sprintf(dname, "/dev/%s", rootdev->name); 950 if (!Fake && !file_readable(dname)) { 951 msgConfirm("Unable to make device node for %s in /dev!\n" 952 "The creation of filesystems will be aborted.", dname); 953 return DITEM_FAILURE | DITEM_RESTORE; 954 } 955 if (strcmp(root->mountpoint, "/")) 956 msgConfirm("Warning: %s is marked as a root partition but is mounted on %s", rootdev->name, root->mountpoint); 957 958 if (root->do_newfs && (!upgrade || 959 !msgNoYes("You are upgrading - are you SURE you want to newfs " 960 "the root partition?"))) { 961 int i; 962 963 dialog_clear_norefresh(); 964 msgNotify("Making a new root filesystem on %s", dname); 965 i = performNewfs(root, dname, QUEUE_NO); 966 if (i) { 967 msgConfirm("Unable to make new root filesystem on %s!\n" 968 "Command returned status %d", dname, i); 969 return DITEM_FAILURE | DITEM_RESTORE; 970 } 971 } 972 else { 973 if (!upgrade) { 974 msgConfirm("Warning: Using existing root partition. It will be assumed\n" 975 "that you have the appropriate device entries already in /dev."); 976 } 977 dialog_clear_norefresh(); 978 msgNotify("Checking integrity of existing %s filesystem.", dname); 979 i = vsystem("fsck_ffs -y %s", dname); 980 if (i) 981 msgConfirm("Warning: fsck returned status of %d for %s.\n" 982 "This partition may be unsafe to use.", i, dname); 983 } 984 985 /* 986 * If soft updates was enabled in the editor but we didn't newfs, 987 * use tunefs to update the soft updates flag on the file system. 988 */ 989 if (!root->do_newfs && root->newfs_type == NEWFS_UFS && 990 root->newfs_data.newfs_ufs.softupdates) { 991 i = vsystem("tunefs -n enable %s", dname); 992 if (i) 993 msgConfirm("Warning: Unable to enable soft updates" 994 " for root file system on %s", dname); 995 } 996 997 /* Switch to block device */ 998 sprintf(dname, "/dev/%s", rootdev->name); 999 if (Mount("/mnt", dname)) { 1000 msgConfirm("Unable to mount the root file system on %s! Giving up.", dname); 1001 return DITEM_FAILURE | DITEM_RESTORE; 1002 } 1003 1004 /* Mount devfs for other partitions to mount */ 1005 Mkdir("/mnt/dev"); 1006 if (!Fake) { 1007 struct iovec iov[4]; 1008 1009 iov[0].iov_base = "fstype"; 1010 iov[0].iov_len = strlen(iov[0].iov_base) + 1; 1011 iov[1].iov_base = "devfs"; 1012 iov[1].iov_len = strlen(iov[1].iov_base) + 1; 1013 iov[2].iov_base = "fspath"; 1014 iov[2].iov_len = strlen(iov[2].iov_base) + 1; 1015 iov[3].iov_base = "/mnt/dev"; 1016 iov[3].iov_len = strlen(iov[3].iov_base) + 1; 1017 i = nmount(iov, 4, 0); 1018 1019 if (i) { 1020 dialog_clear_norefresh(); 1021 msgConfirm("Unable to mount DEVFS (error %d)", errno); 1022 return DITEM_FAILURE | DITEM_RESTORE; 1023 } 1024 } 1025 } 1026 1027 /* Now buzz through the rest of the partitions and mount them too */ 1028 devs = deviceFind(NULL, DEVICE_TYPE_DISK); 1029 for (i = 0; devs[i]; i++) { 1030 if (!devs[i]->enabled) 1031 continue; 1032 1033 disk = (Disk *)devs[i]->private; 1034 if (!disk->chunks) { 1035 msgConfirm("No chunk list found for %s!", disk->name); 1036 return DITEM_FAILURE | DITEM_RESTORE; 1037 } 1038 for (c1 = disk->chunks->part; c1; c1 = c1->next) { 1039#ifndef __ia64__ 1040 if (c1->type == freebsd) { 1041 for (c2 = c1->part; c2; c2 = c2->next) { 1042#else 1043 if (c1->type == part) { 1044 c2 = c1; 1045 { 1046#endif 1047 if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) { 1048 PartInfo *tmp = (PartInfo *)c2->private_data; 1049 1050 /* Already did root */ 1051 if (c2 == rootdev) 1052 continue; 1053 1054 sprintf(dname, "%s/dev/%s", 1055 RunningAsInit ? "/mnt" : "", c2->name); 1056 1057 if (tmp->do_newfs && (!upgrade || 1058 !msgNoYes("You are upgrading - are you SURE you" 1059 " want to newfs /dev/%s?", c2->name))) 1060 performNewfs(tmp, dname, QUEUE_YES); 1061 else 1062 command_shell_add(tmp->mountpoint, 1063 "fsck_ffs -y %s/dev/%s", RunningAsInit ? 1064 "/mnt" : "", c2->name); 1065#if 0 1066 if (tmp->soft) 1067 command_shell_add(tmp->mountpoint, 1068 "tunefs -n enable %s/dev/%s", RunningAsInit ? 1069 "/mnt" : "", c2->name); 1070#endif 1071 command_func_add(tmp->mountpoint, Mount, c2->name); 1072 } 1073 else if (c2->type == part && c2->subtype == FS_SWAP) { 1074 char fname[80]; 1075 int i; 1076 1077 if (c2 == swapdev) 1078 continue; 1079 sprintf(fname, "%s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name); 1080 i = (Fake || swapon(fname)); 1081 if (!i) { 1082 dialog_clear_norefresh(); 1083 msgNotify("Added %s as an additional swap device", fname); 1084 } 1085 else { 1086 msgConfirm("Unable to add %s as a swap device: %s", fname, strerror(errno)); 1087 } 1088 } 1089 } 1090 } 1091 else if (c1->type == fat && c1->private_data && 1092 (root->do_newfs || upgrade)) { 1093 char name[FILENAME_MAX]; 1094 1095 sprintf(name, "%s/%s", RunningAsInit ? "/mnt" : "", ((PartInfo *)c1->private_data)->mountpoint); 1096 Mkdir(name); 1097 } 1098#if defined(__ia64__) 1099 else if (c1->type == efi && c1->private_data) { 1100 char bootdir[FILENAME_MAX]; 1101 PartInfo *pi = (PartInfo *)c1->private_data; 1102 char *p; 1103 1104 sprintf(dname, "%s/dev/%s", RunningAsInit ? "/mnt" : "", 1105 c1->name); 1106 1107 if (pi->do_newfs && (!upgrade || 1108 !msgNoYes("You are upgrading - are you SURE you want to " 1109 "newfs /dev/%s?", c1->name))) 1110 performNewfs(pi, dname, QUEUE_YES); 1111 1112 command_func_add(pi->mountpoint, Mount_msdosfs, c1->name); 1113 1114 /* 1115 * Create a directory boot on the EFI filesystem and create a 1116 * link boot on the root filesystem pointing to the one on the 1117 * EFI filesystem. That way, we install the loader, kernel 1118 * and modules on the EFI filesystem. 1119 */ 1120 sprintf(bootdir, "%s", RunningAsInit ? "/mnt" : ""); 1121 sprintf(efi_bootdir, "%s/%s", bootdir, pi->mountpoint); 1122 strcat(bootdir, "/boot"); 1123 strcat(efi_bootdir, "/boot"); 1124 command_func_add(pi->mountpoint, Mkdir_command, efi_bootdir); 1125 1126 /* Make a relative link. */ 1127 p = &efi_bootdir[(RunningAsInit) ? 4 : 0]; 1128 while (*p == '/') 1129 p++; 1130 symlink(p, bootdir); 1131 } 1132#endif 1133 } 1134 } 1135 1136 command_sort(); 1137 command_execute(); 1138 dialog_clear_norefresh(); 1139 return DITEM_SUCCESS | DITEM_RESTORE; 1140} 1141 1142static char * 1143getRelname(void) 1144{ 1145 static char buf[64]; 1146 size_t sz = (sizeof buf) - 1; 1147 1148 if (sysctlbyname("kern.osrelease", buf, &sz, NULL, 0) != -1) { 1149 buf[sz] = '\0'; 1150 return buf; 1151 } 1152 else 1153 return "<unknown>"; 1154} 1155 1156/* Initialize various user-settable values to their defaults */ 1157int 1158installVarDefaults(dialogMenuItem *self) 1159{ 1160 char *cp; 1161 1162 /* Set default startup options */ 1163 variable_set2(VAR_RELNAME, getRelname(), 0); 1164 variable_set2(VAR_CPIO_VERBOSITY, "high", 0); 1165 variable_set2(VAR_TAPE_BLOCKSIZE, DEFAULT_TAPE_BLOCKSIZE, 0); 1166 variable_set2(VAR_INSTALL_ROOT, "/", 0); 1167 variable_set2(VAR_INSTALL_CFG, "install.cfg", 0); 1168 variable_set2(VAR_SKIP_PCCARD, "NO", 0); 1169 cp = getenv("EDITOR"); 1170 if (!cp) 1171 cp = "/usr/bin/ee"; 1172 variable_set2(VAR_EDITOR, cp, 0); 1173 variable_set2(VAR_FTP_USER, "ftp", 0); 1174 variable_set2(VAR_BROWSER_PACKAGE, "links", 0); 1175 variable_set2(VAR_BROWSER_BINARY, "/usr/local/bin/links", 0); 1176 variable_set2(VAR_FTP_STATE, "passive", 0); 1177 variable_set2(VAR_NFS_SECURE, "NO", -1); 1178 variable_set2(VAR_NFS_TCP, "NO", -1); 1179 variable_set2(VAR_NFS_V3, "YES", -1); 1180 if (OnVTY) 1181 variable_set2(VAR_FIXIT_TTY, "standard", 0); 1182 else 1183 variable_set2(VAR_FIXIT_TTY, "serial", 0); 1184 variable_set2(VAR_PKG_TMPDIR, "/var/tmp", 0); 1185 variable_set2(VAR_MEDIA_TIMEOUT, itoa(MEDIA_TIMEOUT), 0); 1186 if (getpid() != 1) 1187 variable_set2(SYSTEM_STATE, "update", 0); 1188 else 1189 variable_set2(SYSTEM_STATE, "init", 0); 1190 variable_set2(VAR_NEWFS_ARGS, "-b 16384 -f 2048", 0); 1191 variable_set2(VAR_CONSTERM, "NO", 0); 1192 return DITEM_SUCCESS; 1193} 1194 1195/* Load the environment up from various system configuration files */ 1196void 1197installEnvironment(void) 1198{ 1199 configEnvironmentRC_conf(); 1200 if (file_readable("/etc/resolv.conf")) 1201 configEnvironmentResolv("/etc/resolv.conf"); 1202} 1203 1204/* Copy the boot floppy contents into /stand */ 1205Boolean 1206copySelf(void) 1207{ 1208 int i; 1209 1210 if (file_readable("/boot.help")) 1211 vsystem("cp /boot.help /mnt"); 1212 msgWeHaveOutput("Copying the boot floppy to /stand on root filesystem"); 1213 i = vsystem("find -x /stand | cpio %s -pdum /mnt", cpioVerbosity()); 1214 if (i) { 1215 msgConfirm("Copy returned error status of %d!", i); 1216 return FALSE; 1217 } 1218 1219 /* Copy the /etc files into their rightful place */ 1220 if (vsystem("cd /mnt/stand; find etc | cpio %s -pdum /mnt", cpioVerbosity())) { 1221 msgConfirm("Couldn't copy up the /etc files!"); 1222 return TRUE; 1223 } 1224 return TRUE; 1225} 1226 1227static void 1228create_termcap(void) 1229{ 1230 FILE *fp; 1231 1232 const char *caps[] = { 1233 termcap_vt100, termcap_cons25, termcap_cons25_m, termcap_cons25r, 1234 termcap_cons25r_m, termcap_cons25l1, termcap_cons25l1_m, 1235 termcap_xterm, NULL, 1236 }; 1237 const char **cp; 1238 1239 if (!file_readable(TERMCAP_FILE)) { 1240 Mkdir("/usr/share/misc"); 1241 fp = fopen(TERMCAP_FILE, "w"); 1242 if (!fp) { 1243 msgConfirm("Unable to initialize termcap file. Some screen-oriented\nutilities may not work."); 1244 return; 1245 } 1246 cp = caps; 1247 while (*cp) 1248 fprintf(fp, "%s\n", *(cp++)); 1249 fclose(fp); 1250 } 1251} 1252