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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
package install_interactive;
use diagnostics;
use strict;
use vars;
use common qw(:common :functional);
use fs;
use fsedit;
use log;
use partition_table qw(:types);
use partition_table_raw;
use detect_devices;
use install_steps;
use devices;
use modules;
sub partitionWizard {
my ($o, $hds, $fstab, $readonly) = @_;
my @wizlog;
my (@solutions, %solutions);
my $min_linux = 500 << 11;
my $max_linux = 2500 << 11;
my $min_swap = 50 << 11;
my $max_swap = 300 << 11;
my $min_freewin = 100 << 11;
# each solution is a [ score, text, function ], where the function retunrs true if succeeded
if (fsedit::free_space(grep { partition_table::can_raw_add($_) } @$hds) > $min_linux and !$readonly) {
$solutions{free_space} = [ 20, _("Use free space"), sub { fsedit::auto_allocate($hds, $o->{partitions}); 1 } ]
} else {
push @wizlog, _("Not enough free space to allocate new partitions");
}
if (@$fstab) {
my $truefs = grep { isTrueFS($_) } @$fstab;
#- value twice the ext2 partitions
$solutions{existing_part} = [ 6 + $truefs + @$fstab, _("Use existing partition"), sub { $o->ask_mntpoint_s($fstab) } ]
} else {
push @wizlog, _("There is no existing partition to use");
}
my @fats = grep { isFat($_) } @$fstab;
fs::df($_) foreach @fats;
if (my @ok_forloopback = sort { $b->{free} <=> $a->{free} } grep { $_->{free} > $min_linux + $min_freewin } @fats) {
$solutions{loopback} =
[ 5 - @fats, _("Use the FAT partition for loopback"),
sub {
my ($s_root, $s_swap);
my $part = $o->ask_from_listf('', _("Which partition do you want to use to put Linux4Win?"), \&partition_table_raw::description, \@ok_forloopback) or return;
$o->ask_from_entries_refH('', _("Choose the sizes"), [
_("Root partition size in MB: ") => { val => \$s_root, min => 1 + ($min_linux >> 11), max => min($part->{free} - 2 * $max_swap - $min_freewin, $max_linux) >> 11, type => 'range' },
_("Swap partition size in MB: ") => { val => \$s_swap, min => 1 + ($min_swap >> 11), max => 2 * $max_swap >> 11, type => 'range' },
]) or return;
push @{$part->{loopback}},
{ type => 0x83, loopback_file => '/lnx4win/linuxsys.img', mntpoint => '/', size => $s_root << 11, device => $part, notFormatted => 1 },
{ type => 0x82, loopback_file => '/lnx4win/swapfile', mntpoint => 'swap', size => $s_swap << 11, device => $part, notFormatted => 1 };
1;
} ];
$solutions{resize_fat} =
[ 6 - @fats, _("Use the free space on the FAT partition"),
sub {
my $part = $o->ask_from_listf('', _("Which partition do you want to resize?"), \&partition_table_raw::description, \@ok_forloopback) or return;
my $w = $o->wait_message(_("Resizing"), _("Computing FAT filesystem bounds"));
my $resize_fat = eval { resize_fat::main->new($part->{device}, devices::make($part->{device})) };
$@ and die _("The FAT resizer is unable to handle your partition,
the following error occured: %s", $@);
my $min_win = $resize_fat->min_size;
$part->{size} > $min_linux + $min_freewin + $min_win or die _("Your windows partition is too fragmented, please run ``defrag'' first");
$o->ask_okcancel('', _("WARNING!
DrakX will now resize your Windows partition. Be careful: this operation is
dangerous. If you have not already done so, you should first exit the
installation, run scandisk under Windows (and optionally run defrag), then
restart the installation. You should also backup your data.
When sure, press Ok.")) or return;
my $size = $part->{size};
$o->ask_from_entries_refH('', _("Which size do you want to keep for windows on"), [
_("partition %s", partition_table_raw::description($part)) => { val => \$size, min => 1 + ($min_win >> 11), max => ($part->{size} - $min_linux) >> 11, type => 'range' },
]) or return;
$size <<= 11;
local *log::l = sub { $w->set(join(' ', @_)) };
eval { $resize_fat->resize($size) };
$@ and die _("FAT resizing failed: %s", $@);
$part->{size} = $size;
$part->{isFormatted} = 1;
my ($hd) = grep { $_->{device} eq $part->{rootDevice} } @$hds;
$hd->{isDirty} = $hd->{needKernelReread} = 1;
$hd->adjustEnd($part);
partition_table::adjust_local_extended($hd, $part);
partition_table::adjust_main_extended($hd);
fsedit::auto_allocate($hds, $o->{partitions});
1;
} ] if !$readonly;
} else {
push @wizlog, _("There is no FAT partitions to resize or to use as loopback (or not enough space left)");
}
if (@$fstab && !$readonly) {
require diskdrake;
$solutions{wipe_drive} =
[ 10, fsedit::is_one_big_fat($hds) ? _("Remove Windows(TM)") : _("Take over the hard drive"),
sub {
my $hd = $o->ask_from_listf('', _("You have more than one hard drive, which one do you install linux on?"),
\&partition_table_raw::description, $hds) or return;
$o->ask_okcancel('', _("All existing partitions and their data will be lost on drive %s", $hd->{device})) or return;
partition_table_raw::zero_MBR($hd);
fsedit::auto_allocate($hds, $o->{partitions});
1;
} ];
}
if (!$readonly && ref($o) =~ /gtk/) { #- diskdrake only available in gtk for now
$solutions{diskdrake} =
[ 0, _("Use diskdrake"), sub {
my $ok = 1;
do {
diskdrake::main($hds, $o->{raid}, interactive_gtk->new, $o->{partitions});
my @fstab = fsedit::get_fstab(@$hds);
unless (fsedit::get_root(\@fstab)) {
$ok = 0;
$o->ask_okcancel('', _("You must have a root partition.
For this, create a partition (or click on an existing one).
Then choose action ``Mount point'' and set it to `/'"), 1) or return;
}
if (!grep { isSwap($_) } @fstab) {
$o->ask_warn('', _("You must have a swap partition")), $ok=0 if $::beginner;
$ok &&= $::expert || $o->ask_okcancel('', _("You don't have a swap partition\n\nContinue anyway?"));
}
} until $ok;
1;
} ];
}
$solutions{fdisk} =
[ -10, _("Use fdisk"), sub {
$o->suspend;
foreach (@$hds) {
print "\n" x 10, _("You can now partition %s.
When you are done, don't forget to save using `w'", partition_table_raw::description($_));
print "\n\n";
my $pid = fork or exec "fdisk", devices::make($_->{device});
waitpid($pid, 0);
}
$o->resume;
0;
} ] if $o->{partitioning}{fdisk};
log::l("partitioning wizard log:\n", (map { ">>wizlog>>$_\n" } @wizlog));
%solutions;
}
#--------------------------------------------------------------------------------
sub wait_load_module {
my ($o, $type, $text, $module) = @_;
#-PO: the first %s is the card type (scsi, network, sound,...)
#-PO: the second is the vendor+model name
$o->wait_message('',
[ _("Installing driver for %s card %s", $type, $text),
$::beginner ? () : _("(module %s)", $module)
]);
}
sub load_module {
my ($o, $type) = @_;
my @options;
my $m = $o->ask_from_listf('',
#-PO: the %s is the driver type (scsi, network, sound,...)
_("Which %s driver should I try?", $type),
\&modules::module2text,
[ modules::module_of_type($type) ]) or return;
my $l = modules::module2text($m);
require modparm;
my @names = modparm::get_options_name($m);
if ((@names != 0) && $o->ask_from_list_('',
_("In some cases, the %s driver needs to have extra information to work
properly, although it normally works fine without. Would you like to specify
extra options for it or allow the driver to probe your machine for the
information it needs? Occasionally, probing will hang a computer, but it should
not cause any damage.", $l),
[ __("Autoprobe"), __("Specify options") ], "Autoprobe") ne "Autoprobe") {
ASK:
if (@names >= 0) {
my @l = $o->ask_from_entries('',
_("You may now provide its options to module %s.", $l),
\@names) or return;
@options = modparm::get_options_result($m, @l);
} else {
@options = split ' ',
$o->ask_from_entry('',
_("You may now provide its options to module %s.
Options are in format ``name=value name2=value2 ...''.
For instance, ``io=0x300 irq=7''", $l),
_("Module options:"),
);
}
}
eval {
my $w = wait_load_module($o, $type, $l, $m);
modules::load($m, $type, @options);
};
if ($@) {
$o->ask_yesorno('',
_("Loading module %s failed.
Do you want to try again with other parameters?", $l), 1) or return;
goto ASK;
}
$l;
}
#------------------------------------------------------------------------------
sub load_thiskind {
my ($o, $type) = @_;
my $pcmcia = $o->{pcmcia} if modules::pcmcia_need_config($o->{pcmcia}) && !$::noauto;
my $w; $w = $o->wait_message(_("PCMCIA"), _("Configuring PCMCIA cards...")) if $pcmcia;
modules::load_thiskind($type, $pcmcia, sub { $w = wait_load_module($o, $type, @_) });
}
#------------------------------------------------------------------------------
sub setup_thiskind {
my ($o, $type, $auto, $at_least_one) = @_;
return if arch() eq "ppc";
my @l;
if (!$::noauto) {
@l = load_thiskind($o, $type);
if (my @err = grep { $_ } map { $_->{error} } @l) {
$o->ask_warn('', join("\n", @err));
}
return @l if $auto && (@l || !$at_least_one);
}
@l = map { $_->{description} } @l;
while (1) {
my $msg = @l ?
[ _("Found %s %s interfaces", join(", ", @l), $type),
_("Do you have another one?") ] :
_("Do you have any %s interfaces?", $type);
my $opt = [ __("Yes"), __("No") ];
push @$opt, __("See hardware info") if $::expert;
my $r = "Yes";
$r = $o->ask_from_list_('', $msg, $opt, "No") unless $at_least_one && @l == 0;
if ($r eq "No") { return @l }
if ($r eq "Yes") {
push @l, load_module($o, $type) || next;
} else {
$o->ask_warn('', [ detect_devices::stringlist() ]);
}
}
}
#------------------------------------------------------------------------------
sub upNetwork {
my ($o, $pppAvoided) = @_;
my $w = $o->wait_message('', _("Bringing up the network"));
install_steps::upNetwork($o, $pppAvoided);
}
sub downNetwork {
my ($o, $pppOnly) = @_;
my $w = $o->wait_message('', _("Bringing down the network"));
install_steps::downNetwork($o, $pppOnly);
}
1;
|