From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Wed, 17 Dec 2003 21:28:47 +0300 From: Alexey Tourbin To: ALT Devel discussion list Message-ID: <20031217182847.GB18450@julia.office.altlinux.ru> Mail-Followup-To: ALT Devel discussion list References: <20031216180216.GA17963@basalt.office.altlinux.org> <20031216180827.GQ18450@julia.office.altlinux.ru> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="igABDXH78n6Jl+Hn" Content-Disposition: inline In-Reply-To: Subject: [devel] Re: kernel 2.6.0-test11 X-BeenThere: devel@altlinux.ru X-Mailman-Version: 2.1.3 Precedence: list Reply-To: ALT Devel discussion list List-Id: ALT Devel discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Dec 2003 18:29:03 -0000 Archived-At: List-Archive: List-Post: --igABDXH78n6Jl+Hn Content-Type: multipart/mixed; boundary="nR4f+zr2kNneuKs8" Content-Disposition: inline Content-Transfer-Encoding: 8bit --nR4f+zr2kNneuKs8 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: 8bit 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 должен расставлять симлинки и чем его текущее поведение не устраивает. --nR4f+zr2kNneuKs8 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="bootloader_utils.pm" 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 . # # Redistribution of this file is permitted under the terms of the GNU # Public License (GPL) #-------------------------------------------------------------------- # Copyright (C) 2003 by ALT Linux Team, # Alexey Tourbin . #-------------------------------------------------------------------- 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; --nR4f+zr2kNneuKs8 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=detectloader #!/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 . Copyright (C) 2000, 2001, 2002 by MandrakeSoft, Pixel 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"; --nR4f+zr2kNneuKs8-- --igABDXH78n6Jl+Hn Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iD8DBQE/4KBffBKgtDjnu0YRAsTTAJ9Zzr2L2I85L6FtpFnY/vj0BTX2/ACgxjKz Op6FzjdpVoj2lNEbb8OzcLE= =YBZo -----END PGP SIGNATURE----- --igABDXH78n6Jl+Hn--