2008-02-02 07:15:27 +03:00
|
|
|
/* $NetBSD: disks.c,v 1.98 2008/02/02 04:15:27 tsutsui Exp $ */
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Philip A. Nelson for Piermont Information Systems Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1999-06-20 10:08:13 +04:00
|
|
|
* This product includes software developed for the NetBSD Project by
|
1997-09-27 03:02:53 +04:00
|
|
|
* Piermont Information Systems Inc.
|
|
|
|
* 4. The name of Piermont Information Systems Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2003-05-19 00:04:21 +04:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
1997-09-27 03:02:53 +04:00
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
2003-05-19 00:04:21 +04:00
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
1997-09-27 03:02:53 +04:00
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* disks.c -- routines to deal with finding disks and labeling disks. */
|
|
|
|
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
#include <errno.h>
|
1997-09-27 03:02:53 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1997-10-07 08:01:29 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
1997-11-03 03:04:53 +03:00
|
|
|
#include <util.h>
|
1997-10-07 08:01:29 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2003-06-16 14:42:47 +04:00
|
|
|
#include <sys/swap.h>
|
1997-10-07 08:01:29 +04:00
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
2003-01-10 23:00:27 +03:00
|
|
|
#define FSTYPENAMES
|
2003-11-30 17:36:43 +03:00
|
|
|
#define MOUNTNAMES
|
2003-01-13 00:49:50 +03:00
|
|
|
#define static
|
2003-01-10 23:00:27 +03:00
|
|
|
#include <sys/disklabel.h>
|
2003-01-13 00:49:50 +03:00
|
|
|
#undef static
|
1997-10-07 08:01:29 +04:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
#include "defs.h"
|
1997-10-29 04:06:42 +03:00
|
|
|
#include "md.h"
|
1997-09-27 03:02:53 +04:00
|
|
|
#include "msg_defs.h"
|
|
|
|
#include "menu_defs.h"
|
|
|
|
#include "txtwalk.h"
|
|
|
|
|
2003-07-11 19:28:58 +04:00
|
|
|
/* Disk descriptions */
|
|
|
|
#define MAX_DISKS 15
|
|
|
|
struct disk_desc {
|
2004-05-16 01:53:29 +04:00
|
|
|
char dd_name[SSTRSIZE];
|
|
|
|
uint dd_no_mbr;
|
|
|
|
uint dd_cyl;
|
|
|
|
uint dd_head;
|
|
|
|
uint dd_sec;
|
|
|
|
uint dd_secsize;
|
|
|
|
uint dd_totsec;
|
2003-07-11 19:28:58 +04:00
|
|
|
};
|
1997-11-02 11:20:40 +03:00
|
|
|
|
1997-10-01 09:04:24 +04:00
|
|
|
/* Local prototypes */
|
2003-11-30 17:36:43 +03:00
|
|
|
static int foundffs(struct data *, size_t);
|
2006-01-09 13:00:34 +03:00
|
|
|
#ifdef USE_SYSVBFS
|
|
|
|
static int foundsysvbfs(struct data *, size_t);
|
|
|
|
#endif
|
2003-11-30 17:36:43 +03:00
|
|
|
static int fsck_preen(const char *, int, const char *);
|
2004-04-25 22:40:37 +04:00
|
|
|
static void fixsb(const char *, const char *, char);
|
1997-11-05 10:28:20 +03:00
|
|
|
|
2003-05-30 15:56:23 +04:00
|
|
|
#ifndef DISK_NAMES
|
2005-06-10 02:14:20 +04:00
|
|
|
#define DISK_NAMES "wd", "sd", "ld", "raid"
|
2003-05-30 15:56:23 +04:00
|
|
|
#endif
|
|
|
|
|
2003-07-25 12:26:21 +04:00
|
|
|
static const char *disk_names[] = { DISK_NAMES, "vnd", NULL };
|
1997-11-02 11:20:40 +03:00
|
|
|
|
2003-07-11 19:28:58 +04:00
|
|
|
static int
|
|
|
|
get_disks(struct disk_desc *dd)
|
1997-10-15 08:35:17 +04:00
|
|
|
{
|
2003-07-25 12:26:21 +04:00
|
|
|
const char **xd;
|
2004-05-16 01:53:29 +04:00
|
|
|
char *cp;
|
1997-10-15 08:35:17 +04:00
|
|
|
struct disklabel l;
|
|
|
|
int i;
|
2003-07-11 19:28:58 +04:00
|
|
|
int numdisks;
|
1997-10-07 08:01:29 +04:00
|
|
|
|
2003-05-19 00:04:21 +04:00
|
|
|
/* initialize */
|
|
|
|
numdisks = 0;
|
|
|
|
|
|
|
|
for (xd = disk_names; *xd != NULL; xd++) {
|
|
|
|
for (i = 0; i < MAX_DISKS; i++) {
|
2004-05-16 01:53:29 +04:00
|
|
|
strlcpy(dd->dd_name, *xd, sizeof dd->dd_name - 2);
|
|
|
|
cp = strchr(dd->dd_name, ':');
|
|
|
|
if (cp != NULL)
|
2006-01-13 01:02:44 +03:00
|
|
|
dd->dd_no_mbr = !strcmp(cp, ":no_mbr");
|
2004-05-18 18:07:06 +04:00
|
|
|
else {
|
|
|
|
dd->dd_no_mbr = 0;
|
2004-05-16 01:53:29 +04:00
|
|
|
cp = strchr(dd->dd_name, 0);
|
2004-05-18 18:07:06 +04:00
|
|
|
}
|
2004-05-16 01:53:29 +04:00
|
|
|
|
|
|
|
snprintf(cp, 2 + 1, "%d", i);
|
|
|
|
if (!get_geom(dd->dd_name, &l)) {
|
2003-05-30 15:56:23 +04:00
|
|
|
if (errno == ENOENT)
|
|
|
|
break;
|
2003-05-19 00:04:21 +04:00
|
|
|
continue;
|
2003-05-30 15:56:23 +04:00
|
|
|
}
|
2003-05-19 00:04:21 +04:00
|
|
|
dd->dd_cyl = l.d_ncylinders;
|
|
|
|
dd->dd_head = l.d_ntracks;
|
|
|
|
dd->dd_sec = l.d_nsectors;
|
|
|
|
dd->dd_secsize = l.d_secsize;
|
|
|
|
dd->dd_totsec = l.d_secperunit;
|
|
|
|
dd++;
|
|
|
|
numdisks++;
|
|
|
|
if (numdisks >= MAX_DISKS)
|
2003-07-11 19:28:58 +04:00
|
|
|
return numdisks;
|
1997-10-15 08:35:17 +04:00
|
|
|
}
|
1997-10-07 08:01:29 +04:00
|
|
|
}
|
2003-07-11 19:28:58 +04:00
|
|
|
return numdisks;
|
1997-10-07 08:01:29 +04:00
|
|
|
}
|
2003-05-19 00:04:21 +04:00
|
|
|
|
2003-07-11 19:28:58 +04:00
|
|
|
static int
|
2003-07-27 11:45:08 +04:00
|
|
|
set_dsk_select(menudesc *m, void *arg)
|
2003-07-11 19:28:58 +04:00
|
|
|
{
|
|
|
|
*(int *)arg = m->cursel;
|
|
|
|
return 1;
|
|
|
|
}
|
1997-10-07 08:01:29 +04:00
|
|
|
|
2000-12-06 07:53:37 +03:00
|
|
|
int
|
2003-06-28 02:20:14 +04:00
|
|
|
find_disks(const char *doingwhat)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
2003-07-11 19:28:58 +04:00
|
|
|
struct disk_desc disks[MAX_DISKS];
|
|
|
|
menu_ent dsk_menu[nelem(disks)];
|
|
|
|
struct disk_desc *disk;
|
|
|
|
int i;
|
|
|
|
int numdisks;
|
|
|
|
int selected_disk = 0;
|
|
|
|
int menu_no;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1997-10-15 08:35:17 +04:00
|
|
|
/* Find disks. */
|
2003-07-11 19:28:58 +04:00
|
|
|
numdisks = get_disks(disks);
|
1997-09-27 03:02:53 +04:00
|
|
|
|
1999-01-21 11:02:17 +03:00
|
|
|
/* need a redraw here, kernel messages hose everything */
|
|
|
|
touchwin(stdscr);
|
|
|
|
refresh();
|
2006-02-25 23:21:00 +03:00
|
|
|
/* Kill typeahead, it won't be what the user had in mind */
|
|
|
|
fpurge(stdin);
|
1999-01-21 11:02:17 +03:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
if (numdisks == 0) {
|
|
|
|
/* No disks found! */
|
1999-03-31 04:44:48 +04:00
|
|
|
msg_display(MSG_nodisk);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ok, NULL);
|
1999-01-21 11:02:17 +03:00
|
|
|
/*endwin();*/
|
1997-09-27 03:02:53 +04:00
|
|
|
return -1;
|
2003-05-19 00:04:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (numdisks == 1) {
|
1997-09-27 03:02:53 +04:00
|
|
|
/* One disk found! */
|
2003-07-11 19:28:58 +04:00
|
|
|
msg_display(MSG_onedisk, disks[0].dd_name, doingwhat);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ok, NULL);
|
1997-09-27 03:02:53 +04:00
|
|
|
} else {
|
|
|
|
/* Multiple disks found! */
|
2003-07-11 19:28:58 +04:00
|
|
|
for (i = 0; i < numdisks; i++) {
|
|
|
|
dsk_menu[i].opt_name = disks[i].dd_name;
|
|
|
|
dsk_menu[i].opt_menu = OPT_NOMENU;
|
|
|
|
dsk_menu[i].opt_flags = OPT_EXIT;
|
|
|
|
dsk_menu[i].opt_action = set_dsk_select;
|
|
|
|
}
|
|
|
|
menu_no = new_menu(MSG_Available_disks,
|
|
|
|
dsk_menu, numdisks, -1, 4, 0, 0,
|
|
|
|
MC_SCROLL | MC_NOEXITOPT,
|
|
|
|
NULL, NULL, NULL, NULL, NULL);
|
|
|
|
if (menu_no == -1)
|
|
|
|
return -1;
|
|
|
|
msg_display(MSG_ask_disk);
|
|
|
|
process_menu(menu_no, &selected_disk);
|
|
|
|
free_menu(menu_no);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
2003-05-19 00:04:21 +04:00
|
|
|
|
2003-07-11 19:28:58 +04:00
|
|
|
disk = disks + selected_disk;
|
|
|
|
strlcpy(diskdev, disk->dd_name, sizeof diskdev);
|
1997-10-07 08:01:29 +04:00
|
|
|
|
2006-01-13 01:02:44 +03:00
|
|
|
/* Use as a default disk if the user has the sets on a local disk */
|
|
|
|
strlcpy(localfs_dev, disk->dd_name, sizeof localfs_dev);
|
|
|
|
|
1999-03-14 17:19:05 +03:00
|
|
|
sectorsize = disk->dd_secsize;
|
1999-03-31 04:44:48 +04:00
|
|
|
dlcyl = disk->dd_cyl;
|
|
|
|
dlhead = disk->dd_head;
|
|
|
|
dlsec = disk->dd_sec;
|
|
|
|
dlsize = disk->dd_totsec;
|
2004-05-16 01:53:29 +04:00
|
|
|
no_mbr = disk->dd_no_mbr;
|
2003-07-11 19:28:58 +04:00
|
|
|
if (dlsize == 0)
|
|
|
|
dlsize = disk->dd_cyl * disk->dd_head * disk->dd_sec;
|
1999-03-31 04:44:48 +04:00
|
|
|
dlcylsize = dlhead * dlsec;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
/* Get existing/default label */
|
2004-03-26 22:55:13 +03:00
|
|
|
memset(&oldlabel, 0, sizeof oldlabel);
|
2003-07-07 16:30:19 +04:00
|
|
|
incorelabel(diskdev, oldlabel);
|
|
|
|
|
2004-03-26 20:28:55 +03:00
|
|
|
/* Set 'target' label to current label in case we don't change it */
|
|
|
|
memcpy(&bsdlabel, &oldlabel, sizeof bsdlabel);
|
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
return numdisks;
|
|
|
|
}
|
|
|
|
|
2003-06-09 23:06:48 +04:00
|
|
|
void
|
2003-07-07 16:30:19 +04:00
|
|
|
fmt_fspart(menudesc *m, int ptn, void *arg)
|
2003-06-09 23:06:48 +04:00
|
|
|
{
|
|
|
|
int poffset, psize, pend;
|
|
|
|
const char *desc;
|
2003-07-07 16:30:19 +04:00
|
|
|
static const char *Yes, *No;
|
2003-11-30 17:36:43 +03:00
|
|
|
partinfo *p = bsdlabel + ptn;
|
2003-07-07 16:30:19 +04:00
|
|
|
|
|
|
|
if (Yes == NULL) {
|
|
|
|
Yes = msg_string(MSG_Yes);
|
|
|
|
No = msg_string(MSG_No);
|
|
|
|
}
|
2003-06-09 23:06:48 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
poffset = p->pi_offset / sizemult;
|
|
|
|
psize = p->pi_size / sizemult;
|
2003-06-09 23:06:48 +04:00
|
|
|
if (psize == 0)
|
|
|
|
pend = 0;
|
|
|
|
else
|
2003-11-30 17:36:43 +03:00
|
|
|
pend = (p->pi_offset + p->pi_size) / sizemult - 1;
|
|
|
|
|
|
|
|
if (p->pi_fstype == FS_BSDFFS)
|
|
|
|
if (p->pi_flags & PIF_FFSv2)
|
|
|
|
desc = "FFSv2";
|
|
|
|
else
|
|
|
|
desc = "FFSv1";
|
|
|
|
else
|
|
|
|
desc = fstypenames[p->pi_fstype];
|
2003-06-09 23:06:48 +04:00
|
|
|
|
|
|
|
#ifdef PART_BOOT
|
|
|
|
if (ptn == PART_BOOT)
|
|
|
|
desc = msg_string(MSG_Boot_partition_cant_change);
|
|
|
|
#endif
|
|
|
|
if (ptn == getrawpartition())
|
|
|
|
desc = msg_string(MSG_Whole_disk_cant_change);
|
|
|
|
else {
|
2003-11-30 17:36:43 +03:00
|
|
|
if (ptn == PART_C)
|
2003-06-09 23:06:48 +04:00
|
|
|
desc = msg_string(MSG_NetBSD_partition_cant_change);
|
|
|
|
}
|
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
wprintw(m->mw, msg_string(MSG_fspart_row),
|
|
|
|
poffset, pend, psize, desc,
|
2003-11-30 17:36:43 +03:00
|
|
|
p->pi_flags & PIF_NEWFS ? Yes : "",
|
|
|
|
p->pi_flags & PIF_MOUNT ? Yes : "",
|
|
|
|
p->pi_mount);
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
1997-11-09 07:14:10 +03:00
|
|
|
/*
|
|
|
|
* Label a disk using an MD-specific string DISKLABEL_CMD for
|
2003-06-17 00:10:02 +04:00
|
|
|
* to invoke disklabel.
|
1997-11-09 07:14:10 +03:00
|
|
|
* if MD code does not define DISKLABEL_CMD, this is a no-op.
|
|
|
|
*
|
2003-06-17 00:10:02 +04:00
|
|
|
* i386 port uses "/sbin/disklabel -w -r", just like i386
|
1997-11-09 07:14:10 +03:00
|
|
|
* miniroot scripts, though this may leave a bogus incore label.
|
|
|
|
*
|
2003-06-17 00:10:02 +04:00
|
|
|
* Sun ports should use DISKLABEL_CMD "/sbin/disklabel -w"
|
|
|
|
* to get incore to ondisk inode translation for the Sun proms.
|
1997-11-09 07:14:10 +03:00
|
|
|
*/
|
2000-12-06 07:53:37 +03:00
|
|
|
int
|
|
|
|
write_disklabel (void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
1997-11-09 07:14:10 +03:00
|
|
|
|
|
|
|
#ifdef DISKLABEL_CMD
|
1997-09-27 03:02:53 +04:00
|
|
|
/* disklabel the disk */
|
2003-11-30 17:36:43 +03:00
|
|
|
return run_program(RUN_DISPLAY, "%s -f /tmp/disktab %s '%s'",
|
2003-10-20 00:17:31 +04:00
|
|
|
DISKLABEL_CMD, diskdev, bsddiskname);
|
2003-01-10 23:00:27 +03:00
|
|
|
#else
|
1999-04-09 14:24:38 +04:00
|
|
|
return 0;
|
2003-01-10 23:00:27 +03:00
|
|
|
#endif
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
ptn_sort(const void *a, const void *b)
|
|
|
|
{
|
2003-07-25 12:26:21 +04:00
|
|
|
return strcmp(bsdlabel[*(const int *)a].pi_mount,
|
|
|
|
bsdlabel[*(const int *)b].pi_mount);
|
2003-07-07 16:30:19 +04:00
|
|
|
}
|
|
|
|
|
2000-12-06 07:53:37 +03:00
|
|
|
int
|
|
|
|
make_filesystems(void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
int i;
|
2003-07-07 16:30:19 +04:00
|
|
|
int ptn;
|
|
|
|
int ptn_order[nelem(bsdlabel)];
|
2003-11-30 17:36:43 +03:00
|
|
|
int error = 0;
|
2003-07-07 16:30:19 +04:00
|
|
|
int maxpart = getmaxpartitions();
|
2003-11-30 17:36:43 +03:00
|
|
|
char *newfs;
|
|
|
|
const char *mnt_opts;
|
|
|
|
const char *fsname;
|
|
|
|
partinfo *lbl;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
if (maxpart > nelem(bsdlabel))
|
|
|
|
maxpart = nelem(bsdlabel);
|
|
|
|
|
|
|
|
/* Making new file systems and mounting them */
|
|
|
|
|
|
|
|
/* sort to ensure /usr/local is mounted after /usr (etc) */
|
|
|
|
for (i = 0; i < maxpart; i++)
|
|
|
|
ptn_order[i] = i;
|
|
|
|
qsort(ptn_order, maxpart, sizeof ptn_order[0], ptn_sort);
|
|
|
|
|
|
|
|
for (i = 0; i < maxpart; i++) {
|
1997-11-03 03:04:53 +03:00
|
|
|
/*
|
2003-05-19 00:04:21 +04:00
|
|
|
* newfs and mount. For now, process only BSD filesystems.
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
* but if this is the mounted-on root, has no mount
|
2003-05-19 00:04:21 +04:00
|
|
|
* point defined, or is marked preserve, don't touch it!
|
1997-11-03 03:04:53 +03:00
|
|
|
*/
|
2003-07-07 16:30:19 +04:00
|
|
|
ptn = ptn_order[i];
|
2003-11-30 17:36:43 +03:00
|
|
|
lbl = bsdlabel + ptn;
|
|
|
|
|
2003-09-27 14:47:17 +04:00
|
|
|
if (is_active_rootpart(diskdev, ptn))
|
2003-07-07 16:30:19 +04:00
|
|
|
continue;
|
2003-06-09 23:06:48 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
if (*lbl->pi_mount == 0)
|
|
|
|
/* No mount point */
|
|
|
|
continue;
|
2003-06-09 23:06:48 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
newfs = NULL;
|
|
|
|
mnt_opts = NULL;
|
|
|
|
fsname = NULL;
|
|
|
|
switch (lbl->pi_fstype) {
|
|
|
|
case FS_APPLEUFS:
|
|
|
|
asprintf(&newfs, "/sbin/newfs %s%.0d",
|
|
|
|
lbl->pi_isize != 0 ? "-i" : "", lbl->pi_isize);
|
|
|
|
mnt_opts = "-tffs -o async";
|
|
|
|
fsname = "ffs";
|
|
|
|
break;
|
2003-06-09 23:06:48 +04:00
|
|
|
case FS_BSDFFS:
|
2006-01-15 23:33:05 +03:00
|
|
|
asprintf(&newfs,
|
|
|
|
"/sbin/newfs -V2 -O %d -b %d -f %d%s%.0d",
|
|
|
|
lbl->pi_flags & PIF_FFSv2 ? 2 : 1,
|
|
|
|
lbl->pi_fsize * lbl->pi_frag, lbl->pi_fsize,
|
|
|
|
lbl->pi_isize != 0 ? " -i " : "", lbl->pi_isize);
|
2003-11-30 17:36:43 +03:00
|
|
|
mnt_opts = "-tffs -o async";
|
|
|
|
fsname = "ffs";
|
2003-06-09 23:06:48 +04:00
|
|
|
break;
|
|
|
|
case FS_BSDLFS:
|
2003-11-30 17:36:43 +03:00
|
|
|
asprintf(&newfs, "/sbin/newfs_lfs -b %d",
|
|
|
|
lbl->pi_fsize * lbl->pi_frag);
|
|
|
|
mnt_opts = "-tlfs";
|
|
|
|
fsname = "lfs";
|
|
|
|
break;
|
|
|
|
case FS_MSDOS:
|
2008-02-02 07:15:27 +03:00
|
|
|
#ifdef USE_NEWFS_MSDOS
|
|
|
|
asprintf(&newfs, "/sbin/newfs_msdos");
|
|
|
|
#endif
|
2003-11-30 17:36:43 +03:00
|
|
|
mnt_opts = "-tmsdos";
|
|
|
|
fsname = "msdos";
|
2003-06-09 23:06:48 +04:00
|
|
|
break;
|
2006-01-09 13:00:34 +03:00
|
|
|
#ifdef USE_SYSVBFS
|
|
|
|
case FS_SYSVBFS:
|
|
|
|
asprintf(&newfs, "/sbin/newfs_sysvbfs");
|
|
|
|
mnt_opts = "-tsysvbfs";
|
|
|
|
fsname = "sysvbfs";
|
|
|
|
break;
|
|
|
|
#endif
|
2003-06-09 23:06:48 +04:00
|
|
|
}
|
2003-11-30 17:36:43 +03:00
|
|
|
if (lbl->pi_flags & PIF_NEWFS && newfs != NULL) {
|
2008-02-02 07:15:27 +03:00
|
|
|
#ifdef USE_NEWFS_MSDOS
|
|
|
|
if (lbl->pi_fstype == FS_MSDOS) {
|
|
|
|
/* newfs only if mount fails */
|
|
|
|
if (run_program(RUN_SILENT | RUN_ERROR_OK,
|
|
|
|
"mount -rt msdos /dev/%s%c /mnt2",
|
|
|
|
diskdev, 'a' + ptn) != 0)
|
|
|
|
error = run_program(
|
|
|
|
RUN_DISPLAY | RUN_PROGRESS,
|
|
|
|
"%s /dev/r%s%c",
|
|
|
|
newfs, diskdev, 'a' + ptn);
|
|
|
|
else {
|
|
|
|
run_program(RUN_SILENT | RUN_ERROR_OK,
|
|
|
|
"umount /mnt2");
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
2003-11-30 17:36:43 +03:00
|
|
|
error = run_program(RUN_DISPLAY | RUN_PROGRESS,
|
|
|
|
"%s /dev/r%s%c", newfs, diskdev, 'a' + ptn);
|
|
|
|
} else {
|
|
|
|
/* We'd better check it isn't dirty */
|
|
|
|
error = fsck_preen(diskdev, ptn, fsname);
|
|
|
|
}
|
|
|
|
free(newfs);
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if (lbl->pi_flags & PIF_MOUNT && mnt_opts != NULL) {
|
|
|
|
make_target_dir(lbl->pi_mount);
|
|
|
|
error = target_mount(mnt_opts, diskdev, ptn,
|
|
|
|
lbl->pi_mount);
|
|
|
|
if (error) {
|
|
|
|
msg_display(MSG_mountfail,
|
|
|
|
diskdev, 'a' + ptn, lbl->pi_mount);
|
|
|
|
process_menu(MENU_ok, NULL);
|
|
|
|
return error;
|
|
|
|
}
|
- Add 2 functions in label.c, getpartoff()/getpartsize() used to let the user
enter partitions offet and size. The user can chose unit independantly of
the unit used for display ('M'/'c'/'s'). These functions do the proper
bound checks and alignement/roudups. Used in the edfspart menu and
i386 md_make_bsd_partitions() (other ports should do the change as
well).
- now that getpartsize() does the rigth thing, kill the swapadj hack (which was
buggy anyway).
- in i386 md_make_bsd_partitions(), don't propose defaults that don't fit on
the disk. If the disk is too small, fallback to custom instead.
- fix a bug in mbr.c, where the partition flags would not have always been
reset. sysinst created me a MBR with 2 active partition. The boot code
doesn't like it :)
- added a message for eventual mount failures.
- killed donewfs and extracting messages, as we run the commands in a
subwindow these messages just flashed on the screen.
- Changes a few exit(1) to return(1), to give the user a second chance.
- added msg_clear() or wclear(stdscr) in a place or two, to make
display a bit nicer.
- in run_cmd(), if the command succeeded, don't wait for the user to
press enter.
1999-04-12 02:40:19 +04:00
|
|
|
}
|
1997-11-03 03:04:53 +03:00
|
|
|
}
|
2003-11-30 17:36:43 +03:00
|
|
|
return 0;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
2000-12-06 07:53:37 +03:00
|
|
|
int
|
|
|
|
make_fstab(void)
|
1997-09-27 03:02:53 +04:00
|
|
|
{
|
|
|
|
FILE *f;
|
2003-01-10 23:00:27 +03:00
|
|
|
int i, swap_dev = -1;
|
1997-09-27 03:02:53 +04:00
|
|
|
|
|
|
|
/* Create the fstab. */
|
1997-11-02 11:20:40 +03:00
|
|
|
make_target_dir("/etc");
|
1999-03-31 04:44:48 +04:00
|
|
|
f = target_fopen("/etc/fstab", "w");
|
1999-01-21 11:02:17 +03:00
|
|
|
if (logging)
|
2002-12-05 04:17:15 +03:00
|
|
|
(void)fprintf(logfp,
|
|
|
|
"Creating %s/etc/fstab.\n", target_prefix());
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(NULL, "cat <<EOF >%s/etc/fstab\n", target_prefix());
|
1999-01-21 11:02:17 +03:00
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
if (f == NULL) {
|
|
|
|
#ifndef DEBUG
|
1999-04-09 14:24:38 +04:00
|
|
|
msg_display(MSG_createfstab);
|
1999-01-21 11:02:17 +03:00
|
|
|
if (logging)
|
2002-12-05 04:17:15 +03:00
|
|
|
(void)fprintf(logfp, "Failed to make /etc/fstab!\n");
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ok, NULL);
|
- Add 2 functions in label.c, getpartoff()/getpartsize() used to let the user
enter partitions offet and size. The user can chose unit independantly of
the unit used for display ('M'/'c'/'s'). These functions do the proper
bound checks and alignement/roudups. Used in the edfspart menu and
i386 md_make_bsd_partitions() (other ports should do the change as
well).
- now that getpartsize() does the rigth thing, kill the swapadj hack (which was
buggy anyway).
- in i386 md_make_bsd_partitions(), don't propose defaults that don't fit on
the disk. If the disk is too small, fallback to custom instead.
- fix a bug in mbr.c, where the partition flags would not have always been
reset. sysinst created me a MBR with 2 active partition. The boot code
doesn't like it :)
- added a message for eventual mount failures.
- killed donewfs and extracting messages, as we run the commands in a
subwindow these messages just flashed on the screen.
- Changes a few exit(1) to return(1), to give the user a second chance.
- added msg_clear() or wclear(stdscr) in a place or two, to make
display a bit nicer.
- in run_cmd(), if the command succeeded, don't wait for the user to
press enter.
1999-04-12 02:40:19 +04:00
|
|
|
return 1;
|
1997-09-27 03:02:53 +04:00
|
|
|
#else
|
|
|
|
f = stdout;
|
2003-05-19 00:04:21 +04:00
|
|
|
#endif
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
|
2005-09-12 19:47:09 +04:00
|
|
|
scripting_fprintf(f, "# NetBSD /etc/fstab\n# See /usr/share/examples/"
|
|
|
|
"fstab/ for more examples.\n", target_prefix());
|
2003-06-09 23:06:48 +04:00
|
|
|
for (i = 0; i < getmaxpartitions(); i++) {
|
|
|
|
const char *s = "";
|
|
|
|
const char *mp = bsdlabel[i].pi_mount;
|
|
|
|
const char *fstype = "ffs";
|
2003-08-05 17:35:26 +04:00
|
|
|
int fsck_pass = 0, dump_freq = 0;
|
2003-06-09 23:06:48 +04:00
|
|
|
|
|
|
|
if (!*mp) {
|
|
|
|
/*
|
|
|
|
* No mount point specified, comment out line and
|
|
|
|
* use /mnt as a placeholder for the mount point.
|
|
|
|
*/
|
|
|
|
s = "# ";
|
|
|
|
mp = "/mnt";
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (bsdlabel[i].pi_fstype) {
|
2003-08-05 17:35:26 +04:00
|
|
|
case FS_UNUSED:
|
|
|
|
continue;
|
2003-06-09 23:06:48 +04:00
|
|
|
case FS_BSDLFS:
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
/* If there is no LFS, just comment it out. */
|
2006-11-30 23:48:13 +03:00
|
|
|
if (!check_lfs_progs())
|
2003-06-09 23:06:48 +04:00
|
|
|
s = "# ";
|
|
|
|
fstype = "lfs";
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case FS_BSDFFS:
|
2003-11-30 17:36:43 +03:00
|
|
|
fsck_pass = (strcmp(mp, "/") == 0) ? 1 : 2;
|
2003-08-05 17:35:26 +04:00
|
|
|
dump_freq = 1;
|
2003-06-09 23:06:48 +04:00
|
|
|
break;
|
|
|
|
case FS_MSDOS:
|
2003-08-05 17:35:26 +04:00
|
|
|
fstype = "msdos";
|
2003-06-09 23:06:48 +04:00
|
|
|
break;
|
|
|
|
case FS_SWAP:
|
2003-01-10 23:00:27 +03:00
|
|
|
if (swap_dev == -1)
|
|
|
|
swap_dev = i;
|
2005-09-12 19:47:09 +04:00
|
|
|
scripting_fprintf(f, "/dev/%s%c\t\tnone\tswap\tsw\t\t 0 0\n",
|
2003-05-19 00:04:21 +04:00
|
|
|
diskdev, 'a' + i);
|
2003-08-05 17:35:26 +04:00
|
|
|
continue;
|
2006-01-09 13:00:34 +03:00
|
|
|
#ifdef USE_SYSVBFS
|
|
|
|
case FS_SYSVBFS:
|
|
|
|
fstype = "sysvbfs";
|
|
|
|
make_target_dir("/stand");
|
|
|
|
break;
|
|
|
|
#endif
|
2003-08-05 17:35:26 +04:00
|
|
|
default:
|
|
|
|
fstype = "???";
|
|
|
|
s = "# ";
|
2003-06-09 23:06:48 +04:00
|
|
|
break;
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
2005-08-28 17:10:20 +04:00
|
|
|
/* The code that remounts root rw doesn't check the partition */
|
|
|
|
if (strcmp(mp, "/") == 0 && !(bsdlabel[i].pi_flags & PIF_MOUNT))
|
|
|
|
s = "# ";
|
|
|
|
|
2005-09-12 19:47:09 +04:00
|
|
|
scripting_fprintf(f, "%s/dev/%s%c\t\t%s\t%s\trw%s%s%s%s%s%s%s%s\t\t %d %d\n",
|
2003-08-05 17:35:26 +04:00
|
|
|
s, diskdev, 'a' + i, mp, fstype,
|
|
|
|
bsdlabel[i].pi_flags & PIF_MOUNT ? "" : ",noauto",
|
|
|
|
bsdlabel[i].pi_flags & PIF_ASYNC ? ",async" : "",
|
|
|
|
bsdlabel[i].pi_flags & PIF_NOATIME ? ",noatime" : "",
|
2003-08-10 18:51:48 +04:00
|
|
|
bsdlabel[i].pi_flags & PIF_NODEV ? ",nodev" : "",
|
2003-08-05 17:35:26 +04:00
|
|
|
bsdlabel[i].pi_flags & PIF_NODEVMTIME ? ",nodevmtime" : "",
|
2003-08-10 18:51:48 +04:00
|
|
|
bsdlabel[i].pi_flags & PIF_NOEXEC ? ",noexec" : "",
|
|
|
|
bsdlabel[i].pi_flags & PIF_NOSUID ? ",nosuid" : "",
|
2003-08-05 17:35:26 +04:00
|
|
|
bsdlabel[i].pi_flags & PIF_SOFTDEP ? ",softdep" : "",
|
|
|
|
dump_freq, fsck_pass);
|
2003-06-09 23:06:48 +04:00
|
|
|
}
|
|
|
|
|
2003-06-07 01:37:13 +04:00
|
|
|
if (tmp_mfs_size != 0) {
|
2003-01-10 23:00:27 +03:00
|
|
|
if (swap_dev != -1)
|
2005-09-12 19:47:09 +04:00
|
|
|
scripting_fprintf(f, "/dev/%s%c\t\t/tmp\tmfs\trw,-s=%d\n",
|
2003-06-07 01:37:13 +04:00
|
|
|
diskdev, 'a' + swap_dev, tmp_mfs_size);
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
else
|
2005-09-12 19:47:09 +04:00
|
|
|
scripting_fprintf(f, "swap\t\t/tmp\tmfs\trw,-s=%d\n",
|
2003-08-04 13:23:50 +04:00
|
|
|
tmp_mfs_size);
|
1999-01-21 11:02:17 +03:00
|
|
|
}
|
2003-06-09 23:06:48 +04:00
|
|
|
|
2007-06-18 20:58:42 +04:00
|
|
|
/* Add /kern, /proc and /dev/pts to fstab and make mountpoint. */
|
2005-09-12 19:47:09 +04:00
|
|
|
scripting_fprintf(f, "kernfs\t\t/kern\tkernfs\trw\n");
|
2007-06-18 20:58:42 +04:00
|
|
|
scripting_fprintf(f, "ptyfs\t\t/dev/pts\tptyfs\trw\n");
|
2005-09-12 19:47:09 +04:00
|
|
|
scripting_fprintf(f, "procfs\t\t/proc\tprocfs\trw,noauto\n");
|
2008-01-15 15:09:24 +03:00
|
|
|
scripting_fprintf(f, "/dev/cd0a\t\t/cdrom\tcd9660\tro,noauto\n");
|
2003-06-09 23:06:48 +04:00
|
|
|
make_target_dir("/kern");
|
2003-08-05 17:35:26 +04:00
|
|
|
make_target_dir("/proc");
|
2007-06-18 20:58:42 +04:00
|
|
|
make_target_dir("/dev/pts");
|
2008-01-15 15:09:24 +03:00
|
|
|
make_target_dir("/cdrom");
|
2003-06-09 23:06:48 +04:00
|
|
|
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
scripting_fprintf(NULL, "EOF\n");
|
|
|
|
|
1997-09-27 03:02:53 +04:00
|
|
|
#ifndef DEBUG
|
|
|
|
fclose(f);
|
1999-01-21 11:02:17 +03:00
|
|
|
fflush(NULL);
|
1997-09-27 03:02:53 +04:00
|
|
|
#endif
|
1999-04-09 14:24:38 +04:00
|
|
|
return 0;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
|
|
|
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
|
1997-11-13 06:06:44 +03:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
static int
|
2003-01-10 23:00:27 +03:00
|
|
|
/*ARGSUSED*/
|
|
|
|
foundffs(struct data *list, size_t num)
|
1997-10-01 09:04:24 +04:00
|
|
|
{
|
2003-11-30 17:36:43 +03:00
|
|
|
int error;
|
1997-10-01 09:04:24 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
if (num < 2 || strcmp(list[1].u.s_val, "/") == 0 ||
|
|
|
|
strstr(list[2].u.s_val, "noauto") != NULL)
|
|
|
|
return 0;
|
1997-10-07 08:01:29 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
error = fsck_preen(list[0].u.s_val, ' '-'a', "ffs");
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
1997-10-01 09:04:24 +04:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
error = target_mount("", list[0].u.s_val, ' '-'a', list[1].u.s_val);
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
return 0;
|
1997-10-01 09:04:24 +04:00
|
|
|
}
|
|
|
|
|
2006-01-09 13:00:34 +03:00
|
|
|
#ifdef USE_SYSVBFS
|
|
|
|
static int
|
|
|
|
/*ARGSUSED*/
|
|
|
|
foundsysvbfs(struct data *list, size_t num)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (num < 2 || strcmp(list[1].u.s_val, "/") == 0 ||
|
|
|
|
strstr(list[2].u.s_val, "noauto") != NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error = target_mount("", list[0].u.s_val, ' '-'a', list[1].u.s_val);
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/*
|
2004-04-25 21:15:27 +04:00
|
|
|
* Do an fsck. On failure, inform the user by showing a warning
|
1997-11-05 10:28:20 +03:00
|
|
|
* message and doing menu_ok() before proceeding.
|
2003-11-30 17:36:43 +03:00
|
|
|
* Returns 0 on success, or nonzero return code from fsck() on failure.
|
1997-11-05 10:28:20 +03:00
|
|
|
*/
|
2003-11-30 17:36:43 +03:00
|
|
|
static int
|
|
|
|
fsck_preen(const char *disk, int ptn, const char *fsname)
|
1997-11-03 05:38:41 +03:00
|
|
|
{
|
2003-11-30 17:36:43 +03:00
|
|
|
char *prog;
|
extend sysinst disk handling, some general clean ups, better /etc support
and some sparc64 fixes. details:
- new scripting_{,v}fprintf() that also write to the script log (if open).
- support of creation of LFS filesystems
- standard installs now allow one to choose which file systems to create,
out of the list of /usr, /var, /home, MFS /tmp, and swap. a / is always
created, but the rest all optional. [*]
- new disklabel method: use existing. this requires one to fill in the
mount points (and having at least a "/" is enforced).
- preservation of existing filesystems (at install) is supported.
- rewrote most of make_fstab(): the entire thing is generated from the
bsdlabel now, rather than hard coding / to 'a' and swap to 'b'. create
MFS /tmp if requested.
- if IPv6 support isn't present, don't display any ipv6 messages.
- better rc.conf support
- sparc & sparc64 default to "cylinders" now.
- choosing "standard" instead of "standard with X" de-selects the X pkgs
by default.
- sparc64: don't install bootblocks until we have a complete system, avoids
booting with no /dev/console.
- sparc64: bump STDNEEDMB, it is way low.
[*] i have added default values for DEFVARSIZE & DEFUSRSIZE (this is used
only if /usr and /home are selected) to each port, based on STDNEEDMB. as
such, my guesses might be wrong so port maintainers should look at these.
2001-01-14 05:38:13 +03:00
|
|
|
int error;
|
2003-11-30 17:36:43 +03:00
|
|
|
|
|
|
|
ptn += 'a';
|
|
|
|
if (fsname == NULL)
|
|
|
|
return 0;
|
|
|
|
/* first check fsck program exists, if not assue ok */
|
|
|
|
asprintf(&prog, "/sbin/fsck_%s", fsname);
|
|
|
|
if (prog == NULL)
|
|
|
|
return 0;
|
|
|
|
if (access(prog, X_OK) != 0)
|
|
|
|
return 0;
|
2004-04-25 00:42:39 +04:00
|
|
|
if (!strcmp(fsname,"ffs"))
|
2004-04-25 22:40:37 +04:00
|
|
|
fixsb(prog, disk, ptn);
|
2003-11-30 17:36:43 +03:00
|
|
|
error = run_program(0, "%s -p -q /dev/r%s%c", prog, disk, ptn);
|
|
|
|
free(prog);
|
|
|
|
if (error != 0) {
|
|
|
|
msg_display(MSG_badfs, disk, ptn, error);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ok, NULL);
|
2004-04-25 21:15:27 +04:00
|
|
|
/* XXX at this point maybe we should run a full fsck? */
|
1997-10-07 08:01:29 +04:00
|
|
|
}
|
1997-11-05 10:28:20 +03:00
|
|
|
return error;
|
|
|
|
}
|
1997-10-01 09:04:24 +04:00
|
|
|
|
2004-04-25 22:40:37 +04:00
|
|
|
/* This performs the same function as the etc/rc.d/fixsb script
|
|
|
|
* which attempts to correct problems with ffs1 filesystems
|
|
|
|
* which may have been introduced by booting a netbsd-current kernel
|
|
|
|
* from between April of 2003 and January 2004. For more information
|
|
|
|
* This script was developed as a response to NetBSD pr install/25138
|
|
|
|
* Additional prs regarding the original issue include:
|
|
|
|
* bin/17910 kern/21283 kern/21404 port-macppc/23925 port-macppc/23926
|
2004-04-25 21:15:27 +04:00
|
|
|
*/
|
2004-04-25 00:42:39 +04:00
|
|
|
static void
|
2004-04-25 22:40:37 +04:00
|
|
|
fixsb(const char *prog, const char *disk, char ptn)
|
2004-04-25 00:42:39 +04:00
|
|
|
{
|
|
|
|
int fd;
|
2004-04-25 00:48:57 +04:00
|
|
|
int rval;
|
2004-04-25 22:40:37 +04:00
|
|
|
union {
|
|
|
|
struct fs fs;
|
|
|
|
char buf[SBLOCKSIZE];
|
|
|
|
} sblk;
|
|
|
|
struct fs *fs = &sblk.fs;
|
|
|
|
|
2004-04-29 00:59:32 +04:00
|
|
|
snprintf(sblk.buf, sizeof(sblk.buf), "/dev/r%s%c",
|
|
|
|
disk, ptn == ' ' ? 0 : ptn);
|
2004-04-25 22:40:37 +04:00
|
|
|
fd = open(sblk.buf, O_RDONLY);
|
2004-04-25 00:42:39 +04:00
|
|
|
if (fd == -1)
|
|
|
|
return;
|
2004-04-25 21:15:27 +04:00
|
|
|
|
|
|
|
/* Read ffsv1 main superblock */
|
2004-04-25 22:40:37 +04:00
|
|
|
rval = pread(fd, sblk.buf, sizeof sblk.buf, SBLOCK_UFS1);
|
2004-04-25 00:42:39 +04:00
|
|
|
close(fd);
|
2004-04-25 22:40:37 +04:00
|
|
|
if (rval != sizeof sblk.buf)
|
2004-04-25 00:42:39 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (fs->fs_magic != FS_UFS1_MAGIC &&
|
|
|
|
fs->fs_magic != FS_UFS1_MAGIC_SWAPPED)
|
2004-04-25 21:15:27 +04:00
|
|
|
/* Not FFSv1 */
|
2004-04-25 00:42:39 +04:00
|
|
|
return;
|
|
|
|
if (fs->fs_old_flags & FS_FLAGS_UPDATED)
|
2004-04-25 21:15:27 +04:00
|
|
|
/* properly updated fslevel 4 */
|
2004-04-25 00:42:39 +04:00
|
|
|
return;
|
|
|
|
if (fs->fs_bsize != fs->fs_maxbsize)
|
2004-04-25 21:15:27 +04:00
|
|
|
/* not messed up */
|
2004-04-25 00:42:39 +04:00
|
|
|
return;
|
|
|
|
|
2004-04-25 21:15:27 +04:00
|
|
|
/*
|
|
|
|
* OK we have a munged fs, first 'upgrade' to fslevel 4,
|
|
|
|
* We specify -b16 in order to stop fsck bleating that the
|
|
|
|
* sb doesn't match the first alternate.
|
|
|
|
*/
|
2004-04-25 22:40:37 +04:00
|
|
|
run_program(RUN_DISPLAY | RUN_PROGRESS,
|
2004-04-25 22:50:44 +04:00
|
|
|
"%s -p -b 16 -c 4 /dev/r%s%c", prog, disk, ptn);
|
2004-04-25 21:15:27 +04:00
|
|
|
/* Then downgrade to fslevel 3 */
|
2004-04-25 22:40:37 +04:00
|
|
|
run_program(RUN_DISPLAY | RUN_PROGRESS,
|
|
|
|
"%s -p -c 3 /dev/r%s%c", prog, disk, ptn);
|
2004-04-25 00:42:39 +04:00
|
|
|
}
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/*
|
|
|
|
* fsck and mount the root partition.
|
|
|
|
*/
|
2006-01-13 01:02:44 +03:00
|
|
|
static int
|
2003-11-30 17:36:43 +03:00
|
|
|
mount_root(void)
|
1997-11-05 10:28:20 +03:00
|
|
|
{
|
2003-06-17 00:10:02 +04:00
|
|
|
int error;
|
1997-11-05 10:28:20 +03:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
error = fsck_preen(diskdev, rootpart, "ffs");
|
1997-11-05 10:28:20 +03:00
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
|
2003-06-17 00:10:02 +04:00
|
|
|
/* Mount /dev/<diskdev>a on target's "".
|
2003-05-19 00:04:21 +04:00
|
|
|
* If we pass "" as mount-on, Prefixing will DTRT.
|
1997-11-05 10:28:20 +03:00
|
|
|
* for now, use no options.
|
|
|
|
* XXX consider -o remount in case target root is
|
2003-06-17 00:10:02 +04:00
|
|
|
* current root, still readonly from single-user?
|
1997-11-05 10:28:20 +03:00
|
|
|
*/
|
2003-11-30 17:36:43 +03:00
|
|
|
return target_mount("", diskdev, rootpart, "");
|
1997-11-03 05:38:41 +03:00
|
|
|
}
|
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
/* Get information on the file systems mounted from the root filesystem.
|
|
|
|
* Offer to convert them into 4.4BSD inodes if they are not 4.4BSD
|
|
|
|
* inodes. Fsck them. Mount them.
|
|
|
|
*/
|
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
int
|
2003-11-30 17:36:43 +03:00
|
|
|
mount_disks(void)
|
2003-06-16 23:42:13 +04:00
|
|
|
{
|
|
|
|
char *fstab;
|
1997-11-03 05:38:41 +03:00
|
|
|
int fstabsize;
|
1997-11-05 10:28:20 +03:00
|
|
|
int error;
|
1997-11-03 05:38:41 +03:00
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
static struct lookfor fstabbuf[] = {
|
|
|
|
{"/dev/", "/dev/%s %s ffs %s", "c", NULL, 0, 0, foundffs},
|
|
|
|
{"/dev/", "/dev/%s %s ufs %s", "c", NULL, 0, 0, foundffs},
|
2006-01-09 13:00:34 +03:00
|
|
|
#ifdef USE_SYSVBFS
|
|
|
|
{"/dev/", "/dev/%s %s sysvbfs %s", "c", NULL, 0, 0,
|
|
|
|
foundsysvbfs},
|
|
|
|
#endif
|
2003-11-30 17:36:43 +03:00
|
|
|
};
|
|
|
|
static size_t numfstabbuf = sizeof(fstabbuf) / sizeof(struct lookfor);
|
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
/* First the root device. */
|
2006-01-13 01:02:44 +03:00
|
|
|
if (target_already_root())
|
|
|
|
/* avoid needing to call target_already_root() again */
|
|
|
|
targetroot_mnt[0] = 0;
|
|
|
|
else {
|
2003-11-30 17:36:43 +03:00
|
|
|
error = mount_root();
|
2003-05-19 00:04:21 +04:00
|
|
|
if (error != 0 && error != EBUSY)
|
1997-11-03 05:38:41 +03:00
|
|
|
return 0;
|
1997-10-01 09:04:24 +04:00
|
|
|
}
|
|
|
|
|
1997-11-05 10:28:20 +03:00
|
|
|
/* Check the target /etc/fstab exists before trying to parse it. */
|
2003-05-19 00:04:21 +04:00
|
|
|
if (target_dir_exists_p("/etc") == 0 ||
|
1997-12-05 17:00:59 +03:00
|
|
|
target_file_exists_p("/etc/fstab") == 0) {
|
1997-11-05 10:28:20 +03:00
|
|
|
msg_display(MSG_noetcfstab, diskdev);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ok, NULL);
|
1997-11-05 10:28:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-11-03 05:38:41 +03:00
|
|
|
/* Get fstab entries from the target-root /etc/fstab. */
|
1999-03-31 04:44:48 +04:00
|
|
|
fstabsize = target_collect_file(T_FILE, &fstab, "/etc/fstab");
|
1997-10-01 09:04:24 +04:00
|
|
|
if (fstabsize < 0) {
|
|
|
|
/* error ! */
|
1997-11-05 10:28:20 +03:00
|
|
|
msg_display(MSG_badetcfstab, diskdev);
|
2003-06-03 15:54:48 +04:00
|
|
|
process_menu(MENU_ok, NULL);
|
1997-10-01 09:04:24 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2003-11-30 17:36:43 +03:00
|
|
|
error = walk(fstab, (size_t)fstabsize, fstabbuf, numfstabbuf);
|
1997-10-01 09:04:24 +04:00
|
|
|
free(fstab);
|
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
return error;
|
1997-09-27 03:02:53 +04:00
|
|
|
}
|
2000-09-27 16:42:04 +04:00
|
|
|
|
|
|
|
int
|
2003-07-25 12:26:21 +04:00
|
|
|
set_swap(const char *disk, partinfo *pp)
|
2000-09-27 16:42:04 +04:00
|
|
|
{
|
2003-07-07 16:30:19 +04:00
|
|
|
int i;
|
2003-06-16 14:42:47 +04:00
|
|
|
char *cp;
|
|
|
|
int rval;
|
2000-09-27 16:42:04 +04:00
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
if (pp == NULL)
|
|
|
|
pp = oldlabel;
|
2000-09-27 16:42:04 +04:00
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
for (i = 0; i < MAXPARTITIONS; i++) {
|
2003-06-16 14:42:47 +04:00
|
|
|
if (pp[i].pi_fstype != FS_SWAP)
|
|
|
|
continue;
|
2003-07-25 12:26:21 +04:00
|
|
|
asprintf(&cp, "/dev/%s%c", disk, 'a' + i);
|
2003-06-16 14:42:47 +04:00
|
|
|
rval = swapctl(SWAP_ON, cp, 0);
|
|
|
|
free(cp);
|
|
|
|
if (rval != 0)
|
|
|
|
return -1;
|
2000-09-27 16:42:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2003-06-16 14:42:47 +04:00
|
|
|
|
|
|
|
int
|
2003-07-25 12:26:21 +04:00
|
|
|
check_swap(const char *disk, int remove_swap)
|
2003-06-16 14:42:47 +04:00
|
|
|
{
|
|
|
|
struct swapent *swap;
|
|
|
|
char *cp;
|
|
|
|
int nswap;
|
|
|
|
int l;
|
|
|
|
int rval = 0;
|
|
|
|
|
|
|
|
nswap = swapctl(SWAP_NSWAP, 0, 0);
|
|
|
|
if (nswap <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
swap = malloc(nswap * sizeof *swap);
|
|
|
|
if (swap == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
nswap = swapctl(SWAP_STATS, swap, nswap);
|
|
|
|
if (nswap < 0)
|
|
|
|
goto bad_swap;
|
|
|
|
|
2003-07-25 12:26:21 +04:00
|
|
|
l = strlen(disk);
|
2003-06-16 14:42:47 +04:00
|
|
|
while (--nswap >= 0) {
|
|
|
|
/* Should we check the se_dev or se_path? */
|
|
|
|
cp = swap[nswap].se_path;
|
|
|
|
if (memcmp(cp, "/dev/", 5) != 0)
|
|
|
|
continue;
|
2003-07-25 12:26:21 +04:00
|
|
|
if (memcmp(cp + 5, disk, l) != 0)
|
2003-06-16 14:42:47 +04:00
|
|
|
continue;
|
|
|
|
if (!isalpha(*(unsigned char *)(cp + 5 + l)))
|
|
|
|
continue;
|
|
|
|
if (cp[5 + l + 1] != 0)
|
|
|
|
continue;
|
|
|
|
/* ok path looks like it is for this device */
|
2003-07-25 12:26:21 +04:00
|
|
|
if (!remove_swap) {
|
2003-06-16 14:42:47 +04:00
|
|
|
/* count active swap areas */
|
|
|
|
rval++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (swapctl(SWAP_OFF, cp, 0) == -1)
|
|
|
|
rval = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
free(swap);
|
|
|
|
return rval;
|
|
|
|
|
|
|
|
bad_swap:
|
|
|
|
rval = -1;
|
|
|
|
goto done;
|
|
|
|
}
|