Here is a short description to configure a PXE server using dhcpd and tftpd. This allows a network boot for your ethernet card conforming to the Interl PXE specification. ******************************************************************************** ********** General overview ************ ******************************************************************************** You need a dhcp server and a tftp server on one or two machines to allow the network boot. We are not using a PXE server to achieve this as it is not mandatory. You can install tftp-server and dhcp-server package from the Mandrake distribution for example. On the server machine at 192.168.2.1, you will find a "/etc/dhcpd.conf" sample file written by Florin Grad , where "mydomain.com" is assumed to be your domain name, and 192.168.1.1 a name server. All install are done on subnet 192.168.2.0. All the files that will be downloaded by the tftp daemon are located under "/tftpboot" : "/tftpboot/pxelinux.0" is a program that is loaded directly by the machine where a network boot will be done, this program comes from the SYSLINUX package by H. Peter Anvin. (look at http://syslinux.zytor.com/pxe.php for more information) "/tftpboot/pxelinux.cfg/" is a directory where all configuration file for pxelinux.0 will be found, pxelinux.0 will download these file by itself. It searches first for a file named accordind to the machine IP address in hexadecimal, for example for 192.168.2.20, it looks for "C0A80214" first, then "C0A8021" and so on down to "C0", "C" and "default". "/tftpboot/network.rdz" is the standard network initrd for Mandrake installation. "/tftpboot/vmlinuz" is the boot kernel for installation. "/tftpboot/help.msg" is the message displayed by pxelinux.0, note that currently graphical message (as for install using SYSLINUX 1.48 with graphic patch by Mandrake) is not supported. All file "network.rdz", "vmlinuz", "help.msg" can be found by mounting "network.img", or the network floppy disk used for install, "pxelinux.cfg" is just an adaptation of the file found on the "network.img" called "syslinux.cfg" but without the reference to boot.msg (as it is not currently supported). Update network configuration for your needs and start dhcp server on the machine and tftp server and this should work. ******************************************************************************** * /etc/dhcpd.conf ************************************************************** ******************************************************************************** ddns-update-style ad-hoc; authoritative; option space PXE; option PXE.mtftp-ip code 1 = ip-address; option PXE.mtftp-cport code 2 = unsigned integer 16; option PXE.mtftp-sport code 3 = unsigned integer 16; option PXE.mtftp-tmout code 4 = unsigned integer 8; option PXE.mtftp-delay code 5 = unsigned integer 8; option PXE.discovery-control code 6 = unsigned integer 8; option PXE.discovery-mcast-addr code 7 = ip-address; default-lease-time 28800; max-lease-time 86400; option domain-name "mydomain.com"; option domain-name-servers 192.168.1.1; class "PXE" { match if substring(option vendor-class-identifier, 0, 9) = "PXEClient"; option vendor-class-identifier "PXEClient"; vendor-option-space PXE; option PXE.mtftp-ip 0.0.0.0; next-server 192.168.2.1; #tftp server location filename "pxelinux.0"; # standard TFTP } shared-network "mynetwork" { subnet 192.168.2.0 netmask 255.255.255.0 { option subnet-mask 255.255.255.0; option routers 192.168.2.1; ddns-domainname = "mydomain.com"; pool { range 192.168.2.10 192.168.2.20; allow members of "PXE"; } } } ******************************************************************************** * /tftpboot/pxelinux.cfg/default *********************************************** ******************************************************************************** default linux prompt 1 timeout 72 display help.msg label linux kernel vmlinuz append ramdisk_size=32000 initrd=network.rdz root=/dev/ram3 vga=788 label vgalo kernel vmlinuz append ramdisk_size=32000 initrd=network.rdz root=/dev/ram3 vga=785 label vgahi kernel vmlinuz append ramdisk_size=32000 initrd=network.rdz root=/dev/ram3 vga=791 label vga16 kernel vmlinuz append ramdisk_size=32000 initrd=network.rdz root=/dev/ram3 vga16 label text kernel vmlinuz append ramdisk_size=32000 initrd=network.rdz root=/dev/ram3 text label patch kernel vmlinuz append ramdisk_size=32000 initrd=network.rdz root=/dev/ram3 patch vga=788 label expert kernel vmlinuz append ramdisk_size=32000 initrd=network.rdz root=/dev/ram3 expert vga=788 label rescue kernel vmlinuz append ramdisk_size=32000 initrd=network.rdz root=/dev/ram3 rescue rw label oem kernel vmlinuz append ramdisk_size=32000 initrd=network.rdz automatic=method:cdrom root=/dev/ram3 rescue oem rw ******************************************************************************** * Usefull linkst *************************************************************** ******************************************************************************** http://syslinux.zytor.com/pxe.php http://www.kano.org.uk/projects/pxe/ tion value='range'>range
path: root/perl-install/common.pm
blob: adaa07a0dc96be492a39544c281de01c2a896325 (plain)
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
package common; # $Id: common.pm 245955 2008-09-18 14:19:04Z pixel $

use MDK::Common;
use diagnostics;
use strict;
BEGIN { eval { require Locale::gettext } } #- allow common.pm to be used in drakxtools-backend without perl-Locale-gettext

use log;
use run_program;

use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw($SECTORSIZE N P N_ check_for_xserver files_exist formatTime MB formatXiB get_parent_uid is_running makedev mageia_release mageia_release_info removeXiBSuffix require_root_capability setVirtual set_alternative set_l10n_sort set_permissions to_utf8  translate unmakedev);

# perl_checker: RE-EXPORT-ALL
push @EXPORT, @MDK::Common::EXPORT;


$::prefix ||= ""; # no warning

#-#####################################################################################
#- Globals
#-#####################################################################################
our $SECTORSIZE  = 512;

#-#####################################################################################
#- Functions
#-#####################################################################################

sub P {
    my ($s_singular, $s_plural, $nb, @para) = @_; 
    sprintf(translate($s_singular, $s_plural, $nb), @para);
}

sub N {
    my ($s, @para) = @_; 
    sprintf(translate($s), @para);
}
sub N_ { $_[0] }


sub makedev { ($_[0] << 8) | $_[1] }
sub unmakedev { $_[0] >> 8, $_[0] & 0xff }

sub translate_real {
    my ($s, $o_plural, $o_nb) = @_;
    $s or return '';
    my $s2;
    foreach (@::textdomains, 'libDrakX') {
     if ($o_plural) {
         $s2 = Locale::gettext::dngettext($_, $s, $o_plural, $o_nb);
     } else {
         $s2 = Locale::gettext::dgettext($_, $s);
     }
	# when utf8 pragma is in use, Locale::gettext() returns an utf8 string not tagged as such:
	c::set_tagged_utf8($s2) if !utf8::is_utf8($s2) && utf8::is_utf8($s);
	return $s2 if $s ne $s2 && $s2 ne $o_plural;
    }
    # didn't lookup anything or locale is "C":
    $s2;
}

sub remove_translate_context {
    my ($s) = @_;
    #- translation with context, kde-like 
    $s =~ s/^_:.*\n//;
    $s;
}

sub translate {
    my $s = translate_real(@_);
    $::one_message_has_been_translated ||= join(':', (caller(1))[1,2]); #- see mygtk2.pm
    remove_translate_context($s);
}

sub from_utf8 {
    my ($s) = @_;
    Locale::gettext::iconv($s, "utf-8", undef); #- undef = locale charmap = nl_langinfo(CODESET)
}
sub to_utf8 { 
    my ($s) = @_;
    my $str = Locale::gettext::iconv($s, undef, "utf-8"); #- undef = locale charmap = nl_langinfo(CODESET)
    c::set_tagged_utf8($str);
    $str;
}

#- This is needed because text printed by Gtk2 will always be encoded
#- in UTF-8;
#- we first check if LC_ALL is defined, because if it is, changing
#- only LC_COLLATE will have no effect.
sub set_l10n_sort() {
    my $collation_locale = $ENV{LC_ALL};
    if (!$collation_locale) {
        $collation_locale = c::setlocale(c::LC_COLLATE());
        $collation_locale =~ /UTF-8/ or c::setlocale(c::LC_COLLATE(), "$collation_locale.UTF-8");
    }
}


sub setVirtual {
    my ($vt_number) = @_;
    my $vt = '';
    sysopen(my $C, "/dev/console", 2) or die "failed to open /dev/console: $!";
    ioctl($C, c::VT_GETSTATE(), $vt) &&
      ioctl($C, c::VT_ACTIVATE(), $vt_number) &&
	ioctl($C, c::VT_WAITACTIVE(), $vt_number) or die "setVirtual failed";
    unpack "S", $vt;
}

sub nonblock {
    my ($F) = @_;
    fcntl($F, c::F_SETFL(), fcntl($F, c::F_GETFL(), 0) | c::O_NONBLOCK()) or die "cannot fcntl F_SETFL: $!";
}

#- return a size in sector
#- ie MB(1) is 2048 sectors, which is 1MB
sub MB {
    my ($nb_MB) = @_;
    $nb_MB * 2048;
}

sub removeXiBSuffix {
    local $_ = shift;

    /(\d+)\s*kB?$/i and return $1 * 1024;
    /(\d+)\s*MB?$/i and return $1 * 1024 * 1024;
    /(\d+)\s*GB?$/i and return $1 * 1024 * 1024 * 1024;
    /(\d+)\s*TB?$/i and return $1 * 1024 * 1024 * 1024 * 1024;
    $_;
}
sub formatXiB {
    my ($newnb, $o_newbase) = @_;
    my $newbase = $o_newbase || 1;
    my $sign = $newnb < 0 ? -1 : 1;
    $newnb = abs(int($newnb));
    my ($nb, $base);
    my $decr = sub { 
	($nb, $base) = ($newnb, $newbase);
	$base >= 1024 ? ($newbase = $base / 1024) : ($newnb = $nb / 1024);
    };
    my $suffix;
    foreach (N("B"), N("KB"), N("MB"), N("GB"), N("TB")) {
	$decr->(); 
	if ($newnb < 1 && $newnb * $newbase < 1) {
	    $suffix = $_;
	    last;
	}
    }
    my $v = $nb * $base;
    my $s = $v < 10 && int(10 * $v - 10 * int($v));
    int($v * $sign) . ($s ? "." . abs($s) : '') . ($suffix || N("TB"));
}

sub formatTime {
    my ($s, $m, $h) = gmtime($_[0]);