1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
/* $NetBSD: install.c,v 1.25 2023/01/06 18:13:40 martin Exp $ */
/*
* 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. 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
* 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.
*
*/
/* install.c -- system installation. */
#include <sys/param.h>
#include <stdio.h>
#include <curses.h>
#include "defs.h"
#include "msg_defs.h"
#include "menu_defs.h"
/*
* helper function: call the md pre/post disklabel callback for all involved
* inner partitions and write them back.
* return net result
*/
static bool
write_all_parts(struct install_partition_desc *install)
{
struct disk_partitions **allparts, *parts;
#ifndef NO_CLONES
struct selected_partition *src;
#endif
size_t num_parts, i, j;
bool found, res;
/* pessimistic assumption: all partitions on different devices */
allparts = calloc(install->num + install->num_write_back,
sizeof(*allparts));
if (allparts == NULL)
return false;
/* collect all different partition sets */
num_parts = 0;
for (i = 0; i < install->num_write_back; i++) {
parts = install->write_back[i];
if (parts == NULL)
continue;
found = false;
for (j = 0; j < num_parts; j++) {
if (allparts[j] == parts) {
found = true;
break;
}
}
if (found)
continue;
allparts[num_parts++] = parts;
}
for (i = 0; i < install->num; i++) {
parts = install->infos[i].parts;
if (parts == NULL)
continue;
found = false;
for (j = 0; j < num_parts; j++) {
if (allparts[j] == parts) {
found = true;
break;
}
}
if (found)
continue;
allparts[num_parts++] = parts;
}
/* do multiple phases, abort anytime and go out, returning res */
res = true;
/* phase 1: pre disklabel - used to write MBR and similar */
for (i = 0; i < num_parts; i++) {
if (!md_pre_disklabel(install, allparts[i])) {
res = false;
goto out;
}
}
/* phase 2: write our partitions (used to be: disklabel) */
for (i = 0; i < num_parts; i++) {
if (!allparts[i]->pscheme->write_to_disk(allparts[i])) {
res = false;
goto out;
}
}
/* phase 3: now we may have a first chance to enable swap space */
set_swap_if_low_ram(install);
#ifndef NO_CLONES
/* phase 4: copy any cloned partitions data (if requested) */
for (i = 0; i < install->num; i++) {
if ((install->infos[i].flags & PUIFLG_CLONE_PARTS) == 0
|| install->infos[i].clone_src == NULL
|| !install->infos[i].clone_src->with_data)
continue;
src = &install->infos[i].clone_src
->selection[install->infos[i].clone_ndx];
clone_partition_data(install->infos[i].parts,
install->infos[i].cur_part_id,
src->parts, src->id);
}
#endif
/* phase 5: post disklabel (used for updating boot loaders) */
for (i = 0; i < num_parts; i++) {
if (!md_post_disklabel(install, allparts[i])) {
res = false;
goto out;
}
}
out:
free(allparts);
return res;
}
/* Do the system install. */
void
do_install(void)
{
int find_disks_ret;
int retcode = 0, res;
struct install_partition_desc install = {};
#ifndef NO_PARTMAN
partman_go = -1;
#else
partman_go = 0;
#endif
#ifndef DEBUG
msg_display(MSG_installusure);
if (!ask_noyes(NULL))
return;
#endif
memset(&install, 0, sizeof install);
/* Create and mount partitions */
find_disks_ret = find_disks(msg_string(MSG_install), false);
if (partman_go == 1) {
if (partman(&install) < 0) {
hit_enter_to_continue(MSG_abort_part, NULL);
return;
}
} else if (find_disks_ret < 0)
return;
else {
/* Classical partitioning wizard */
partman_go = 0;
clear();
refresh();
if (check_swap(pm->diskdev, 0) > 0) {
hit_enter_to_continue(MSG_swapactive, NULL);
if (check_swap(pm->diskdev, 1) < 0) {
hit_enter_to_continue(MSG_swapdelfailed, NULL);
if (!debug)
return;
}
}
for (;;) {
if (md_get_info(&install)) {
res = md_make_bsd_partitions(&install);
if (res == -1) {
pm->parts = NULL;
continue;
} else if (res == 1) {
break;
}
}
hit_enter_to_continue(MSG_abort_inst, NULL);
goto error;
}
/* Last chance ... do you really want to do this? */
clear();
refresh();
msg_fmt_display(MSG_lastchance, "%s", pm->diskdev);
if (!ask_noyes(NULL))
goto error;
if ((!pm->no_part && !write_all_parts(&install)) ||
make_filesystems(&install) ||
make_fstab(&install) != 0 ||
md_post_newfs(&install) != 0)
goto error;
}
/* Unpack the distribution. */
process_menu(MENU_distset, &retcode);
if (retcode == 0)
goto error;
if (get_and_unpack_sets(0, MSG_disksetupdone,
MSG_extractcomplete, MSG_abortinst) != 0)
goto error;
if (md_post_extract(&install, false) != 0)
goto error;
root_pw_setup();
#if CHECK_ENTROPY
do_add_entropy();
#endif
do_configmenu(&install);
sanity_check();
md_cleanup_install(&install);
hit_enter_to_continue(MSG_instcomplete, NULL);
error:
free_install_desc(&install);
}
|