From 01bca3b459d49d1211e5e6b858ecdae8d9a6effd Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Sun, 31 Aug 2008 17:50:55 +0000 Subject: * moved code into BootEnvironment::Base.pm, all boot environments need to generate the same system-specific files anyway (since the actual booting process is identical, it's only the preboot stuff that differs) git-svn-id: http://svn.openslx.org/svn/openslx/openslx/trunk@2163 95ad53e4-c205-0410-b2fa-d234c58c8868 --- boot-env/OpenSLX/BootEnvironment/Base.pm | 96 +++++++++++++++++++++++--- boot-env/OpenSLX/BootEnvironment/PREBOOT_CD.pm | 75 -------------------- boot-env/OpenSLX/BootEnvironment/PXE.pm | 71 ------------------- 3 files changed, 85 insertions(+), 157 deletions(-) diff --git a/boot-env/OpenSLX/BootEnvironment/Base.pm b/boot-env/OpenSLX/BootEnvironment/Base.pm index af47f859..78732957 100644 --- a/boot-env/OpenSLX/BootEnvironment/Base.pm +++ b/boot-env/OpenSLX/BootEnvironment/Base.pm @@ -18,10 +18,16 @@ use warnings; our $VERSION = 1.01; # API-version . implementation-version +use Clone qw(clone); +use File::Basename; use File::Path; use OpenSLX::Basics; use OpenSLX::ConfigDB; +use OpenSLX::MakeInitRamFS::Engine; +use OpenSLX::Utils; + +our %initramfsMap; sub new { @@ -62,13 +68,6 @@ sub finalize return 1; } -sub targetPath -{ - my $self = shift; - - return $self->{'target-path'}; -} - sub writeBootloaderMenuFor { my $self = shift; @@ -81,10 +80,85 @@ sub writeBootloaderMenuFor sub writeFilesRequiredForBooting { - my $self = shift; - my $info = shift; - my $tftpbuildPath = shift; - my $slxVersion = shift; + my $self = shift; + my $info = shift; + my $buildPath = shift; + my $slxVersion = shift; + + my $kernelFile = $info->{'kernel-file'}; + my $kernelName = basename($kernelFile); + + my $vendorOSPath = "$self->{'target-path'}/$info->{'vendor-os'}->{name}"; + mkpath $vendorOSPath unless -e $vendorOSPath || $self->{'dry-run'}; + + my $targetKernel = "$vendorOSPath/$kernelName"; + if (!-e $targetKernel) { + vlog(1, _tr('copying kernel %s to %s', $kernelFile, $targetKernel)); + slxsystem(qq[cp -p "$kernelFile" "$targetKernel"]) + unless $self->{'dry-run'}; + } + + # reuse initramfs if it has already been created for another boot + # environment, create it otherwise: + my $initramfsName = "$vendorOSPath/$info->{'initramfs-name'}"; + my $initramfsID = $info->{'initramfs-name'}; + my $cached = $initramfsMap{$initramfsID}; + if ($cached) { + my $file = $cached->{file}; + vlog(1, _tr('copying initialramfs %s from %s', $initramfsName, $file)); + slxsystem("cp -a $file $initramfsName") unless $self->{'dry-run'}; + $info->{kernel_params} = $cached->{kernel_params}; + return 0; + } + else { + vlog(1, _tr('generating initialramfs %s', $initramfsName)); + $self->_makeInitRamFS($info, $initramfsName, $slxVersion); + $initramfsMap{$initramfsID} = { + file => $initramfsName, + kernel_params => $info->{kernel_params}, + }; + return 1; + } +} + +sub _makeInitRamFS +{ + my $self = shift; + my $info = shift; + my $initramfs = shift; + my $slxVersion = shift; + + my $vendorOS = $info->{'vendor-os'}; + my $kernelFile = basename(followLink($info->{'kernel-file'})); + + my $attrs = clone($info->{attrs} || {}); + + my $params = { + 'attrs' => $attrs, + 'export-name' => $info->{export}->{name}, + 'export-uri' => $info->{'export-uri'}, + 'initramfs' => $initramfs, + 'kernel-params' => [ split ' ', ($info->{kernel_params} || '') ], + 'kernel-version' => $kernelFile =~ m[-(.+)$] ? $1 : '', + 'plugins' => $info->{'active-plugins'}, + 'root-path' + => "$openslxConfig{'private-path'}/stage1/$vendorOS->{name}", + 'slx-version' => $slxVersion, + 'system-name' => $info->{name}, + }; + + # TODO: make debug-level an explicit attribute, it's used in many places! + my $kernelParams = $info->{kernel_params} || ''; + if ($kernelParams =~ m{debug(?:=(\d+))?}) { + my $debugLevel = defined $1 ? $1 : '1'; + $params->{'debug-level'} = $debugLevel; + } + + my $makeInitRamFSEngine = OpenSLX::MakeInitRamFS::Engine->new($params); + $makeInitRamFSEngine->execute($self->{'dry-run'}); + + # copy back kernel-params, as they might have been changed (by plugins) + $info->{kernel_params} = join ' ', $makeInitRamFSEngine->kernelParams(); return; } diff --git a/boot-env/OpenSLX/BootEnvironment/PREBOOT_CD.pm b/boot-env/OpenSLX/BootEnvironment/PREBOOT_CD.pm index 62ab499f..84c43d06 100644 --- a/boot-env/OpenSLX/BootEnvironment/PREBOOT_CD.pm +++ b/boot-env/OpenSLX/BootEnvironment/PREBOOT_CD.pm @@ -18,12 +18,10 @@ use warnings; use base qw(OpenSLX::BootEnvironment::Base); -use Clone qw(clone); use File::Basename; use File::Path; use OpenSLX::Basics; -use OpenSLX::MakeInitRamFS::Engine; use OpenSLX::Utils; sub initialize @@ -45,77 +43,4 @@ sub initialize return 1; } -sub writeFilesRequiredForBooting -{ - my $self = shift; - my $info = shift; - my $tftpbuildPath = shift; - my $slxVersion = shift; - -print "CD-boot not implemented yet\n"; - -return 1; - - my $kernelFile = $info->{'kernel-file'}; - my $kernelName = basename($kernelFile); - - my $vendorOSPath = "$tftpbuildPath/$info->{'vendor-os'}->{name}"; - mkpath $vendorOSPath unless -e $vendorOSPath || $self->{'dry-run'}; - - my $targetKernel = "$vendorOSPath/$kernelName"; - if (!-e $targetKernel) { - vlog(1, _tr('copying kernel %s to %s', $kernelFile, $targetKernel)); - slxsystem(qq[cp -p "$kernelFile" "$targetKernel"]) - unless $self->{'dry-run'}; - } - my $initramfs = "$vendorOSPath/$info->{'initramfs-name'}"; - $self->_makeInitRamFS($info, $initramfs, $slxVersion); - - return 1; -} - -sub _makeInitRamFS -{ - my $self = shift; - my $info = shift; - my $initramfs = shift; - my $slxVersion = shift; - - vlog(1, _tr('generating initialramfs %s', $initramfs)); - - my $vendorOS = $info->{'vendor-os'}; - my $kernelFile = basename(followLink($info->{'kernel-file'})); - - my $attrs = clone($info->{attrs} || {}); - - my $params = { - 'attrs' => $attrs, - 'export-name' => $info->{export}->{name}, - 'export-uri' => $info->{'export-uri'}, - 'initramfs' => $initramfs, - 'kernel-params' => [ split ' ', ($info->{kernel_params} || '') ], - 'kernel-version' => $kernelFile =~ m[-(.+)$] ? $1 : '', - 'plugins' => $info->{'active-plugins'}, - 'root-path' - => "$openslxConfig{'private-path'}/stage1/$vendorOS->{name}", - 'slx-version' => $slxVersion, - 'system-name' => $info->{name}, - }; - - # TODO: make debug-level an explicit attribute, it's used in many places! - my $kernelParams = $info->{kernel_params} || ''; - if ($kernelParams =~ m{debug(?:=(\d+))?}) { - my $debugLevel = defined $1 ? $1 : '1'; - $params->{'debug-level'} = $debugLevel; - } - - my $makeInitRamFSEngine = OpenSLX::MakeInitRamFS::Engine->new($params); - $makeInitRamFSEngine->execute($self->{'dry-run'}); - - # copy back kernel-params, as they might have been changed (by plugins) - $info->{kernel_params} = join ' ', $makeInitRamFSEngine->kernelParams(); - - return; -} - 1; diff --git a/boot-env/OpenSLX/BootEnvironment/PXE.pm b/boot-env/OpenSLX/BootEnvironment/PXE.pm index 25f2c77f..40c6acb4 100644 --- a/boot-env/OpenSLX/BootEnvironment/PXE.pm +++ b/boot-env/OpenSLX/BootEnvironment/PXE.pm @@ -18,12 +18,10 @@ use warnings; use base qw(OpenSLX::BootEnvironment::Base); -use Clone qw(clone); use File::Basename; use File::Path; use OpenSLX::Basics; -use OpenSLX::MakeInitRamFS::Engine; use OpenSLX::Utils; sub initialize @@ -110,31 +108,6 @@ sub writeBootloaderMenuFor return 1; } -sub writeFilesRequiredForBooting -{ - my $self = shift; - my $info = shift; - my $buildPath = shift; - my $slxVersion = shift; - - my $kernelFile = $info->{'kernel-file'}; - my $kernelName = basename($kernelFile); - - my $vendorOSPath = "$self->{'target-path'}/$info->{'vendor-os'}->{name}"; - mkpath $vendorOSPath unless -e $vendorOSPath || $self->{'dry-run'}; - - my $targetKernel = "$vendorOSPath/$kernelName"; - if (!-e $targetKernel) { - vlog(1, _tr('copying kernel %s to %s', $kernelFile, $targetKernel)); - slxsystem(qq[cp -p "$kernelFile" "$targetKernel"]) - unless $self->{'dry-run'}; - } - my $initramfs = "$vendorOSPath/$info->{'initramfs-name'}"; - $self->_makeInitRamFS($info, $initramfs, $slxVersion); - - return 1; -} - sub _getTemplate { my $self = shift; @@ -242,48 +215,4 @@ sub _prepareBootloaderConfigFolder return 1; } -sub _makeInitRamFS -{ - my $self = shift; - my $info = shift; - my $initramfs = shift; - my $slxVersion = shift; - - vlog(1, _tr('generating initialramfs %s', $initramfs)); - - my $vendorOS = $info->{'vendor-os'}; - my $kernelFile = basename(followLink($info->{'kernel-file'})); - - my $attrs = clone($info->{attrs} || {}); - - my $params = { - 'attrs' => $attrs, - 'export-name' => $info->{export}->{name}, - 'export-uri' => $info->{'export-uri'}, - 'initramfs' => $initramfs, - 'kernel-params' => [ split ' ', ($info->{kernel_params} || '') ], - 'kernel-version' => $kernelFile =~ m[-(.+)$] ? $1 : '', - 'plugins' => $info->{'active-plugins'}, - 'root-path' - => "$openslxConfig{'private-path'}/stage1/$vendorOS->{name}", - 'slx-version' => $slxVersion, - 'system-name' => $info->{name}, - }; - - # TODO: make debug-level an explicit attribute, it's used in many places! - my $kernelParams = $info->{kernel_params} || ''; - if ($kernelParams =~ m{debug(?:=(\d+))?}) { - my $debugLevel = defined $1 ? $1 : '1'; - $params->{'debug-level'} = $debugLevel; - } - - my $makeInitRamFSEngine = OpenSLX::MakeInitRamFS::Engine->new($params); - $makeInitRamFSEngine->execute($self->{'dry-run'}); - - # copy back kernel-params, as they might have been changed (by plugins) - $info->{kernel_params} = join ' ', $makeInitRamFSEngine->kernelParams(); - - return; -} - 1; -- cgit v1.2.3-55-g7522