2014-07-26 23:30:39 +04:00
|
|
|
/* $NetBSD: bsddisklabel.c,v 1.1 2014/07/26 19:30:44 dholland Exp $ */
|
1999-08-16 12:29:04 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 1997 Piermont Information Systems Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Based on code 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.
|
2011-04-04 12:30:12 +04:00
|
|
|
* 3. The name of Piermont Information Systems Inc. may not be used to endorse
|
1999-08-16 12:29:04 +04:00
|
|
|
* 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
|
|
|
|
* 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
|
|
|
|
* 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)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* bsddisklabel.c -- generate standard BSD disklabel */
|
|
|
|
/* Included by appropriate arch/XXXX/md.c */
|
|
|
|
|
2003-05-21 14:05:20 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/exec.h>
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <util.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include "defs.h"
|
|
|
|
#include "md.h"
|
|
|
|
#include "endian.h"
|
|
|
|
#include "msg_defs.h"
|
|
|
|
#include "menu_defs.h"
|
|
|
|
|
2009-04-07 14:45:04 +04:00
|
|
|
static int check_partitions(void);
|
|
|
|
|
2003-07-26 21:06:22 +04:00
|
|
|
/* For the current state of this file blame abs@NetBSD.org */
|
2003-05-21 14:05:20 +04:00
|
|
|
/* Even though he wasn't the last to hack it, but he did admit doing so :-) */
|
|
|
|
|
2009-10-18 16:09:48 +04:00
|
|
|
#define PART_ANY -1
|
|
|
|
#define PART_EXTRA -2
|
|
|
|
#define PART_TMP_RAMDISK -3
|
2003-06-07 01:37:13 +04:00
|
|
|
|
2003-05-21 14:05:20 +04:00
|
|
|
/* Defaults for things that might be defined in md.h */
|
|
|
|
#ifndef PART_ROOT
|
2003-11-30 17:36:43 +03:00
|
|
|
#define PART_ROOT PART_A
|
2003-05-21 14:05:20 +04:00
|
|
|
#endif
|
|
|
|
#ifndef PART_SWAP
|
2003-11-30 17:36:43 +03:00
|
|
|
#define PART_SWAP PART_B
|
2003-05-21 14:05:20 +04:00
|
|
|
#endif
|
|
|
|
#ifndef PART_USR
|
2003-06-07 01:37:13 +04:00
|
|
|
#define PART_USR PART_ANY
|
2003-05-21 14:05:20 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DEFVARSIZE
|
|
|
|
#define DEFVARSIZE 32
|
|
|
|
#endif
|
|
|
|
#ifndef DEFROOTSIZE
|
|
|
|
#define DEFROOTSIZE 32
|
|
|
|
#endif
|
|
|
|
#ifndef DEFUSRSIZE
|
|
|
|
#define DEFUSRSIZE 128
|
|
|
|
#endif
|
2003-06-13 15:45:49 +04:00
|
|
|
#ifndef DEFSWAPSIZE
|
|
|
|
#define DEFSWAPSIZE 128
|
|
|
|
#endif
|
1999-08-16 12:29:04 +04:00
|
|
|
|
2008-01-24 02:15:37 +03:00
|
|
|
int
|
2009-05-14 20:23:38 +04:00
|
|
|
save_ptn(int ptn, daddr_t start, daddr_t size, int fstype, const char *mountpt)
|
2003-05-21 14:05:20 +04:00
|
|
|
{
|
2003-06-05 00:05:12 +04:00
|
|
|
static int maxptn;
|
2005-01-21 00:59:35 +03:00
|
|
|
partinfo *p;
|
|
|
|
int pp;
|
2003-05-21 14:05:20 +04:00
|
|
|
|
2003-06-05 00:05:12 +04:00
|
|
|
if (maxptn == 0)
|
2003-05-21 14:05:20 +04:00
|
|
|
maxptn = getmaxpartitions();
|
2003-06-05 00:05:12 +04:00
|
|
|
|
|
|
|
if (ptn < 0 || bsdlabel[ptn].pi_fstype != FS_UNUSED) {
|
2003-05-21 14:05:20 +04:00
|
|
|
ptn = getrawpartition() + 1;
|
|
|
|
#ifdef PART_FIRST_FREE
|
|
|
|
if (ptn < PART_FIRST_FREE)
|
|
|
|
ptn = PART_FIRST_FREE;
|
|
|
|
#endif
|
|
|
|
for (;; ptn++) {
|
|
|
|
if (ptn >= maxptn)
|
|
|
|
return -1;
|
|
|
|
if (ptn == PART_USR)
|
|
|
|
continue;
|
|
|
|
if (bsdlabel[ptn].pi_fstype == FS_UNUSED)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fstype == FS_UNUSED)
|
|
|
|
return ptn;
|
|
|
|
|
2005-01-21 00:59:35 +03:00
|
|
|
p = bsdlabel + ptn;
|
|
|
|
p->pi_offset = start;
|
|
|
|
p->pi_size = size;
|
2005-09-12 00:38:26 +04:00
|
|
|
set_ptype(p, fstype, mountpt ? PIF_NEWFS : 0);
|
2003-06-05 00:05:12 +04:00
|
|
|
|
|
|
|
if (mountpt != NULL) {
|
2005-01-21 00:59:35 +03:00
|
|
|
for (pp = 0; pp < maxptn; pp++) {
|
|
|
|
if (strcmp(bsdlabel[pp].pi_mount, mountpt) == 0)
|
|
|
|
bsdlabel[pp].pi_flags &= ~PIF_MOUNT;
|
2003-07-07 16:30:19 +04:00
|
|
|
}
|
2005-01-21 00:59:35 +03:00
|
|
|
strlcpy(p->pi_mount, mountpt, sizeof p->pi_mount);
|
|
|
|
p->pi_flags |= PIF_MOUNT;
|
2012-11-21 00:17:43 +04:00
|
|
|
/* Default to UFS2. */
|
2009-04-04 14:38:00 +04:00
|
|
|
if (p->pi_fstype == FS_BSDFFS) {
|
2009-04-05 04:50:51 +04:00
|
|
|
#ifdef DEFAULT_UFS2
|
|
|
|
#ifndef HAVE_UFS2_BOOT
|
|
|
|
if (strcmp(mountpt, "/") != 0)
|
|
|
|
#endif
|
|
|
|
p->pi_flags |= PIF_FFSv2;
|
2009-04-04 14:38:00 +04:00
|
|
|
#endif
|
|
|
|
}
|
2003-05-21 14:05:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ptn;
|
|
|
|
}
|
|
|
|
|
2008-01-24 02:15:37 +03:00
|
|
|
void
|
2003-10-20 00:17:31 +04:00
|
|
|
set_ptn_titles(menudesc *m, int opt, void *arg)
|
2003-06-05 00:05:12 +04:00
|
|
|
{
|
2003-10-20 00:17:31 +04:00
|
|
|
struct ptn_info *pi = arg;
|
2003-06-05 00:05:12 +04:00
|
|
|
struct ptn_size *p;
|
|
|
|
int sm = MEG / sectorsize;
|
2009-05-14 20:23:38 +04:00
|
|
|
daddr_t size;
|
2003-10-20 00:17:31 +04:00
|
|
|
char inc_free[12];
|
|
|
|
|
|
|
|
p = &pi->ptn_sizes[opt];
|
|
|
|
if (p->mount[0] == 0) {
|
2011-05-30 18:20:48 +04:00
|
|
|
wprintw(m->mw, "%s", msg_string(MSG_add_another_ptn));
|
2003-10-20 00:17:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
size = p->size;
|
|
|
|
if (p == pi->pool_part)
|
2011-04-04 12:30:12 +04:00
|
|
|
snprintf(inc_free, sizeof inc_free, "(%" PRIi64 ")",
|
2003-10-20 00:17:31 +04:00
|
|
|
(size + pi->free_space) / sm);
|
|
|
|
else
|
|
|
|
inc_free[0] = 0;
|
2009-05-14 20:23:38 +04:00
|
|
|
wprintw(m->mw, "%6" PRIi64 "%8s%10" PRIi64 "%10" PRIi64 " %c %s",
|
2003-10-20 00:17:31 +04:00
|
|
|
size / sm, inc_free, size / dlcylsize, size,
|
|
|
|
p == pi->pool_part ? '+' : ' ', p->mount);
|
|
|
|
}
|
|
|
|
|
2008-01-24 02:15:37 +03:00
|
|
|
void
|
2003-10-20 00:17:31 +04:00
|
|
|
set_ptn_menu(struct ptn_info *pi)
|
|
|
|
{
|
|
|
|
struct ptn_size *p;
|
|
|
|
menu_ent *m;
|
2003-06-05 00:05:12 +04:00
|
|
|
|
2003-10-20 00:17:31 +04:00
|
|
|
for (m = pi->ptn_menus, p = pi->ptn_sizes;; m++, p++) {
|
|
|
|
m->opt_name = NULL;
|
2003-06-05 00:05:12 +04:00
|
|
|
m->opt_menu = OPT_NOMENU;
|
|
|
|
m->opt_flags = 0;
|
|
|
|
m->opt_action = set_ptn_size;
|
|
|
|
if (p->mount[0] == 0)
|
|
|
|
break;
|
|
|
|
}
|
2003-10-20 00:17:31 +04:00
|
|
|
if (pi->free_parts != 0)
|
|
|
|
m++;
|
|
|
|
m->opt_name = MSG_askunits;
|
|
|
|
m->opt_menu = MENU_sizechoice;
|
|
|
|
m->opt_flags = OPT_SUB;
|
|
|
|
m->opt_action = NULL;
|
|
|
|
m++;
|
2003-06-05 00:05:12 +04:00
|
|
|
|
|
|
|
if (pi->free_space >= 0)
|
|
|
|
snprintf(pi->exit_msg, sizeof pi->exit_msg,
|
|
|
|
msg_string(MSG_fssizesok),
|
2009-05-14 20:23:38 +04:00
|
|
|
(int)(pi->free_space / sizemult), multname, pi->free_parts);
|
2003-06-05 00:05:12 +04:00
|
|
|
else
|
|
|
|
snprintf(pi->exit_msg, sizeof pi->exit_msg,
|
|
|
|
msg_string(MSG_fssizesbad),
|
2009-05-14 20:23:38 +04:00
|
|
|
(int)(-pi->free_space / sizemult), multname, (uint) -pi->free_space);
|
2003-06-05 00:05:12 +04:00
|
|
|
|
2003-10-20 00:17:31 +04:00
|
|
|
set_menu_numopts(pi->menu_no, m - pi->ptn_menus);
|
2003-06-05 00:05:12 +04:00
|
|
|
}
|
|
|
|
|
2008-01-24 02:15:37 +03:00
|
|
|
int
|
2003-07-27 11:45:08 +04:00
|
|
|
set_ptn_size(menudesc *m, void *arg)
|
2003-06-05 00:05:12 +04:00
|
|
|
{
|
|
|
|
struct ptn_info *pi = arg;
|
|
|
|
struct ptn_size *p;
|
2003-06-10 21:47:15 +04:00
|
|
|
char answer[10];
|
2003-06-12 02:17:03 +04:00
|
|
|
char dflt[10];
|
2003-06-05 00:05:12 +04:00
|
|
|
char *cp;
|
2009-05-14 20:23:38 +04:00
|
|
|
daddr_t size, old_size;
|
2003-06-05 00:05:12 +04:00
|
|
|
int mult;
|
|
|
|
|
2003-07-27 11:45:08 +04:00
|
|
|
p = pi->ptn_sizes + m->cursel;
|
2003-06-05 00:05:12 +04:00
|
|
|
|
2003-06-07 01:37:13 +04:00
|
|
|
if (pi->free_parts == 0 && p->size == 0)
|
|
|
|
/* Don't allow 'free_parts' to go negative */
|
|
|
|
return 0;
|
|
|
|
|
2003-06-05 00:05:12 +04:00
|
|
|
if (p->mount[0] == 0) {
|
2003-06-12 02:17:03 +04:00
|
|
|
msg_prompt_win(MSG_askfsmount, -1, 18, 0, 0,
|
2003-06-05 00:05:12 +04:00
|
|
|
NULL, p->mount, sizeof p->mount);
|
|
|
|
if (p->mount[0] == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-06-12 02:17:03 +04:00
|
|
|
size = p->size;
|
2003-10-20 00:17:31 +04:00
|
|
|
old_size = size;
|
2003-06-12 02:17:03 +04:00
|
|
|
if (size == 0)
|
|
|
|
size = p->dflt_size;
|
|
|
|
size /= sizemult;
|
2009-05-14 20:23:38 +04:00
|
|
|
snprintf(dflt, sizeof dflt, "%" PRIi64 "%s",
|
2003-09-27 14:16:33 +04:00
|
|
|
size, p == pi->pool_part ? "+" : "");
|
2003-06-05 00:05:12 +04:00
|
|
|
|
2003-06-12 02:17:03 +04:00
|
|
|
for (;;) {
|
|
|
|
mult = sizemult;
|
|
|
|
msg_prompt_win(MSG_askfssize, -1, 18, 0, 0,
|
|
|
|
dflt, answer, sizeof answer,
|
2003-06-05 00:05:12 +04:00
|
|
|
p->mount, multname);
|
2003-06-13 15:45:49 +04:00
|
|
|
/* Some special cases when /usr is first given a size */
|
2003-10-20 00:17:31 +04:00
|
|
|
if (old_size == 0 && !strcmp(p->mount, "/usr")) {
|
2003-06-13 15:45:49 +04:00
|
|
|
/* Remove space for /usr from / */
|
|
|
|
if (!pi->ptn_sizes[0].changed) {
|
|
|
|
pi->ptn_sizes[0].size -= p->dflt_size;
|
|
|
|
pi->free_space += p->dflt_size;
|
2005-01-21 20:02:40 +03:00
|
|
|
pi->ptn_sizes[0].changed = 1;
|
2003-06-13 15:45:49 +04:00
|
|
|
}
|
|
|
|
/* hack to add free space to default sized /usr */
|
|
|
|
if (!strcmp(answer, dflt)) {
|
|
|
|
size = p->dflt_size;
|
|
|
|
pi->pool_part = p;
|
|
|
|
goto adjust_free;
|
|
|
|
}
|
2003-06-12 02:17:03 +04:00
|
|
|
}
|
2003-06-05 00:05:12 +04:00
|
|
|
size = strtoul(answer, &cp, 0);
|
|
|
|
switch (*cp++) {
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
case 's':
|
|
|
|
mult = 1;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
mult = dlcylsize;
|
|
|
|
break;
|
|
|
|
case 'm':
|
2003-06-07 01:37:13 +04:00
|
|
|
case 'M':
|
2003-06-05 00:05:12 +04:00
|
|
|
mult = MEG / sectorsize;
|
|
|
|
break;
|
2003-06-07 01:37:13 +04:00
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
mult = 1024 * MEG / sectorsize;
|
|
|
|
break;
|
2003-06-05 00:05:12 +04:00
|
|
|
case '+':
|
|
|
|
cp--;
|
|
|
|
if (cp != answer)
|
|
|
|
break;
|
|
|
|
mult = 1;
|
2003-10-20 00:17:31 +04:00
|
|
|
size = old_size;
|
2003-06-05 00:05:12 +04:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
cp--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*cp == 0 || *cp == '+')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = NUMSEC(size, mult, dlcylsize);
|
2009-10-18 16:09:48 +04:00
|
|
|
if (p->ptn_id == PART_TMP_RAMDISK) {
|
2003-11-20 12:47:53 +03:00
|
|
|
p->size = size;
|
|
|
|
return 0;
|
|
|
|
}
|
2003-06-05 00:05:12 +04:00
|
|
|
if (p == pi->pool_part)
|
|
|
|
pi->pool_part = NULL;
|
2003-09-27 14:16:33 +04:00
|
|
|
if (*cp == '+' && p->limit == 0) {
|
2003-06-05 00:05:12 +04:00
|
|
|
pi->pool_part = p;
|
2003-09-27 14:16:33 +04:00
|
|
|
if (size == 0)
|
|
|
|
size = dlcylsize;
|
|
|
|
}
|
2003-06-14 16:58:45 +04:00
|
|
|
if (p->limit != 0 && size > p->limit)
|
|
|
|
size = p->limit;
|
2003-06-12 02:17:03 +04:00
|
|
|
adjust_free:
|
2003-10-20 00:17:31 +04:00
|
|
|
if (size != old_size)
|
2003-06-13 15:45:49 +04:00
|
|
|
p->changed = 1;
|
2003-10-20 00:17:31 +04:00
|
|
|
pi->free_space += old_size - size;
|
|
|
|
p->size = size;
|
2003-06-05 00:05:12 +04:00
|
|
|
if (size == 0) {
|
2003-10-20 00:17:31 +04:00
|
|
|
if (old_size != 0)
|
2003-06-05 00:05:12 +04:00
|
|
|
pi->free_parts++;
|
2003-06-07 01:37:13 +04:00
|
|
|
if (p->ptn_id == PART_EXTRA)
|
2003-06-05 00:05:12 +04:00
|
|
|
memmove(p, p + 1,
|
2003-10-20 00:17:31 +04:00
|
|
|
(char *)&pi->ptn_sizes[MAXPARTITIONS]
|
2003-06-05 00:05:12 +04:00
|
|
|
- (char *)p);
|
|
|
|
} else {
|
2003-06-13 15:45:49 +04:00
|
|
|
int f = pi->free_space;
|
2003-10-20 00:17:31 +04:00
|
|
|
if (old_size == 0)
|
2003-06-05 00:05:12 +04:00
|
|
|
pi->free_parts--;
|
2003-06-13 15:45:49 +04:00
|
|
|
if (f < mult && -f < mult) {
|
|
|
|
/*
|
|
|
|
* Round size to end of available space,
|
|
|
|
* but keep cylinder alignment
|
|
|
|
*/
|
|
|
|
if (f < 0)
|
2006-10-05 01:27:27 +04:00
|
|
|
f = -roundup(-f, dlcylsize);
|
2003-06-13 15:45:49 +04:00
|
|
|
else
|
2006-10-05 01:27:27 +04:00
|
|
|
f = rounddown(f, dlcylsize);
|
2003-06-13 15:45:49 +04:00
|
|
|
size += f;
|
2003-10-20 00:17:31 +04:00
|
|
|
if (size != 0) {
|
|
|
|
pi->free_space -= f;
|
|
|
|
p->size += f;
|
|
|
|
}
|
2003-06-05 00:05:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-20 00:17:31 +04:00
|
|
|
set_ptn_menu(pi);
|
2003-06-05 00:05:12 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-24 02:15:37 +03:00
|
|
|
void
|
2009-05-14 20:23:38 +04:00
|
|
|
get_ptn_sizes(daddr_t part_start, daddr_t sectors, int no_swap)
|
2003-06-05 00:05:12 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int maxpart = getmaxpartitions();
|
|
|
|
int sm; /* sectors in 1MB */
|
|
|
|
struct ptn_size *p;
|
2009-05-14 20:23:38 +04:00
|
|
|
daddr_t size;
|
2003-06-05 00:05:12 +04:00
|
|
|
|
2003-10-20 00:17:31 +04:00
|
|
|
static struct ptn_info pi = { -1, {
|
2003-06-13 15:45:49 +04:00
|
|
|
#define PI_ROOT 0
|
2004-06-06 10:06:59 +04:00
|
|
|
{ PART_ROOT, { '/', '\0' },
|
2006-10-24 02:41:51 +04:00
|
|
|
DEFROOTSIZE, DEFROOTSIZE , 0, 0},
|
2003-06-13 15:45:49 +04:00
|
|
|
#define PI_SWAP 1
|
2004-06-06 10:06:59 +04:00
|
|
|
{ PART_SWAP, { 's', 'w', 'a', 'p', '\0' },
|
2006-10-24 02:41:51 +04:00
|
|
|
DEFSWAPSIZE, DEFSWAPSIZE, 0, 0 },
|
2009-10-18 16:09:48 +04:00
|
|
|
{ PART_TMP_RAMDISK,
|
|
|
|
#ifdef HAVE_TMPFS
|
2010-02-18 15:21:52 +03:00
|
|
|
{ '/', 't', 'm', 'p', ' ', '(', 't', 'm', 'p', 'f', 's', ')', '\0' },
|
2009-10-18 16:09:48 +04:00
|
|
|
#else
|
2010-02-18 15:21:52 +03:00
|
|
|
{ '/', 't', 'm', 'p', ' ', '(', 'm', 'f', 's', ')', '\0' },
|
2009-10-18 16:09:48 +04:00
|
|
|
#endif
|
|
|
|
64, 0, 0, 0 },
|
2003-06-13 15:45:49 +04:00
|
|
|
#define PI_USR 3
|
2006-10-24 02:41:51 +04:00
|
|
|
{ PART_USR, { '/', 'u', 's', 'r', '\0' }, DEFUSRSIZE,
|
|
|
|
0, 0, 0 },
|
|
|
|
{ PART_ANY, { '/', 'v', 'a', 'r', '\0' }, DEFVARSIZE,
|
|
|
|
0, 0, 0 },
|
|
|
|
{ PART_ANY, { '/', 'h', 'o', 'm', 'e', '\0' }, 0,
|
|
|
|
0, 0, 0 },
|
2003-10-20 00:17:31 +04:00
|
|
|
}, {
|
|
|
|
{ NULL, OPT_NOMENU, 0, set_ptn_size },
|
|
|
|
{ MSG_askunits, MENU_sizechoice, OPT_SUB, NULL },
|
2006-10-24 02:41:51 +04:00
|
|
|
}, 0, 0, NULL, { 0 } };
|
2003-06-05 00:05:12 +04:00
|
|
|
|
|
|
|
if (maxpart > MAXPARTITIONS)
|
|
|
|
maxpart = MAXPARTITIONS; /* sanity */
|
|
|
|
|
2003-06-13 15:45:49 +04:00
|
|
|
msg_display(MSG_ptnsizes);
|
|
|
|
msg_table_add(MSG_ptnheaders);
|
|
|
|
|
2003-06-10 21:47:15 +04:00
|
|
|
if (pi.menu_no < 0) {
|
2009-04-04 15:04:28 +04:00
|
|
|
/* If there is a swap partition elsewhere, don't add one here.*/
|
|
|
|
if (no_swap) {
|
2003-10-20 00:17:31 +04:00
|
|
|
pi.ptn_sizes[PI_SWAP].size = 0;
|
2009-04-04 15:04:28 +04:00
|
|
|
} else {
|
|
|
|
#if DEFSWAPSIZE == -1
|
|
|
|
/* Dynamic swap size. */
|
2009-04-04 15:24:24 +04:00
|
|
|
pi.ptn_sizes[PI_SWAP].dflt_size = get_ramsize();
|
|
|
|
pi.ptn_sizes[PI_SWAP].size =
|
|
|
|
pi.ptn_sizes[PI_SWAP].dflt_size;
|
2009-04-04 15:04:28 +04:00
|
|
|
#endif
|
|
|
|
}
|
2011-04-04 12:30:12 +04:00
|
|
|
|
2003-06-13 15:45:49 +04:00
|
|
|
/* If installing X increase default size of /usr */
|
2006-01-13 01:02:44 +03:00
|
|
|
if (set_X11_selected())
|
2003-06-13 15:45:49 +04:00
|
|
|
pi.ptn_sizes[PI_USR].dflt_size += XNEEDMB;
|
2003-06-05 00:05:12 +04:00
|
|
|
|
2005-02-20 23:42:36 +03:00
|
|
|
/* Start of planning to give free space to / */
|
|
|
|
pi.pool_part = &pi.ptn_sizes[PI_ROOT];
|
|
|
|
/* Make size of root include default size of /usr */
|
|
|
|
pi.ptn_sizes[PI_ROOT].size += pi.ptn_sizes[PI_USR].dflt_size;
|
|
|
|
|
2005-11-05 12:55:34 +03:00
|
|
|
sm = MEG / sectorsize;
|
|
|
|
|
2005-02-20 23:42:36 +03:00
|
|
|
if (root_limit != 0) {
|
|
|
|
/* Bah - bios can not read all the disk, limit root */
|
2003-09-27 14:16:33 +04:00
|
|
|
pi.ptn_sizes[PI_ROOT].limit = root_limit - part_start;
|
2005-02-20 23:42:36 +03:00
|
|
|
/* Allocate a /usr partition if bios can't read
|
|
|
|
* everything except swap.
|
|
|
|
*/
|
|
|
|
if (pi.ptn_sizes[PI_ROOT].limit
|
2005-11-05 12:55:34 +03:00
|
|
|
< sectors - pi.ptn_sizes[PI_SWAP].size * sm) {
|
2005-02-20 23:42:36 +03:00
|
|
|
/* Root won't be able to access all the space */
|
|
|
|
/* Claw back space for /usr */
|
|
|
|
pi.ptn_sizes[PI_USR].size =
|
2003-06-14 16:58:45 +04:00
|
|
|
pi.ptn_sizes[PI_USR].dflt_size;
|
2005-02-20 23:42:36 +03:00
|
|
|
pi.ptn_sizes[PI_ROOT].size -=
|
2003-06-14 16:58:45 +04:00
|
|
|
pi.ptn_sizes[PI_USR].dflt_size;
|
2005-02-20 23:42:36 +03:00
|
|
|
pi.ptn_sizes[PI_ROOT].changed = 1;
|
|
|
|
/* Give free space to /usr */
|
|
|
|
pi.pool_part = &pi.ptn_sizes[PI_USR];
|
|
|
|
}
|
2003-06-14 16:58:45 +04:00
|
|
|
}
|
2003-06-13 15:45:49 +04:00
|
|
|
|
|
|
|
/* Change preset sizes from MB to sectors */
|
2003-06-07 01:37:13 +04:00
|
|
|
pi.free_space = sectors;
|
|
|
|
for (p = pi.ptn_sizes; p->mount[0]; p++) {
|
|
|
|
p->size = NUMSEC(p->size, sm, dlcylsize);
|
|
|
|
p->dflt_size = NUMSEC(p->dflt_size, sm, dlcylsize);
|
|
|
|
pi.free_space -= p->size;
|
|
|
|
}
|
2003-06-05 00:05:12 +04:00
|
|
|
|
2003-06-13 15:45:49 +04:00
|
|
|
/* Steal space from swap to make things fit.. */
|
|
|
|
if (pi.free_space < 0) {
|
2006-10-05 01:27:27 +04:00
|
|
|
i = roundup(-pi.free_space, dlcylsize);
|
2003-06-13 15:45:49 +04:00
|
|
|
if (i > pi.ptn_sizes[PI_SWAP].size)
|
|
|
|
i = pi.ptn_sizes[PI_SWAP].size;
|
|
|
|
pi.ptn_sizes[PI_SWAP].size -= i;
|
|
|
|
pi.free_space += i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add space for 2 system dumps to / (traditional) */
|
2004-07-17 14:55:03 +04:00
|
|
|
i = get_ramsize() * sm;
|
2006-10-05 01:27:27 +04:00
|
|
|
i = roundup(i, dlcylsize);
|
2003-06-13 15:45:49 +04:00
|
|
|
if (pi.free_space > i * 2)
|
|
|
|
i *= 2;
|
|
|
|
if (pi.free_space > i) {
|
|
|
|
pi.ptn_sizes[PI_ROOT].size += i;
|
|
|
|
pi.free_space -= i;
|
|
|
|
}
|
|
|
|
|
2003-06-14 16:58:45 +04:00
|
|
|
/* Ensure all of / is readable by the system boot code */
|
|
|
|
i = pi.ptn_sizes[PI_ROOT].limit;
|
|
|
|
if (i != 0 && (i -= pi.ptn_sizes[PI_ROOT].size) < 0) {
|
|
|
|
pi.ptn_sizes[PI_ROOT].size += i;
|
|
|
|
pi.free_space -= i;
|
|
|
|
}
|
|
|
|
|
2003-06-07 01:37:13 +04:00
|
|
|
/* Count free partition slots */
|
2003-10-20 00:17:31 +04:00
|
|
|
pi.free_parts = 0;
|
2003-06-07 01:37:13 +04:00
|
|
|
for (i = 0; i < maxpart; i++) {
|
|
|
|
if (bsdlabel[i].pi_size == 0)
|
|
|
|
pi.free_parts++;
|
|
|
|
}
|
2003-10-20 00:17:31 +04:00
|
|
|
for (i = 0; i < MAXPARTITIONS; i++) {
|
2003-06-07 01:37:13 +04:00
|
|
|
p = &pi.ptn_sizes[i];
|
|
|
|
if (i != 0 && p->ptn_id == 0)
|
|
|
|
p->ptn_id = PART_EXTRA;
|
2003-10-20 00:17:31 +04:00
|
|
|
if (p->size != 0)
|
|
|
|
pi.free_parts--;
|
2003-06-07 01:37:13 +04:00
|
|
|
}
|
2003-06-05 00:05:12 +04:00
|
|
|
|
2003-10-20 00:17:31 +04:00
|
|
|
pi.menu_no = new_menu(0, pi.ptn_menus, nelem(pi.ptn_menus),
|
|
|
|
3, -1, 12, 70,
|
|
|
|
MC_NOSHORTCUT |
|
|
|
|
MC_ALWAYS_SCROLL | MC_NOBOX | MC_NOCLEAR,
|
|
|
|
NULL, set_ptn_titles, NULL,
|
2003-06-07 01:37:13 +04:00
|
|
|
"help", pi.exit_msg);
|
2003-06-05 00:05:12 +04:00
|
|
|
|
2003-06-10 21:47:15 +04:00
|
|
|
if (pi.menu_no < 0)
|
|
|
|
return;
|
|
|
|
}
|
2003-06-05 00:05:12 +04:00
|
|
|
|
|
|
|
do {
|
2003-10-20 00:17:31 +04:00
|
|
|
set_ptn_menu(&pi);
|
2004-07-13 02:33:21 +04:00
|
|
|
current_cylsize = dlcylsize;
|
2003-06-05 00:05:12 +04:00
|
|
|
process_menu(pi.menu_no, &pi);
|
|
|
|
} while (pi.free_space < 0 || pi.free_parts < 0);
|
|
|
|
|
2003-06-13 15:45:49 +04:00
|
|
|
/* Give any cylinder fragment to last partition */
|
|
|
|
if (pi.pool_part != NULL || pi.free_space < dlcylsize) {
|
|
|
|
for (p = pi.ptn_sizes + nelem(pi.ptn_sizes) - 1; ;p--) {
|
|
|
|
if (p->size == 0) {
|
|
|
|
if (p == pi.ptn_sizes)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
2009-10-18 16:09:48 +04:00
|
|
|
if (p->ptn_id == PART_TMP_RAMDISK)
|
2003-06-13 15:45:49 +04:00
|
|
|
continue;
|
|
|
|
p->size += pi.free_space % dlcylsize;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-05 00:05:12 +04:00
|
|
|
for (p = pi.ptn_sizes; p->mount[0]; p++, part_start += size) {
|
|
|
|
size = p->size;
|
2005-02-20 23:42:36 +03:00
|
|
|
if (p == pi.pool_part) {
|
2006-10-05 01:27:27 +04:00
|
|
|
size += rounddown(pi.free_space, dlcylsize);
|
2005-02-20 23:42:36 +03:00
|
|
|
if (p->limit != 0 && size > p->limit)
|
|
|
|
size = p->limit;
|
|
|
|
}
|
2003-06-07 01:37:13 +04:00
|
|
|
i = p->ptn_id;
|
2009-10-18 16:09:48 +04:00
|
|
|
if (i == PART_TMP_RAMDISK) {
|
|
|
|
tmp_ramdisk_size = size;
|
2003-06-07 01:37:13 +04:00
|
|
|
size = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2003-06-05 00:05:12 +04:00
|
|
|
if (size == 0)
|
|
|
|
continue;
|
2003-06-07 01:37:13 +04:00
|
|
|
if (i == PART_SWAP) {
|
|
|
|
save_ptn(i, part_start, size, FS_SWAP, NULL);
|
2003-06-05 00:05:12 +04:00
|
|
|
continue;
|
|
|
|
}
|
2003-06-07 01:37:13 +04:00
|
|
|
save_ptn(i, part_start, size, FS_BSDFFS, p->mount);
|
2003-06-05 00:05:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-16 12:29:04 +04:00
|
|
|
/*
|
|
|
|
* md back-end code for menu-driven BSD disklabel editor.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
make_bsd_partitions(void)
|
|
|
|
{
|
2003-05-21 14:05:20 +04:00
|
|
|
int i;
|
|
|
|
int part;
|
1999-08-16 12:29:04 +04:00
|
|
|
int maxpart = getmaxpartitions();
|
2009-05-14 20:23:38 +04:00
|
|
|
daddr_t partstart;
|
2003-05-21 14:05:20 +04:00
|
|
|
int part_raw, part_bsd;
|
2009-05-14 20:23:38 +04:00
|
|
|
daddr_t ptend;
|
2008-05-24 15:06:53 +04:00
|
|
|
int no_swap = 0, valid_part = -1;
|
2003-07-07 16:30:19 +04:00
|
|
|
partinfo *p;
|
1999-08-16 12:29:04 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize global variables that track space used on this disk.
|
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
|
|
|
* Standard 4.4BSD 8-partition labels always cover whole disk.
|
1999-08-16 12:29:04 +04:00
|
|
|
*/
|
2013-03-20 02:16:52 +04:00
|
|
|
if (logfp) fprintf(logfp, "dlsize=%" PRId64 " ptsize=%" PRId64 " ptstart=%" PRId64 "\n", dlsize,ptsize,ptstart);
|
2003-05-21 14:05:20 +04:00
|
|
|
if (ptsize == 0)
|
|
|
|
ptsize = dlsize - ptstart;
|
2003-05-31 02:17:00 +04:00
|
|
|
if (dlsize == 0)
|
|
|
|
dlsize = ptstart + ptsize;
|
2003-05-29 21:53:24 +04:00
|
|
|
|
|
|
|
partstart = ptstart;
|
2003-05-21 14:05:20 +04:00
|
|
|
ptend = ptstart + ptsize;
|
1999-08-16 12:29:04 +04:00
|
|
|
|
2003-06-07 01:37:13 +04:00
|
|
|
/* Ask for layout type -- standard or special */
|
|
|
|
msg_display(MSG_layout,
|
2009-05-14 20:23:38 +04:00
|
|
|
(int) (ptsize / (MEG / sectorsize)),
|
2003-06-13 15:45:49 +04:00
|
|
|
DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE,
|
|
|
|
DEFROOTSIZE + DEFSWAPSIZE + DEFUSRSIZE + XNEEDMB);
|
2003-06-07 01:37:13 +04:00
|
|
|
|
|
|
|
process_menu(MENU_layout, NULL);
|
|
|
|
|
2004-08-14 20:06:36 +04:00
|
|
|
/* Set so we use the 'real' geometry for rounding, input in MB */
|
|
|
|
current_cylsize = dlcylsize;
|
|
|
|
set_sizemultname_meg();
|
2003-06-07 01:37:13 +04:00
|
|
|
|
1999-08-16 12:29:04 +04:00
|
|
|
/* Build standard partitions */
|
2004-03-26 22:55:13 +03:00
|
|
|
memset(&bsdlabel, 0, sizeof bsdlabel);
|
1999-08-16 12:29:04 +04:00
|
|
|
|
|
|
|
/* Set initial partition types to unused */
|
|
|
|
for (part = 0 ; part < maxpart ; ++part)
|
|
|
|
bsdlabel[part].pi_fstype = FS_UNUSED;
|
|
|
|
|
|
|
|
/* Whole disk partition */
|
2003-05-21 14:05:20 +04:00
|
|
|
part_raw = getrawpartition();
|
|
|
|
if (part_raw == -1)
|
2003-11-30 17:36:43 +03:00
|
|
|
part_raw = PART_C; /* for sanity... */
|
2003-05-21 14:05:20 +04:00
|
|
|
bsdlabel[part_raw].pi_offset = 0;
|
|
|
|
bsdlabel[part_raw].pi_size = dlsize;
|
|
|
|
|
2003-11-30 17:36:43 +03:00
|
|
|
if (part_raw == PART_D) {
|
2003-06-05 00:05:12 +04:00
|
|
|
/* Probably a system that expects an i386 style mbr */
|
2003-11-30 17:36:43 +03:00
|
|
|
part_bsd = PART_C;
|
|
|
|
bsdlabel[PART_C].pi_offset = ptstart;
|
|
|
|
bsdlabel[PART_C].pi_size = ptsize;
|
2003-05-29 21:53:24 +04:00
|
|
|
} else {
|
2003-05-21 14:05:20 +04:00
|
|
|
part_bsd = part_raw;
|
2003-05-30 15:56:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(PART_BOOT) && defined(BOOT_SIZE)
|
2003-06-05 00:05:12 +04:00
|
|
|
i = BOOT_SIZE;
|
|
|
|
if (i >= 1024) {
|
2003-05-30 15:56:23 +04:00
|
|
|
/* Treat big numbers as a byte count */
|
2003-06-05 00:05:12 +04:00
|
|
|
i = (i + dlcylsize * sectorsize - 1) / (dlcylsize * sectorsize);
|
|
|
|
i *= dlcylsize;
|
2003-05-30 15:56:23 +04:00
|
|
|
}
|
2014-02-19 16:14:40 +04:00
|
|
|
#if defined(PART_BOOT_FFS)
|
|
|
|
bsdlabel[PART_BOOT].pi_fstype = FS_BSDFFS;
|
|
|
|
bsdlabel[PART_BOOT].pi_flags = PIF_NEWFS;
|
|
|
|
#else
|
2003-05-30 15:56:23 +04:00
|
|
|
bsdlabel[PART_BOOT].pi_fstype = FS_BOOT;
|
2014-02-19 16:14:40 +04:00
|
|
|
#endif
|
2003-06-05 00:05:12 +04:00
|
|
|
bsdlabel[PART_BOOT].pi_size = i;
|
2003-05-29 21:53:24 +04:00
|
|
|
#ifdef BOOT_HIGH
|
2003-06-05 00:05:12 +04:00
|
|
|
bsdlabel[PART_BOOT].pi_offset = ptend - i;
|
|
|
|
ptend -= i;
|
2003-05-29 21:53:24 +04:00
|
|
|
#else
|
2003-05-30 15:56:23 +04:00
|
|
|
bsdlabel[PART_BOOT].pi_offset = ptstart;
|
2003-06-05 00:05:12 +04:00
|
|
|
partstart += i;
|
2003-05-29 21:53:24 +04:00
|
|
|
#endif
|
Rather big update to sysinst, in order to get it working on the prep port.
1) Add an md_post_extract() function. This function is called after
extracting the sets, and allows the arch to do something at that time.
In the case of prep, it is much easier to install the bootcode after all
the sets are extracted, so we do it in md_post_extract(). Added empty
md_post_extract() functions to all other arches so they compile.
2) Add md_mbr_use_wholedisk() and md_check_mbr(). In edit_mbr() I have
split off the code that uses the whole disk for NetBSD, into the
mbr_use_wholedisk() function. On most ports that use mbr.c, I made
md_mbr_use_wholedisk() just call that and return. On prep we create the
magical prep boot partition here. The md_check_mbr() function allows the
arch to add additional checks after the user had manually edited the MBR
to make sure the choices he made allow NetBSD to function. Added a dummy
routine to all mbr.c using arches.
3) Added code to bsdlabel.c to create a partition of type boot if
PART_BOOT is defined, but BOOT_SIZE is not defined. Also added two more
globals "bootsize" and "bootstart" which must be seeded in order to do
so. This is done on prep in md_check_mbr().
4) Added MBR_PTYPE_PREP to the list of MBR partitions.
5) Made the prep port actually install sanely. It now creates a prep
boot partition, labels it correctly, installs all the sets, and then runs
mkbootimage and dd's the bootimage into the prep partition. The result
is a prep installer that creates a bootable NetBSD installation
automatically.
6) Edited the prep menus and messages files to add new labels. In the
case of the translated files, I just added the words in english for
someone to translate later.
I tried to xcompile a few arches to make sure I didn't break anything,
but I could have missed something. Please let me know if I have broken
your arch in any way. I'll watch the autobuilds for the next few days
too. For all ports other than prep there should be no functional changes
at all.
2006-04-05 20:55:01 +04:00
|
|
|
#elif defined(PART_BOOT)
|
|
|
|
if (bootsize != 0) {
|
2013-03-20 02:16:52 +04:00
|
|
|
#if defined(PART_BOOT_MSDOS)
|
|
|
|
bsdlabel[PART_BOOT].pi_fstype = FS_MSDOS;
|
|
|
|
#else
|
Rather big update to sysinst, in order to get it working on the prep port.
1) Add an md_post_extract() function. This function is called after
extracting the sets, and allows the arch to do something at that time.
In the case of prep, it is much easier to install the bootcode after all
the sets are extracted, so we do it in md_post_extract(). Added empty
md_post_extract() functions to all other arches so they compile.
2) Add md_mbr_use_wholedisk() and md_check_mbr(). In edit_mbr() I have
split off the code that uses the whole disk for NetBSD, into the
mbr_use_wholedisk() function. On most ports that use mbr.c, I made
md_mbr_use_wholedisk() just call that and return. On prep we create the
magical prep boot partition here. The md_check_mbr() function allows the
arch to add additional checks after the user had manually edited the MBR
to make sure the choices he made allow NetBSD to function. Added a dummy
routine to all mbr.c using arches.
3) Added code to bsdlabel.c to create a partition of type boot if
PART_BOOT is defined, but BOOT_SIZE is not defined. Also added two more
globals "bootsize" and "bootstart" which must be seeded in order to do
so. This is done on prep in md_check_mbr().
4) Added MBR_PTYPE_PREP to the list of MBR partitions.
5) Made the prep port actually install sanely. It now creates a prep
boot partition, labels it correctly, installs all the sets, and then runs
mkbootimage and dd's the bootimage into the prep partition. The result
is a prep installer that creates a bootable NetBSD installation
automatically.
6) Edited the prep menus and messages files to add new labels. In the
case of the translated files, I just added the words in english for
someone to translate later.
I tried to xcompile a few arches to make sure I didn't break anything,
but I could have missed something. Please let me know if I have broken
your arch in any way. I'll watch the autobuilds for the next few days
too. For all ports other than prep there should be no functional changes
at all.
2006-04-05 20:55:01 +04:00
|
|
|
bsdlabel[PART_BOOT].pi_fstype = FS_BOOT;
|
2013-03-20 02:16:52 +04:00
|
|
|
#endif
|
Rather big update to sysinst, in order to get it working on the prep port.
1) Add an md_post_extract() function. This function is called after
extracting the sets, and allows the arch to do something at that time.
In the case of prep, it is much easier to install the bootcode after all
the sets are extracted, so we do it in md_post_extract(). Added empty
md_post_extract() functions to all other arches so they compile.
2) Add md_mbr_use_wholedisk() and md_check_mbr(). In edit_mbr() I have
split off the code that uses the whole disk for NetBSD, into the
mbr_use_wholedisk() function. On most ports that use mbr.c, I made
md_mbr_use_wholedisk() just call that and return. On prep we create the
magical prep boot partition here. The md_check_mbr() function allows the
arch to add additional checks after the user had manually edited the MBR
to make sure the choices he made allow NetBSD to function. Added a dummy
routine to all mbr.c using arches.
3) Added code to bsdlabel.c to create a partition of type boot if
PART_BOOT is defined, but BOOT_SIZE is not defined. Also added two more
globals "bootsize" and "bootstart" which must be seeded in order to do
so. This is done on prep in md_check_mbr().
4) Added MBR_PTYPE_PREP to the list of MBR partitions.
5) Made the prep port actually install sanely. It now creates a prep
boot partition, labels it correctly, installs all the sets, and then runs
mkbootimage and dd's the bootimage into the prep partition. The result
is a prep installer that creates a bootable NetBSD installation
automatically.
6) Edited the prep menus and messages files to add new labels. In the
case of the translated files, I just added the words in english for
someone to translate later.
I tried to xcompile a few arches to make sure I didn't break anything,
but I could have missed something. Please let me know if I have broken
your arch in any way. I'll watch the autobuilds for the next few days
too. For all ports other than prep there should be no functional changes
at all.
2006-04-05 20:55:01 +04:00
|
|
|
bsdlabel[PART_BOOT].pi_size = bootsize;
|
|
|
|
bsdlabel[PART_BOOT].pi_offset = bootstart;
|
2008-01-02 14:23:22 +03:00
|
|
|
#if defined(PART_BOOT_PI_FLAGS)
|
|
|
|
bsdlabel[PART_BOOT].pi_flags |= PART_BOOT_PI_FLAGS;
|
|
|
|
#endif
|
|
|
|
#if defined(PART_BOOT_PI_MOUNT)
|
|
|
|
strlcpy(bsdlabel[PART_BOOT].pi_mount, PART_BOOT_PI_MOUNT,
|
|
|
|
sizeof bsdlabel[PART_BOOT].pi_mount);
|
|
|
|
#endif
|
Rather big update to sysinst, in order to get it working on the prep port.
1) Add an md_post_extract() function. This function is called after
extracting the sets, and allows the arch to do something at that time.
In the case of prep, it is much easier to install the bootcode after all
the sets are extracted, so we do it in md_post_extract(). Added empty
md_post_extract() functions to all other arches so they compile.
2) Add md_mbr_use_wholedisk() and md_check_mbr(). In edit_mbr() I have
split off the code that uses the whole disk for NetBSD, into the
mbr_use_wholedisk() function. On most ports that use mbr.c, I made
md_mbr_use_wholedisk() just call that and return. On prep we create the
magical prep boot partition here. The md_check_mbr() function allows the
arch to add additional checks after the user had manually edited the MBR
to make sure the choices he made allow NetBSD to function. Added a dummy
routine to all mbr.c using arches.
3) Added code to bsdlabel.c to create a partition of type boot if
PART_BOOT is defined, but BOOT_SIZE is not defined. Also added two more
globals "bootsize" and "bootstart" which must be seeded in order to do
so. This is done on prep in md_check_mbr().
4) Added MBR_PTYPE_PREP to the list of MBR partitions.
5) Made the prep port actually install sanely. It now creates a prep
boot partition, labels it correctly, installs all the sets, and then runs
mkbootimage and dd's the bootimage into the prep partition. The result
is a prep installer that creates a bootable NetBSD installation
automatically.
6) Edited the prep menus and messages files to add new labels. In the
case of the translated files, I just added the words in english for
someone to translate later.
I tried to xcompile a few arches to make sure I didn't break anything,
but I could have missed something. Please let me know if I have broken
your arch in any way. I'll watch the autobuilds for the next few days
too. For all ports other than prep there should be no functional changes
at all.
2006-04-05 20:55:01 +04:00
|
|
|
}
|
|
|
|
#endif /* PART_BOOT w/o BOOT_SIZE */
|
2003-05-30 15:56:23 +04:00
|
|
|
|
2006-01-09 18:25:20 +03:00
|
|
|
#if defined(PART_SYSVBFS) && defined(SYSVBFS_SIZE)
|
2006-01-09 13:00:34 +03:00
|
|
|
bsdlabel[PART_SYSVBFS].pi_offset = partstart;
|
|
|
|
bsdlabel[PART_SYSVBFS].pi_fstype = FS_SYSVBFS;
|
2006-01-09 18:25:20 +03:00
|
|
|
bsdlabel[PART_SYSVBFS].pi_size = SYSVBFS_SIZE;
|
2006-01-09 13:00:34 +03:00
|
|
|
bsdlabel[PART_SYSVBFS].pi_flags |= PIF_NEWFS | PIF_MOUNT;
|
2006-01-09 18:25:20 +03:00
|
|
|
strlcpy(bsdlabel[PART_SYSVBFS].pi_mount, "/stand",
|
|
|
|
sizeof bsdlabel[PART_SYSVBFS].pi_mount);
|
2006-01-09 13:00:34 +03:00
|
|
|
partstart += SYSVBFS_SIZE;
|
|
|
|
#endif
|
|
|
|
|
2003-05-29 21:53:24 +04:00
|
|
|
#ifdef PART_REST
|
2003-05-30 15:56:23 +04:00
|
|
|
bsdlabel[PART_REST].pi_offset = 0;
|
|
|
|
bsdlabel[PART_REST].pi_size = ptstart;
|
2003-05-29 21:53:24 +04:00
|
|
|
#endif
|
1999-08-16 12:29:04 +04:00
|
|
|
|
2008-05-24 15:06:53 +04:00
|
|
|
if (layoutkind == 4) {
|
|
|
|
/*
|
|
|
|
* If 'oldlabel' is a default label created by the kernel it
|
|
|
|
* will have exactly one valid partition besides raw_part
|
|
|
|
* which covers the whole disk - but might lie outside the
|
|
|
|
* mbr partition we (by now) have offset by a few sectors.
|
|
|
|
* Check for this and and fix ut up.
|
|
|
|
*/
|
|
|
|
valid_part = -1;
|
|
|
|
for (i = 0; i < maxpart; i++) {
|
|
|
|
if (i == part_raw)
|
|
|
|
continue;
|
|
|
|
if (oldlabel[i].pi_size > 0 && PI_ISBSDFS(&oldlabel[i])) {
|
|
|
|
if (valid_part >= 0) {
|
|
|
|
/* nope, not the default case */
|
|
|
|
valid_part = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
valid_part = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (valid_part >= 0 && oldlabel[valid_part].pi_offset < ptstart) {
|
|
|
|
oldlabel[valid_part].pi_offset = ptstart;
|
|
|
|
oldlabel[valid_part].pi_size -= ptstart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-07 16:30:19 +04:00
|
|
|
/*
|
|
|
|
* Save any partitions that are outside the area we are
|
|
|
|
* going to use.
|
|
|
|
* In particular this saves details of the other MBR
|
2003-10-20 00:17:31 +04:00
|
|
|
* partitions on a multiboot i386 system.
|
2003-07-07 16:30:19 +04:00
|
|
|
*/
|
|
|
|
for (i = maxpart; i--;) {
|
|
|
|
if (bsdlabel[i].pi_size != 0)
|
|
|
|
/* Don't overwrite special partitions */
|
|
|
|
continue;
|
|
|
|
p = &oldlabel[i];
|
|
|
|
if (p->pi_fstype == FS_UNUSED || p->pi_size == 0)
|
|
|
|
continue;
|
2003-06-05 00:05:12 +04:00
|
|
|
if (layoutkind == 4) {
|
2008-05-24 15:06:53 +04:00
|
|
|
if (PI_ISBSDFS(p)) {
|
2003-07-07 16:30:19 +04:00
|
|
|
p->pi_flags |= PIF_MOUNT;
|
2008-05-24 15:06:53 +04:00
|
|
|
if (layoutkind == 4 && i == valid_part) {
|
|
|
|
int fstype = p->pi_fstype;
|
|
|
|
p->pi_fstype = 0;
|
|
|
|
strcpy(p->pi_mount, "/");
|
|
|
|
set_ptype(p, fstype, PIF_NEWFS);
|
|
|
|
}
|
|
|
|
}
|
2003-07-07 16:30:19 +04:00
|
|
|
} else {
|
2011-04-04 12:30:12 +04:00
|
|
|
if (p->pi_offset < ptstart + ptsize &&
|
2003-10-20 00:17:31 +04:00
|
|
|
p->pi_offset + p->pi_size > ptstart)
|
|
|
|
/* Not outside area we are allocating */
|
|
|
|
continue;
|
|
|
|
if (p->pi_fstype == FS_SWAP)
|
|
|
|
no_swap = 1;
|
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
|
|
|
}
|
2003-07-07 16:30:19 +04:00
|
|
|
bsdlabel[i] = oldlabel[i];
|
|
|
|
}
|
1999-08-16 12:29:04 +04:00
|
|
|
|
2008-05-24 15:06:53 +04:00
|
|
|
if (layoutkind != 4)
|
2003-10-20 00:17:31 +04:00
|
|
|
get_ptn_sizes(partstart, ptend - partstart, no_swap);
|
2003-06-05 00:05:12 +04:00
|
|
|
|
1999-08-16 12:29:04 +04:00
|
|
|
/*
|
|
|
|
* OK, we have a partition table. Give the user the chance to
|
|
|
|
* edit it and verify it's OK, or abort altogether.
|
|
|
|
*/
|
|
|
|
edit_check:
|
2003-05-21 14:05:20 +04:00
|
|
|
if (edit_and_check_label(bsdlabel, maxpart, part_raw, part_bsd) == 0) {
|
1999-08-16 12:29:04 +04:00
|
|
|
msg_display(MSG_abort);
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-07 14:45:04 +04:00
|
|
|
if (check_partitions() == 0)
|
1999-08-16 12:29:04 +04:00
|
|
|
goto edit_check;
|
|
|
|
|
|
|
|
/* Disk name */
|
2003-10-20 00:17:31 +04:00
|
|
|
msg_prompt(MSG_packname, bsddiskname, bsddiskname, sizeof bsddiskname);
|
1999-08-16 12:29:04 +04:00
|
|
|
|
|
|
|
/* save label to disk for MI code to update. */
|
|
|
|
(void) savenewlabel(bsdlabel, maxpart);
|
|
|
|
|
|
|
|
/* Everything looks OK. */
|
|
|
|
return (1);
|
|
|
|
}
|
2009-04-07 14:45:04 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check that there is at least a / somewhere.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
check_partitions(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_BOOTXX_xFS
|
|
|
|
int rv;
|
|
|
|
char *bootxx;
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UFS2_BOOT
|
|
|
|
int fstype;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_BOOTXX_xFS
|
|
|
|
/* check if we have boot code for the root partition type */
|
|
|
|
bootxx = bootxx_name();
|
|
|
|
if (bootxx != NULL) {
|
|
|
|
rv = access(bootxx, R_OK);
|
|
|
|
free(bootxx);
|
2013-11-05 00:07:49 +04:00
|
|
|
} else
|
|
|
|
rv = -1;
|
|
|
|
if (rv != 0) {
|
2009-04-07 14:45:04 +04:00
|
|
|
process_menu(MENU_ok, deconst(MSG_No_Bootcode));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_UFS2_BOOT
|
|
|
|
fstype = bsdlabel[rootpart].pi_fstype;
|
|
|
|
if (fstype == FS_BSDFFS &&
|
|
|
|
(bsdlabel[rootpart].pi_flags & PIF_FFSv2) != 0) {
|
|
|
|
process_menu(MENU_ok, deconst(MSG_cannot_ufs2_root));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return md_check_partitions();
|
|
|
|
}
|