[devel] Re: kernel 2.6.0-test11

Alexey Tourbin =?iso-8859-1?q?at_=CE=C1_altlinux=2Eru?=
Ср Дек 17 21:28:47 MSK 2003


On Wed, Dec 17, 2003 at 11:22:27AM +0300, Ed V. Bartosh wrote:
>  AT> Уже посмотрел.  Пусть пока так.
>  AT> Переписывание кода в прцессе.
> 
> Когда можно надеяться на появление сего в Сизифе ?

Сейчас полностью переписан /usr/sbin/detectloader.
От него оторван perl-MDK-Common, взамен написан модуль bootloader_utils.pm.

Остается переписать /usr/share/loader/{grub,lilo} и /sbin/installkernel.

Лучше объясните мне, как /sbin/installkernel должен расставлять симлинки
и чем его текущее поведение не устраивает.
----------- следующая часть -----------
package bootloader_utils;
# $Id: bootloader_utils.pm,v 1.2 2003/12/04 12:29:17 at Exp $
#--------------------------------------------------------------------
# Copyright (C) 2000, 2001, 2002 by MandrakeSoft.
# Chmouel Boudjnah <chmouel на mandrakesoft.com>.
#
# Redistribution of this file is permitted under the terms of the GNU 
# Public License (GPL)
#--------------------------------------------------------------------
# Copyright (C) 2003 by ALT Linux Team,
# Alexey Tourbin <at на altlinux.org>.
#--------------------------------------------------------------------

require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(mnt2dev partitions typeOfMBR getroot);

use strict;

sub fstab {
	open my $f, '/etc/fstab' or return;
	my @fstab;
	while (<$f>) {
		next if /^\s*#/;
		my @ent = split;
		push @fstab, \@ent;
	}
	return @fstab;
}

sub mnt2dev {
	my $mnt = shift;
	foreach my $ent (fstab()) {
		return $$ent[0] if $$ent[1] eq $mnt;
	}
	return;
}

my @MBR_signatures = (
	[ 'empty', 0, "\0\0\0\0" ],
	[ 'grub', 0, "\xEBG", 0x17d, "stage1 \0" ],
	[ 'grub', 0, "\xEBH", 0x17e, "stage1 \0" ],
	[ 'grub', 0, "\xEBH", 0x18a, "stage1 \0" ],
	[ 'grub', 0, "\xEBH", 0x181, "GRUB \0" ],
	[ 'lilo', 0x2,  "LILO" ],
	[ 'lilo', 0x6,  "LILO" ],
	[ 'grub', 0x6,  "GRUB" ],
	[ 'osbs', 0x2,  "OSBS" ], #- http://www.prz.tu-berlin.de/~wolf/os-bs.html
	[ 'pqmagic', 0xef, "PQV" ],
	[ 'BootStar', 0x130, "BootStar:" ],
	[ 'DocsBoot', 0x148, 'DocsBoot' ],
	[ 'system_commander', 0x1ad, "SYSCMNDRSYS" ],
	[ 'Be Os', 0x24, 'Boot Manager' ],
	[ 'os2', 0, "\xFA\xB8\x30\x00", 0xfA, "OS/2" ],
	[ 'TimO', 0, 'IBM Thinkpad hibernation partition' ],
	[ 'dos', 0xa0, "\x25\x03\x4E\x02\xCD\x13" ],
	[ 'dos', 0xa0, "\x00\xB4\x08\xCD\x13\x72" ], #- nt2k's
	[ 'dos', 0x60, "\xBB\x00\x7C\xB8\x01\x02\x57\xCD\x13\x5F\x73\x0C\x33\xC0\xCD\x13" ], #- nt's
	[ 'dos', 0x70, "\x0C\x33\xC0\xCD\x13\x4F\x75\xED\xBE\xA3" ],
	[ 'freebsd', 0xC0, "\x00\x30\xE4\xCD\x16\xCD\x19\xBB\x07\x00\xB4" ],
	[ 'freebsd', 0x160, "\x6A\x10\x89\xE6\x48\x80\xCC\x40\xCD\x13" ],
	[ 'dummy', 0xAC, "\x0E\xB3\x07\x56\xCD\x10\x5E\xEB" ], #- caldera?
	[ 'ranish', 0x100, "\x6A\x10\xB4\x42\x8B\xF4\xCD\x13\x8B\xE5\x73" ],
	[ 'os2', 0x1c2, "\x0A" ],
	[ 'Acronis', 0, "\xE8\x12\x01" ],
);

sub typeFromMagic {
	my $fname = shift;
	sysopen my $fh, $fname, 0 or return;
set:	foreach my $set (@_) {
		my ($type, %magic) = @$set;
		while (my ($offset, $signature) = each %magic) {
			sysseek($fh, $offset, 0)
				or next set;
			my $n = length $signature;
			sysread($fh, my $buf, $n) == $n
				or next set;
			$buf eq $signature
				or next set;
		}
		return $type;
	}
	return;
}

use File::Temp qw(tempdir);
use sigtrap qw(die normal-signals);

sub typeOfMBR($) {
	my $disk = shift;
	my $dev = "/dev/$$disk{dev}";
	unless (-b $dev) {
		my $dir = tempdir("bootloader.XXXXXXXXXX", CLEANUP => 1, TMPDIR => 1);
		$dev = "$dir/$$disk{dev}";
		system "mknod", $dev, "b", $$disk{major}, $$disk{minor};
		die "$0: cannot create block special file $dev\n"
			unless $? == 0 && -b $dev;
	}
	return typeFromMagic($dev, @MBR_signatures);
}

sub media_type {
	my $dev = shift;
	open my $fh, "/proc/ide/$dev/media" or return;
	my $type = <$fh>;
	chomp $type;
	return $type;
}

sub partitions {
	open my $fh, "/proc/partitions" or return;
	my @all;
	while (<$fh>) {
		next unless /\d/;
		my %ent;
		@ent{qw(major minor size dev)} = split;
		$ent{media} = media_type $ent{dev};
		push @all, \%ent;
	}
	return @all;
}

sub getroot {
	if (open my $fh, "/proc/cmdline") {
		return $1 if <$fh> =~ /root=(\/\S+)/;
	}
	my $root = mnt2dev("/");
	return $root if $root;
	return $& if `/usr/sbin/rdev` =~ /\/\S+/;
	return;	
}

1;
----------- следующая часть -----------
#!/usr/bin/perl
# $Id: detectloader,v 1.3 2003/12/06 15:21:28 at Exp $

=head1	NAME

detectloader - detect what type of loader you have on your disk

=head1	DESCRIPTION

detectloader detects the type of the boot loader you have on your MBR.  It
finds the first disk via /proc/partitions and looks via the magic serial what
kind of boot loader you have installed.  If neither LILO nor GRUB is found on
MBR, try partitions too.

=head1	LIMITATION

Supports only grub and lilo.  Patches welcome for other boot loaders.

=head1	COPYRIGHT

Copyright (C) 2003 by ALT Linux Team, Alexey Tourbin <at на altlinux.org>.

Copyright (C) 2000, 2001, 2002 by MandrakeSoft, Pixel <pixel на mandrakesoft.com>
and others MandrakeSoft folks.

Redistribution of this file is permitted under the terms of the GNU 
Public License (GPL).

=cut

use bootloader_utils qw(partitions typeOfMBR);
use strict;

use Getopt::Long qw(GetOptions);
GetOptions "q|quiet" => \my $quiet
	or die "usage: $0 [-q|--quiet]\n";

sub warning {
	warn "@_\n" unless $quiet;
}

sub read_skiplist {
	open my $fh, "/etc/bootloader/skiplist" or return;
	my @list;
	while (<$fh>) {
		next unless /^#/;
		/\S+/ and push @list, $&;
	}
	return @list;
}

sub detect {
	my %known_loaders = map { $_ => 1 } qw(grub lilo);
	my %skiplist = map { $_ => 1 } read_skiplist();
	my (@disks, @partitions);
	foreach (partitions()) {
		next if $skiplist{$$_{dev}};
		next if $$_{media} eq "cdrom";
		$$_{dev} =~ /\d$/
			? push @partitions, $_
			: push @disks, $_
			;
	}
	foreach my $disk (@disks) {
		my $loader = typeOfMBR($disk);
		if ($known_loaders{$loader}) {
			warning "$0: $$disk{dev}: $loader";
			return $loader;
		}
	}
	warning "no bootloader on MBR, trying partitions!";
	open my $pipe, "-|", "fdisk", "-l",
		or warning "$0: fdisk not available"
		and return;
	while (<$pipe>) {
		next unless m#^/dev/(\w+\d+)\s+\*\s+#;
		next if $skiplist{$1};
		my ($partition) = grep { $$_{dev} eq $1 } @partitions;
		next unless $partition;
		my $loader = typeOfMBR($partition);
		if ($known_loaders{$loader}) {
			warning "$0: $$partition{dev}: $loader";
			return $loader;
		}
	}
	return;
}

my $loader = $ENV{DEFAULT_LOADER} || detect();
print uc($loader) . "\n";
----------- следующая часть -----------
Было удалено вложение не в текстовом формате...
Имя     : =?iso-8859-1?q?=CF=D4=D3=D5=D4=D3=D4=D7=D5=C5=D4?=
Тип     : application/pgp-signature
Размер  : 189 байтов
Описание: =?iso-8859-1?q?=CF=D4=D3=D5=D4=D3=D4=D7=D5=C5=D4?=
Url     : <http://lists.altlinux.org/pipermail/devel/attachments/20031217/ddc7997e/attachment-0001.bin>


Подробная информация о списке рассылки Devel