ALT Linux kernel packages development
 help / color / mirror / Atom feed
From: Alexey Tourbin <at@altlinux.ru>
To: devel-kernel@altlinux.org
Subject: [d-kernel] Re: /sbin/installkernel vs DURING_INSTALL
Date: Thu, 18 Dec 2003 20:02:19 +0300
Message-ID: <20031218170219.GU18450@julia.office.altlinux.ru> (raw)
In-Reply-To: <20031218162939.GG17423@master.mivlgu.local>


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

On Thu, Dec 18, 2003 at 07:29:39PM +0300, Sergey Vlasov wrote:
> On Thu, Dec 18, 2003 at 07:20:08PM +0300, Alexey Tourbin wrote:
> > Господа, сейчас имеется следующее:
> > [[ -n "$DURING_INSTALL" ]] && exit 0
> > 
> > Мне кажется это неверным.  В процессе установки имеется важная
> > информация об устанавливаемом ядре, а именно: %version.  Поэтому после
> > окончания установки без дополнительной информации (heuristics) нормально
> > установить ядро нельзя.
> 
> Зато в этот момент нет другой информации - о загрузчике и его настройках.

Хочется, чтобы %post скрипт ядра отрабатывал хотя бы на уровне
модификации конфигов /etc/lilo.conf и /boot/grub/menu.lst.  Это есть
залог того, что %postun скрипт тоже отработает правильно.  Иначе будут
угадывания и симлинки + проблемы "с первым ядром".

> > Вообще же кривость этого скрипта заставляет меня сомневаться в
> > необходимости того, чем этот скрипт занимается.
> 
> :)

Большой и кривой.

Пока есть следующее представление: /usr/share/loader/{lilo,gurb} должны
изменять конфиги и не делать ничего больше.  Это есть также некоторое
оправдание того, чтобы им быть написанным на перле.

Запуском /sbin/lilo и расставлением симлинков должен заниматься
/sbin/installkernel.

Предварительные версии /usr/share/loader/{lilo,gurb} я отдаю на
рассмотрение (в grub не доделаны параметры для kernel).  Над
/sbin/installkernel надо медитировать.

[-- Attachment #1.2: lilo --]
[-- Type: text/plain, Size: 2421 bytes --]

#!/usr/bin/perl
# $Id: lilo,v 1.1.1.1 2003/11/26 19:11:38 at Exp $
#--------------------------------------------------------------------
# Copyright (C) 2000, 2001 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>.
#--------------------------------------------------------------------
# description: Add/remove entry for lilo bootloader.

use strict;
use Getopt::Long qw(GetOptions);
GetOptions "n|nolaunch" => \my $nolaunch, "r|remove" => \my $remove, "m|memtest" => \my $memtest
	and (my $version = shift) and (@ARGV == 0)
	or die "usage: $0 [-n|--nolaunch] [-r|--remove] [-m|--memtest] version\n";

use bootloader_utils qw(getroot);

sub add_memtest {
	local $_ = shift;
	my $txt = "image=/boot/memtest-$version\n\tlabel=memtest86-$version";
	/^image=\/boot\/memtest-\Q$version\E\b/m
		or $_ .= $txt;
	return $_;
}

sub remove_memtest {
	local $_ = shift;
	my @sections = split /^(?=image=)/m;
	@sections =  grep { !/^image=\/boot\/memtest-\Q$version\E\b/ } @sections;
	return join "" => @sections;
}

sub kernel_label {
	local $_ = shift;
	s/\.//g; 
	s/mdk|alt//;
	s/secure/sec/;
	s/enterprise/ent/;
	s/vanilla/vnl/;
	return $_;
}

sub add_kernel {
	local $_ = shift;
	my $label = kernel_label($version);
	my $root = getroot();
	my $txt = "image=/boot/vmlinuz-$version\n\tlabel=$label\n\troot=$root\n\tread-only\n\toptional\n";
	/^image=\/boot\/vmlinuz-\Q$version\E\b/
		or $_ .= $txt;
	return $_;
}

sub remove_kernel {
	local $_ = shift;
	my @sections = split /^(?=image=)/m;
	@sections = grep { !/^image=\/boot\/vmlinuz-\Q$version\E\b/ } @sections;
	return join "" => @sections;
}

{
# open lilo.conf for update
	my $lilo_conf = $ENV{LILO_CONF} || "/etc/lilo.conf";
	open my $fh, "+<", $lilo_conf
		or die "Cannot open $lilo_conf\n";
	local $/ = undef;
	my $content = <$fh>;
	
# modify the content
	if ($memtest && $remove) {
		$content = remove_memtest($content);
	} elsif ($memtest) {
		$content = add_memtest($content);
	} elsif ($remove) {
		$content = remove_kernel($content);
	} else {
		$content = add_kernel($content);
	}
# debug
	print $content;
	exit 0;

# do the update
	seek $fh, 0, 0;
	print $fh $content;
	truncate $fh, tell $fh;
# autoclosed
}

[-- Attachment #1.3: grub --]
[-- Type: text/plain, Size: 2718 bytes --]

#!/usr/bin/perl
# $Id: grub,v 1.3 2003/12/04 12:33:15 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>.
#--------------------------------------------------------------------
# description: Add/remove entry for grub bootloader.

use strict;
use bootloader_utils qw(mnt2dev getroot);

use Getopt::Long qw(GetOptions);
GetOptions "r|remove" => \my $remove, "m|memtest" => \my $memtest
	and (my $version = shift) and (@ARGV == 0)
	or die "usage: $0 [-r|--remove] [-m|--memtest] version\n";

sub dev2grub {
	my $dev = shift;
	my ($disk, $part) = $dev =~ /([^\d\s]+)(\d+)/
		or return;
# Sample device.map entry:
# (hd0) /dev/hda
# Sample convertion:
# /dev/hda5 => (hd0,4)
	$part--;
	my $map = $ENV{GRUB_DEVICE_MAP} || "/boot/grub/device.map";
	open my $fh, $map
		or return;
	my $grub_part;
	while (<$fh>) {
		if (/\((\w+d\d+)\)\s+\Q$disk\E$/) {
			$grub_part = "($1,$part)";
			last;
		}
	}
	return $grub_part;
}

my $boot = mnt2dev("/boot") ? "" : "/boot";
my $grub_part = dev2grub(getroot());
die "Can't convert grub_partition\n" unless $grub_part;

sub add_memtest {
	local $_ = shift;
	/\/memtest-\Q$version\E\b/
		or $_ .= <<EOF;

title memtest86-$version
kernel $grub_part$boot/memtest-$version.bin
EOF
	return $_;
}

sub remove_memtest {
	local $_ = shift;
	my @sections = split /^(?=title\s)/m;
	@sections =  grep { !/\/memtest-\Q$version\E\b/ } @sections;
	return join "" => @sections;
}

sub add_kernel {
	local $_ = shift;
	/\/vmlinuz-\Q$version\E\b/
		or $_ .= <<EOF;

title $version
kernel $grub_part$boot/vmlinuz-$version
initrd $grub_part$boot/initrd-$version.img
EOF
	return $_;
}

sub remove_kernel {
	local $_ = shift;
	my @sections = split /^(?=title\s)/m;
	@sections =  grep { !/\/vmlinuz-\Q$version\E\b/ } @sections;
	return join "" => @sections;
}

{
# open menu.lst for update
	my $menu_lst = $ENV{GRUB_MENU_LST} || "/boot/grub/menu.lst";
	open my $fh, "+<", $menu_lst
		or die "Cannot open $menu_lst\n";
	local $/ = undef;
	my $content = <$fh>;
	
# modify the content
	if ($memtest && $remove) {
		$content = remove_memtest($content);
	} elsif ($memtest) {
		$content = add_memtest($content);
	} elsif ($remove) {
		$content = remove_kernel($content);
	} else {
		$content = add_kernel($content);
	}
# debug
	print $content;
	exit 0;

# do the update
	seek $fh, 0, 0;
	print $fh $content;
	truncate $fh, tell $fh;
# autoclosed
}

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

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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-18 16:20 [d-kernel] " Alexey Tourbin
2003-12-18 16:29 ` Sergey Vlasov
2003-12-18 17:02   ` Alexey Tourbin [this message]
2003-12-18 18:10     ` [d-kernel] " Alexey I. Froloff
2003-12-18 20:30     ` Sergey Vlasov
2003-12-18 20:11 ` [d-kernel] " Michael Shigorin

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=20031218170219.GU18450@julia.office.altlinux.ru \
    --to=at@altlinux.ru \
    --cc=devel-kernel@altlinux.org \
    --cc=devel-kernel@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 kernel packages development

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel-kernel/0 devel-kernel/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-kernel devel-kernel/ http://lore.altlinux.org/devel-kernel \
		devel-kernel@altlinux.org devel-kernel@altlinux.ru devel-kernel@altlinux.com
	public-inbox-index devel-kernel

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


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