ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Alexey Tourbin <at@altlinux.ru>
To: ALT Devel discussion list <devel@altlinux.ru>
Subject: [devel] Re: kernel 2.6.0-test11
Date: Wed, 17 Dec 2003 21:28:47 +0300
Message-ID: <20031217182847.GB18450@julia.office.altlinux.ru> (raw)
In-Reply-To: <m3wu8vq2f0.fsf@altlinux.ru>


[-- Attachment #1.1: Type: text/plain, Size: 514 bytes --]

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 должен расставлять симлинки
и чем его текущее поведение не устраивает.

[-- Attachment #1.2: bootloader_utils.pm --]
[-- Type: text/plain, Size: 3636 bytes --]

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;

[-- Attachment #1.3: detectloader --]
[-- Type: text/plain, Size: 2199 bytes --]

#!/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";

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2003-12-17 18:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-16 16:43 [devel] " Ed V. Bartosh
2003-12-16 18:02 ` Dmitry V. Levin
2003-12-16 18:08   ` [devel] " Alexey Tourbin
2003-12-17  8:22     ` Ed V. Bartosh
2003-12-17 18:28       ` Alexey Tourbin [this message]
2003-12-17 20:21         ` Sergey Vlasov
2003-12-18  7:36         ` Michael Shigorin
2003-12-17  8:20   ` [devel] " Ed V. Bartosh
2003-12-17  9:47     ` Sergey Vlasov
2003-12-17 10:04 ` [devel] Re: [d-kernel] " Anton Farygin
2003-12-17  9:05   ` Ed V. Bartosh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031217182847.GB18450@julia.office.altlinux.ru \
    --to=at@altlinux.ru \
    --cc=devel@altlinux.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git