2 * The new sysinstall program.
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
10 * Jordan Hubbard. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
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
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.
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
37 #include "sysinstall.h"
39 #include <sys/disklabel.h>
40 #include <sys/errno.h>
41 #include <sys/ioctl.h>
42 #include <sys/fcntl.h>
45 #include <sys/param.h>
47 #include <sys/mount.h>
48 #include <ufs/ufs/ufsmount.h>
49 #include <fs/msdosfs/msdosfsmount.h>
52 #include <sys/sysctl.h>
56 /* Hack for rsaref package add, which displays interactive license.
62 static void create_termcap(void);
63 static void fixit_common(void);
65 #define TERMCAP_FILE "/usr/share/misc/termcap"
67 static void installConfigure(void);
70 checkLabels(Boolean whinge, Chunk **rdev, Chunk **sdev, Chunk **udev, Chunk **vdev, Chunk **tdev, Chunk **hdev)
75 Chunk *c1, *c2, *rootdev, *swapdev, *usrdev, *vardev, *tmpdev, *homedev;
78 /* Don't allow whinging if noWarn is set */
79 if (variable_get(VAR_NO_WARN))
95 rootdev = swapdev = usrdev = vardev = tmpdev = homedev = NULL;
97 /* We don't need to worry about root/usr/swap if we're already multiuser */
101 devs = deviceFind(NULL, DEVICE_TYPE_DISK);
102 /* First verify that we have a root device */
103 for (i = 0; devs[i]; i++) {
104 if (!devs[i]->enabled)
106 disk = (Disk *)devs[i]->private;
107 msgDebug("Scanning disk %s for root filesystem\n", disk->name);
109 msgFatal("No chunk list found for %s!", disk->name);
110 for (c1 = disk->chunks->part; c1; c1 = c1->next) {
111 if (c1->type == freebsd) {
112 for (c2 = c1->part; c2; c2 = c2->next) {
113 if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) {
114 if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/")) {
117 msgConfirm("WARNING: You have more than one root device set?!\n"
118 "Using the first one found.");
124 msgDebug("Found rootdev at %s!\n", rootdev->name);
127 else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/usr")) {
130 msgConfirm("WARNING: You have more than one /usr filesystem.\n"
131 "Using the first one found.");
137 msgDebug("Found usrdev at %s!\n", usrdev->name);
140 else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/var")) {
143 msgConfirm("WARNING: You have more than one /var filesystem.\n"
144 "Using the first one found.");
150 msgDebug("Found vardev at %s!\n", vardev->name);
152 } else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/tmp")) {
155 msgConfirm("WARNING: You have more than one /tmp filesystem.\n"
156 "Using the first one found.");
162 msgDebug("Found tmpdev at %s!\n", tmpdev->name);
164 } else if (!strcmp(((PartInfo *)c2->private_data)->mountpoint, "/home")) {
167 msgConfirm("WARNING: You have more than one /home filesystem.\n"
168 "Using the first one found.");
174 msgDebug("Found homedev at %s!\n", homedev->name);
183 /* Now check for swap devices */
184 for (i = 0; devs[i]; i++) {
185 if (!devs[i]->enabled)
187 disk = (Disk *)devs[i]->private;
188 msgDebug("Scanning disk %s for swap partitions\n", disk->name);
190 msgFatal("No chunk list found for %s!", disk->name);
191 for (c1 = disk->chunks->part; c1; c1 = c1->next) {
192 if (c1->type == freebsd) {
193 for (c2 = c1->part; c2; c2 = c2->next) {
194 if (c2->type == part && c2->subtype == FS_SWAP && !swapdev) {
197 msgDebug("Found swapdev at %s!\n", swapdev->name);
205 /* Copy our values over */
219 if (!rootdev && whinge) {
220 msgConfirm("No root device found - you must label a partition as /\n"
221 "in the label editor.");
224 if (!swapdev && whinge) {
225 msgConfirm("No swap devices found - you must create at least one\n"
235 static Boolean alreadyDone = FALSE;
236 int status = DITEM_SUCCESS;
239 return DITEM_SUCCESS;
241 if (!variable_get(DISK_LABELLED)) {
242 msgConfirm("You need to assign disk labels before you can proceed with\n"
243 "the installation.");
244 return DITEM_FAILURE;
246 /* If it's labelled, assume it's also partitioned */
247 if (!variable_get(DISK_PARTITIONED))
248 variable_set2(DISK_PARTITIONED, "yes", 0);
250 /* If we refuse to proceed, bail. */
251 dialog_clear_norefresh();
252 if (!variable_get(VAR_NO_WARN)) {
254 "Last Chance! Are you SURE you want continue the installation?\n\n"
255 "If you're running this on a disk with data you wish to save\n"
256 "then WE STRONGLY ENCOURAGE YOU TO MAKE PROPER BACKUPS before\n"
258 "We can take no responsibility for lost disk contents!") != 0)
259 return DITEM_FAILURE;
262 if (DITEM_STATUS(diskLabelCommit(NULL)) != DITEM_SUCCESS) {
263 msgConfirm("Couldn't make filesystems properly. Aborting.");
264 return DITEM_FAILURE;
268 msgConfirm("installInitial: Couldn't clone the boot floppy onto the\n"
269 "root file system. Aborting!");
270 return DITEM_FAILURE;
273 if (!Restarting && chroot("/mnt") == -1) {
274 msgConfirm("installInitial: Unable to chroot to %s - this is bad!",
276 return DITEM_FAILURE;
280 variable_set2(RUNNING_ON_ROOT, "yes", 0);
282 /* Configure various files in /etc */
283 if (DITEM_STATUS(configResolv(NULL)) == DITEM_FAILURE)
284 status = DITEM_FAILURE;
285 if (DITEM_STATUS(configFstab(NULL)) == DITEM_FAILURE)
286 status = DITEM_FAILURE;
288 /* stick a helpful shell over on the 4th VTY */
289 if (!variable_get(VAR_NO_HOLOSHELL))
290 systemCreateHoloshell();
297 installFixitHoloShell(dialogMenuItem *self)
300 systemCreateHoloshell();
301 return DITEM_SUCCESS;
306 installFixitCDROM(dialogMenuItem *self)
311 return DITEM_SUCCESS;
313 variable_set2(SYSTEM_STATE, "fixit", 0);
314 (void)unlink("/mnt2");
315 (void)rmdir("/mnt2");
318 msgConfirm("Please insert a FreeBSD live filesystem CD/DVD and press return");
319 if (DITEM_STATUS(mediaSetCDROM(NULL)) != DITEM_SUCCESS
320 || !DEVICE_INIT(mediaDevice)) {
321 /* If we can't initialize it, it's probably not a FreeBSD CDROM so punt on it */
323 if (msgYesNo("Unable to mount the disc - do you want to try again?") != 0)
324 return DITEM_FAILURE;
330 /* Since the fixit code expects everything to be in /mnt2, and the CDROM mounting stuff /dist, do
331 * a little kludge dance here..
333 if (symlink("/dist", "/mnt2")) {
334 msgConfirm("Unable to symlink /mnt2 to the disc mount point. Please report this\n"
335 "unexpected failure to freebsd-bugs@FreeBSD.org.");
336 return DITEM_FAILURE;
340 * If /tmp points to /mnt2/tmp from a previous fixit floppy session, it's
341 * not very good for us if we point it to the CDROM now. Rather make it
342 * a directory in the root MFS then. Experienced admins will still be
343 * able to mount their disk's /tmp over this if they need.
345 if (lstat("/tmp", &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFLNK)
346 (void)unlink("/tmp");
350 * Since setuid binaries ignore LD_LIBRARY_PATH, we indeed need the
351 * ld.so.hints file. Fortunately, it's fairly small (~ 3 KB).
353 if (!file_readable("/var/run/ld.so.hints")) {
355 if (vsystem("/mnt2/sbin/ldconfig -s /mnt2/usr/lib")) {
356 msgConfirm("Warning: ldconfig could not create the ld.so hints file.\n"
357 "Dynamic executables from the disc likely won't work.");
361 /* Yet more iggly hardcoded pathnames. */
362 Mkdir("/usr/libexec");
363 if (!file_readable("/usr/libexec/ld.so") && file_readable("/mnt2/usr/libexec/ld.so")) {
364 if (symlink("/mnt2/usr/libexec/ld.so", "/usr/libexec/ld.so"))
365 msgDebug("Couldn't link to ld.so - not necessarily a problem for ELF\n");
367 if (!file_readable("/usr/libexec/ld-elf.so.1")) {
368 if (symlink("/mnt2/usr/libexec/ld-elf.so.1", "/usr/libexec/ld-elf.so.1")) {
369 msgConfirm("Warning: could not create the symlink for ld-elf.so.1\n"
370 "Dynamic executables from the disc likely won't work.");
373 /* optional nicety */
374 if (!file_readable("/usr/bin/vi"))
375 symlink("/mnt2/usr/bin/vi", "/usr/bin/vi");
378 msgConfirm("Please remove the FreeBSD fixit CDROM/DVD now.");
379 return DITEM_SUCCESS;
383 installFixitFloppy(dialogMenuItem *self)
385 struct ufs_args args;
386 extern char *distWanted;
389 return DITEM_SUCCESS;
391 /* Try to open the floppy drive */
392 if (DITEM_STATUS(mediaSetFloppy(NULL)) == DITEM_FAILURE || !mediaDevice) {
393 msgConfirm("Unable to set media device to floppy.");
395 return DITEM_FAILURE;
398 memset(&args, 0, sizeof(args));
399 args.fspec = mediaDevice->devname;
400 mediaDevice->private = "/mnt2";
404 variable_set2(SYSTEM_STATE, "fixit", 0);
407 if (!DEVICE_INIT(mediaDevice)) {
408 if (msgYesNo("The attempt to mount the fixit floppy failed, bad floppy\n"
409 "or unclean filesystem. Do you want to try again?"))
410 return DITEM_FAILURE;
415 if (!directory_exists("/tmp"))
416 (void)symlink("/mnt2/tmp", "/tmp");
419 msgConfirm("Please remove the fixit floppy now.");
420 return DITEM_SUCCESS;
424 * The common code for both fixit variants.
432 if (!directory_exists("/var/tmp/vi.recover")) {
433 if (DITEM_STATUS(Mkdir("/var/tmp/vi.recover")) != DITEM_SUCCESS) {
434 msgConfirm("Warning: Was unable to create a /var/tmp/vi.recover directory.\n"
435 "vi will kvetch and moan about it as a result but should still\n"
436 "be essentially usable.");
439 if (!directory_exists("/bin"))
441 (void)symlink("/stand/sh", "/bin/sh");
442 /* Link the /etc/ files */
443 if (DITEM_STATUS(Mkdir("/etc")) != DITEM_SUCCESS)
444 msgConfirm("Unable to create an /etc directory! Things are weird on this floppy..");
445 else if ((symlink("/mnt2/etc/spwd.db", "/etc/spwd.db") == -1 && errno != EEXIST) ||
446 (symlink("/mnt2/etc/protocols", "/etc/protocols") == -1 && errno != EEXIST) ||
447 (symlink("/mnt2/etc/group", "/etc/group") == -1 && errno != EEXIST) ||
448 (symlink("/mnt2/etc/services", "/etc/services") == -1 && errno != EEXIST))
449 msgConfirm("Couldn't symlink the /etc/ files! I'm not sure I like this..");
450 if (!file_readable(TERMCAP_FILE))
452 if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
453 systemSuspendDialog(); /* must be before the fork() */
454 if (!(child = fork())) {
457 extern int login_tty(int);
459 ioctl(0, TIOCNOTTY, NULL);
460 for (i = getdtablesize(); i >= 0; --i)
463 if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
464 fd = open("/dev/console", O_RDWR);
466 fd = open("/dev/ttyv3", O_RDWR);
467 ioctl(0, TIOCSCTTY, &fd);
471 if (login_tty(fd) == -1)
472 msgDebug("fixit: I can't set the controlling terminal.\n");
474 signal(SIGTTOU, SIG_IGN);
475 if (tcgetattr(0, &foo) != -1) {
476 foo.c_cc[VERASE] = '\010';
477 if (tcsetattr(0, TCSANOW, &foo) == -1)
478 msgDebug("fixit shell: Unable to set erase character.\n");
481 msgDebug("fixit shell: Unable to get terminal attributes!\n");
482 setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/stand:"
483 "/mnt2/stand:/mnt2/bin:/mnt2/sbin:/mnt2/usr/bin:/mnt2/usr/sbin", 1);
484 if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0) {
485 printf("Waiting for fixit shell to exit.\n"
486 "When you are done, type ``exit'' to exit\n"
487 "the fixit shell and be returned here.\n\n");
491 /* use the .profile from the fixit medium */
492 setenv("HOME", "/mnt2", 1);
494 execlp("sh", "-sh", (char *)0);
495 msgDebug("fixit shell: Failed to execute shell!\n");
499 if (strcmp(variable_get(VAR_FIXIT_TTY), "standard") == 0) {
500 dialog_clear_norefresh();
501 msgNotify("Waiting for fixit shell to exit. Go to VTY4 now by\n"
502 "typing ALT-F4. When you are done, type ``exit'' to exit\n"
503 "the fixit shell and be returned here\n.");
505 (void)waitpid(child, &waitstatus, 0);
506 if (strcmp(variable_get(VAR_FIXIT_TTY), "serial") == 0)
507 systemResumeDialog();
514 installExpress(dialogMenuItem *self)
518 dialog_clear_norefresh();
519 variable_set2(SYSTEM_STATE, "express", 0);
520 #if defined(__i386__) || defined(__ia64__)
521 if (DITEM_STATUS((i = diskPartitionEditor(self))) == DITEM_FAILURE)
525 if (DITEM_STATUS((i = diskLabelEditor(self))) == DITEM_FAILURE)
528 if (DITEM_STATUS((i = installCommit(self))) == DITEM_SUCCESS) {
529 i |= DITEM_LEAVE_MENU;
530 /* Set default security level */
531 configSecurityModerate(NULL);
533 /* Give user the option of one last configuration spree */
539 /* Standard mode installation */
541 installStandard(dialogMenuItem *self)
546 variable_set2(SYSTEM_STATE, "standard", 0);
547 dialog_clear_norefresh();
548 #if defined(__i386__) || defined(__ia64__)
549 msgConfirm("In the next menu, you will need to set up a DOS-style (\"fdisk\") partitioning\n"
550 "scheme for your hard disk. If you simply wish to devote all disk space\n"
551 "to FreeBSD (overwriting anything else that might be on the disk(s) selected)\n"
552 "then use the (A)ll command to select the default partitioning scheme followed\n"
553 "by a (Q)uit. If you wish to allocate only free space to FreeBSD, move to a\n"
554 "partition marked \"unused\" and use the (C)reate command.");
557 if (DITEM_STATUS(diskPartitionEditor(self)) == DITEM_FAILURE)
558 return DITEM_FAILURE;
560 if (diskGetSelectCount(&devs) <= 0 && tries < 3) {
561 msgConfirm("You need to select some disks to operate on! Be sure to use SPACE\n"
562 "instead of RETURN in the disk selection menu when selecting a disk.");
568 #if defined(__i386__) || defined(__ia64__)
569 msgConfirm("Now you need to create BSD partitions inside of the fdisk partition(s)\n"
570 "just created. If you have a reasonable amount of disk space (200MB or more)\n"
571 "and don't have any special requirements, simply use the (A)uto command to\n"
572 "allocate space automatically. If you have more specific needs or just don't\n"
573 "care for the layout chosen by (A)uto, press F1 for more information on\n"
576 msgConfirm("Now you need to create BSD partitions on the disk which you are\n"
577 "installing to. If you have a reasonable amount of disk space (200MB or more)\n"
578 "and don't have any special requirements, simply use the (A)uto command to\n"
579 "allocate space automatically. If you have more specific needs or just don't\n"
580 "care for the layout chosen by (A)uto, press F1 for more information on\n"
584 if (DITEM_STATUS(diskLabelEditor(self)) == DITEM_FAILURE)
585 return DITEM_FAILURE;
587 if (DITEM_STATUS((i = installCommit(self))) == DITEM_FAILURE) {
589 msgConfirm("Installation completed with some errors. You may wish to\n"
590 "scroll through the debugging messages on VTY1 with the\n"
591 "scroll-lock feature. You can also choose \"No\" at the next\n"
592 "prompt and go back into the installation menus to try and retry\n"
593 "whichever operations have failed.");
599 msgConfirm("Congratulations! You now have FreeBSD installed on your system.\n\n"
600 "We will now move on to the final configuration questions.\n"
601 "For any option you do not wish to configure, simply select\n"
603 "If you wish to re-enter this utility after the system is up, you\n"
604 "may do so by typing: /usr/sbin/sysinstall.");
606 if (mediaDevice->type != DEVICE_TYPE_FTP && mediaDevice->type != DEVICE_TYPE_NFS) {
607 if (!msgYesNo("Would you like to configure any Ethernet or SLIP/PPP network devices?")) {
608 Device *tmp = tcpDeviceSelect();
610 if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you like to bring the %s interface up right now?", tmp->name))
611 if (!DEVICE_INIT(tmp))
612 msgConfirm("Initialization of %s device failed.", tmp->name);
614 dialog_clear_norefresh();
617 if (!msgNoYes("Do you want this machine to function as a network gateway?"))
618 variable_set2("gateway_enable", "YES", 1);
620 dialog_clear_norefresh();
621 if (!msgNoYes("Do you want to configure inetd and the network services that it provides?"))
624 dialog_clear_norefresh();
625 if (!msgNoYes("Do you want to have anonymous FTP access to this machine?"))
628 dialog_clear_norefresh();
629 if (!msgNoYes("Do you want to configure this machine as an NFS server?"))
630 configNFSServer(self);
632 dialog_clear_norefresh();
633 if (!msgNoYes("Do you want to configure this machine as an NFS client?"))
634 variable_set2("nfs_client_enable", "YES", 1);
636 if (!msgNoYes("Do you want to select a default security profile for\n"
637 "this host (select No for \"moderate\" security)?"))
638 configSecurityProfile(self);
640 configSecurityModerate(self);
642 dialog_clear_norefresh();
643 if (!msgNoYes("Would you like to customize your system console settings?"))
644 dmenuOpenSimple(&MenuSyscons, FALSE);
646 dialog_clear_norefresh();
647 if (!msgYesNo("Would you like to set this machine's time zone now?"))
648 systemExecute("tzsetup");
651 dialog_clear_norefresh();
652 if (!msgYesNo("Would you like to enable Linux binary compatibility?"))
653 (void)configLinux(self);
656 dialog_clear_norefresh();
657 if (!msgNoYes("Does this system have a non-USB mouse attached to it?"))
658 dmenuOpenSimple(&MenuMouse, FALSE);
660 /* Now would be a good time to checkpoint the configuration data */
664 if (directory_exists("/usr/X11R6")) {
665 dialog_clear_norefresh();
666 if (!msgYesNo("Would you like to configure your X server at this time?"))
667 (void)configXSetup(self);
670 dialog_clear_norefresh();
671 if (!msgYesNo("The FreeBSD package collection is a collection of thousands of ready-to-run\n"
672 "applications, from text editors to games to WEB servers and more. Would you\n"
673 "like to browse the collection now?")) {
674 (void)configPackages(self);
677 if (!msgYesNo("Would you like to add any initial user accounts to the system?\n"
678 "Adding at least one account for yourself at this stage is suggested\n"
679 "since working as the \"root\" user is dangerous (it is easy to do\n"
680 "things which adversely affect the entire system)."))
681 (void)configUsers(self);
683 msgConfirm("Now you must set the system manager's password.\n"
684 "This is the password you'll use to log in as \"root\".");
685 if (!systemExecute("passwd root"))
686 variable_set2("root_password", "YES", 0);
688 /* XXX Put whatever other nice configuration questions you'd like to ask the user here XXX */
690 /* Give user the option of one last configuration spree */
691 dialog_clear_norefresh();
693 return DITEM_LEAVE_MENU;
696 /* The version of commit we call from the Install Custom menu */
698 installCustomCommit(dialogMenuItem *self)
702 i = installCommit(self);
703 if (DITEM_STATUS(i) == DITEM_SUCCESS) {
704 /* Set default security level */
705 configSecurityModerate(NULL);
707 /* Give user the option of one last configuration spree */
712 msgConfirm("The commit operation completed with errors. Not\n"
713 "updating /etc files.");
718 * What happens when we finally decide to going ahead with the installation.
720 * This is broken into multiple stages so that the user can do a full
721 * installation but come back here again to load more distributions,
722 * perhaps from a different media type. This would allow, for
723 * example, the user to load the majority of the system from CDROM and
724 * then use ftp to load just the CRYPTO dist.
727 installCommit(dialogMenuItem *self)
732 dialog_clear_norefresh();
737 (void)dmenuOpenSimple(&MenuDistributions, FALSE);
738 /* select reasonable defaults if necessary */
744 return DITEM_FAILURE;
746 str = variable_get(SYSTEM_STATE);
748 msgDebug("installCommit: System state is `%s'\n", str);
750 /* Installation stuff we wouldn't do to a running system */
751 if (RunningAsInit && DITEM_STATUS((i = installInitial())) == DITEM_FAILURE)
755 if (!DEVICE_INIT(mediaDevice)) {
756 if (!msgYesNo("Unable to initialize selected media. Would you like to\n"
757 "adjust your media configuration and try again?")) {
760 return DITEM_FAILURE;
765 return DITEM_FAILURE;
768 /* Now go get it all */
769 i = distExtractAll(self);
771 /* When running as init, *now* it's safe to grab the rc.foo vars */
772 installEnvironment();
774 variable_set2(SYSTEM_STATE, DITEM_STATUS(i) == DITEM_FAILURE ? "error-install" : "full-install", 0);
780 installConfigure(void)
782 /* Final menu of last resort */
783 if (!msgNoYes("Visit the general configuration menu for a chance to set\n"
784 "any last options?"))
785 dmenuOpenSimple(&MenuConfigure, FALSE);
791 installFixupBin(dialogMenuItem *self)
799 /* All of this is done only as init, just to be safe */
802 if ((fp = fopen("/boot/loader.conf", "a")) != NULL) {
803 if (!kstat || !OnVTY)
804 fprintf(fp, "# -- sysinstall generated deltas -- #\n");
806 fprintf(fp, "userconfig_script_load=\"YES\"\n");
808 fprintf(fp, "console=\"comconsole\"\n");
813 /* BOGON #2: We leave /etc in a bad state */
816 /* BOGON #3: No /var/db/mountdtab complains */
818 creat("/var/db/mountdtab", 0644);
820 /* BOGON #4: /compat created by default in root fs */
821 Mkdir("/usr/compat");
822 vsystem("ln -s usr/compat /compat");
824 /* BOGON #5: aliases database not build for bin */
825 vsystem("newaliases");
827 /* Now run all the mtree stuff to fix things up */
828 vsystem("mtree -deU -f /etc/mtree/BSD.root.dist -p /");
829 vsystem("mtree -deU -f /etc/mtree/BSD.var.dist -p /var");
830 vsystem("mtree -deU -f /etc/mtree/BSD.usr.dist -p /usr");
832 /* Do all the last ugly work-arounds here */
834 return DITEM_SUCCESS | DITEM_RESTORE;
839 installX11package(dialogMenuItem *self)
841 WINDOW *w = savescr();
844 dialog_clear_norefresh();
845 msgNotify("Installing XFree86 package...");
846 i = package_add("XFree86-4");
852 /* Fix side-effects from the the XFree86 installation */
854 installFixupXFree(dialogMenuItem *self)
856 /* BOGON #1: XFree86 requires various specialized fixups */
857 if (directory_exists("/usr/X11R6")) {
858 dialog_clear_norefresh();
859 msgNotify("Fixing permissions in XFree86 tree..");
860 vsystem("chmod -R a+r /usr/X11R6");
861 vsystem("find /usr/X11R6 -type d | xargs chmod a+x");
864 /* Also do bogus minimal package registration so ports don't whine */
865 if (file_readable("/usr/X11R6/lib/X11/pkgreg.tar.gz")) {
866 dialog_clear_norefresh();
867 msgNotify("Installing package metainfo..");
868 vsystem("tar xpzf /usr/X11R6/lib/X11/pkgreg.tar.gz -C / && rm /usr/X11R6/lib/X11/pkgreg.tar.gz");
872 return DITEM_SUCCESS | DITEM_RESTORE;
875 /* Go newfs and/or mount all the filesystems we've been asked to */
877 installFilesystems(dialogMenuItem *self)
881 Chunk *c1, *c2, *rootdev, *swapdev;
885 Boolean upgrade = FALSE;
887 /* If we've already done this, bail out */
888 if (!variable_cmp(DISK_LABELLED, "written"))
889 return DITEM_SUCCESS;
891 upgrade = !variable_cmp(SYSTEM_STATE, "upgrade");
892 if (!checkLabels(TRUE, &rootdev, &swapdev, NULL, NULL, NULL, NULL))
893 return DITEM_FAILURE;
896 root = (PartInfo *)rootdev->private_data;
901 if (swapdev && RunningAsInit) {
902 /* As the very first thing, try to get ourselves some swap space */
903 sprintf(dname, "/dev/%s", swapdev->name);
904 if (!Fake && !file_readable(dname)) {
905 msgConfirm("Unable to find device node for %s in /dev!\n"
906 "The creation of filesystems will be aborted.", dname);
907 return DITEM_FAILURE;
911 if (!swapon(dname)) {
912 dialog_clear_norefresh();
913 msgNotify("Added %s as initial swap device", dname);
916 msgConfirm("WARNING! Unable to swap to %s: %s\n"
917 "This may cause the installation to fail at some point\n"
918 "if you don't have a lot of memory.", dname, strerror(errno));
923 if (rootdev && RunningAsInit) {
924 /* Next, create and/or mount the root device */
925 sprintf(dname, "/dev/%s", rootdev->name);
926 if (!Fake && !file_readable(dname)) {
927 msgConfirm("Unable to make device node for %s in /dev!\n"
928 "The creation of filesystems will be aborted.", dname);
929 return DITEM_FAILURE | DITEM_RESTORE;
931 if (strcmp(root->mountpoint, "/"))
932 msgConfirm("Warning: %s is marked as a root partition but is mounted on %s", rootdev->name, root->mountpoint);
934 if (root->newfs && (!upgrade || !msgNoYes("You are upgrading - are you SURE you want to newfs the root partition?"))) {
937 dialog_clear_norefresh();
938 msgNotify("Making a new root filesystem on %s", dname);
939 i = vsystem("%s %s", root->newfs_cmd, dname);
941 msgConfirm("Unable to make new root filesystem on %s!\n"
942 "Command returned status %d", dname, i);
943 return DITEM_FAILURE | DITEM_RESTORE;
948 msgConfirm("Warning: Using existing root partition. It will be assumed\n"
949 "that you have the appropriate device entries already in /dev.");
951 dialog_clear_norefresh();
952 msgNotify("Checking integrity of existing %s filesystem.", dname);
953 i = vsystem("fsck_ffs -y %s", dname);
955 msgConfirm("Warning: fsck returned status of %d for %s.\n"
956 "This partition may be unsafe to use.", i, dname);
959 i = vsystem("tunefs -n enable %s", dname);
961 msgConfirm("Warning: Unable to enable softupdates for root filesystem on %s", dname);
964 /* Switch to block device */
965 sprintf(dname, "/dev/%s", rootdev->name);
966 if (Mount("/mnt", dname)) {
967 msgConfirm("Unable to mount the root file system on %s! Giving up.", dname);
968 return DITEM_FAILURE | DITEM_RESTORE;
971 /* Mount devfs for other partitions to mount */
976 iov[0].iov_base = "fstype";
977 iov[0].iov_len = strlen(iov[0].iov_base) + 1;
978 iov[1].iov_base = "devfs";
979 iov[1].iov_len = strlen(iov[1].iov_base) + 1;
980 iov[2].iov_base = "fspath";
981 iov[2].iov_len = strlen(iov[2].iov_base) + 1;
982 iov[3].iov_base = "/mnt/dev";
983 iov[3].iov_len = strlen(iov[3].iov_base) + 1;
984 i = nmount(iov, 4, 0);
987 dialog_clear_norefresh();
988 msgConfirm("Unable to mount DEVFS (error %d)", errno);
989 return DITEM_FAILURE | DITEM_RESTORE;
994 /* Now buzz through the rest of the partitions and mount them too */
995 devs = deviceFind(NULL, DEVICE_TYPE_DISK);
996 for (i = 0; devs[i]; i++) {
997 if (!devs[i]->enabled)
1000 disk = (Disk *)devs[i]->private;
1001 if (!disk->chunks) {
1002 msgConfirm("No chunk list found for %s!", disk->name);
1003 return DITEM_FAILURE | DITEM_RESTORE;
1005 for (c1 = disk->chunks->part; c1; c1 = c1->next) {
1006 if (c1->type == freebsd) {
1007 for (c2 = c1->part; c2; c2 = c2->next) {
1008 if (c2->type == part && c2->subtype != FS_SWAP && c2->private_data) {
1009 PartInfo *tmp = (PartInfo *)c2->private_data;
1011 /* Already did root */
1015 if (tmp->newfs && (!upgrade || !msgNoYes("You are upgrading - are you SURE you want to newfs /dev/%s?", c2->name)))
1016 command_shell_add(tmp->mountpoint, "%s %s/dev/%s", tmp->newfs_cmd, RunningAsInit ? "/mnt" : "", c2->name);
1018 command_shell_add(tmp->mountpoint, "fsck_ffs -y %s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name);
1020 command_shell_add(tmp->mountpoint, "tunefs -n enable %s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name);
1021 command_func_add(tmp->mountpoint, Mount, c2->name);
1023 else if (c2->type == part && c2->subtype == FS_SWAP) {
1029 sprintf(fname, "%s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name);
1030 i = (Fake || swapon(fname));
1032 dialog_clear_norefresh();
1033 msgNotify("Added %s as an additional swap device", fname);
1036 msgConfirm("Unable to add %s as a swap device: %s", fname, strerror(errno));
1041 else if (c1->type == fat && c1->private_data && (root->newfs || upgrade)) {
1042 char name[FILENAME_MAX];
1044 sprintf(name, "%s/%s", RunningAsInit ? "/mnt" : "", ((PartInfo *)c1->private_data)->mountpoint);
1047 #if defined(__ia64__)
1048 else if (c1->type == efi && c1->private_data) {
1049 char bootdir[FILENAME_MAX];
1050 char efi_bootdir[FILENAME_MAX];
1051 PartInfo *pi = (PartInfo *)c1->private_data;
1053 if (pi->newfs && (!upgrade || !msgNoYes("You are upgrading - are you SURE you want to newfs /dev/%s?", c1->name)))
1054 command_shell_add(pi->mountpoint, "%s %s/dev/%s", pi->newfs_cmd, RunningAsInit ? "/mnt" : "", c1->name);
1056 command_func_add(pi->mountpoint, Mount, c1->name);
1059 * Create a directory boot on the EFI filesystem and create a
1060 * link boot on the root filesystem pointing to the one on the
1061 * EFI filesystem. That way, we install the loader, kernel
1062 * and modules on the EFI filesystem.
1064 sprintf(bootdir, "%s", RunningAsInit ? "/mnt" : "");
1065 sprintf(efi_bootdir, "%s/%s", bootdir, pi->mountpoint);
1066 strcat(bootdir, "/boot");
1067 strcat(efi_bootdir, "/boot");
1069 symlink(efi_bootdir, bootdir);
1077 dialog_clear_norefresh();
1078 return DITEM_SUCCESS | DITEM_RESTORE;
1084 static char buf[64];
1085 size_t sz = (sizeof buf) - 1;
1087 if (sysctlbyname("kern.osrelease", buf, &sz, NULL, 0) != -1) {
1095 /* Initialize various user-settable values to their defaults */
1097 installVarDefaults(dialogMenuItem *self)
1101 /* Set default startup options */
1102 variable_set2(VAR_RELNAME, getRelname(), 0);
1103 variable_set2(VAR_CPIO_VERBOSITY, "high", 0);
1104 variable_set2(VAR_TAPE_BLOCKSIZE, DEFAULT_TAPE_BLOCKSIZE, 0);
1105 variable_set2(VAR_INSTALL_ROOT, "/", 0);
1106 variable_set2(VAR_INSTALL_CFG, "install.cfg", 0);
1107 cp = getenv("EDITOR");
1110 variable_set2(VAR_EDITOR, cp, 0);
1111 variable_set2(VAR_FTP_USER, "ftp", 0);
1112 variable_set2(VAR_BROWSER_PACKAGE, "links", 0);
1113 variable_set2(VAR_BROWSER_BINARY, "/usr/local/bin/links", 0);
1114 variable_set2(VAR_FTP_STATE, "passive", 0);
1115 variable_set2(VAR_NFS_SECURE, "NO", -1);
1117 variable_set2(VAR_FIXIT_TTY, "standard", 0);
1119 variable_set2(VAR_FIXIT_TTY, "serial", 0);
1120 variable_set2(VAR_PKG_TMPDIR, "/var/tmp", 0);
1121 variable_set2(VAR_MEDIA_TIMEOUT, itoa(MEDIA_TIMEOUT), 0);
1123 variable_set2(SYSTEM_STATE, "update", 0);
1125 variable_set2(SYSTEM_STATE, "init", 0);
1126 variable_set2(VAR_NEWFS_ARGS, "-b 16384 -f 2048", 0);
1127 variable_set2(VAR_CONSTERM, "NO", 0);
1128 return DITEM_SUCCESS;
1131 /* Load the environment up from various system configuration files */
1133 installEnvironment(void)
1135 configEnvironmentRC_conf();
1136 if (file_readable("/etc/resolv.conf"))
1137 configEnvironmentResolv("/etc/resolv.conf");
1140 /* Copy the boot floppy contents into /stand */
1146 if (file_readable("/boot.help"))
1147 vsystem("cp /boot.help /mnt");
1148 msgWeHaveOutput("Copying the boot floppy to /stand on root filesystem");
1149 i = vsystem("find -x /stand | cpio %s -pdum /mnt", cpioVerbosity());
1151 msgConfirm("Copy returned error status of %d!", i);
1155 /* Copy the /etc files into their rightful place */
1156 if (vsystem("cd /mnt/stand; find etc | cpio %s -pdum /mnt", cpioVerbosity())) {
1157 msgConfirm("Couldn't copy up the /etc files!");
1164 create_termcap(void)
1168 const char *caps[] = {
1169 termcap_vt100, termcap_cons25, termcap_cons25_m, termcap_cons25r,
1170 termcap_cons25r_m, termcap_cons25l1, termcap_cons25l1_m,
1171 termcap_xterm, NULL,
1175 if (!file_readable(TERMCAP_FILE)) {
1176 Mkdir("/usr/share/misc");
1177 fp = fopen(TERMCAP_FILE, "w");
1179 msgConfirm("Unable to initialize termcap file. Some screen-oriented\nutilities may not work.");
1184 fprintf(fp, "%s\n", *(cp++));