From 016a94742824cf1c4eb06c9a6a2ec6913c45a60d Mon Sep 17 00:00:00 2001 From: daniceexi Date: Wed, 31 Jul 2013 07:05:18 -0400 Subject: [PATCH] Change the insert_dd function for handling the initrd hacking. --- xCAT-server/lib/xcat/plugins/anaconda.pm | 43 ++++++++++----- xCAT-server/lib/xcat/plugins/geninitrd.pm | 4 ++ xCAT-server/lib/xcat/plugins/sles.pm | 67 +++++++++++++---------- 3 files changed, 71 insertions(+), 43 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index e836eed19..524c8bbad 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -2512,19 +2512,26 @@ sub insert_dd { } elsif ( grep (/LZMA compressed data/, @format)) { $initrdfmt = "lzma"; } else { - my $rsp; - push @{$rsp->{data}}, "Could not handle the format of the initrd."; - xCAT::MsgUtils->message("E", $rsp, $callback); - return (); + # check whether it can be handled by xz + $cmd = "xz -t $img"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) { + my $rsp; + push @{$rsp->{data}}, "Could not handle the format of the initrd."; + xCAT::MsgUtils->message("E", $rsp, $callback); + return (); + } else { + $initrdfmt = "lzma"; + } } if ($initrdfmt eq "gzip") { $cmd = "gunzip -c $img > $dd_dir/initrd"; } elsif ($initrdfmt eq "lzma") { - if (! -x "/usr/bin/lzma") { + if (! -x "/usr/bin/xz") { my $rsp; - push @{$rsp->{data}}, "The format of initrd for the target node is \'lzma\', but this management node has not lzma command."; + push @{$rsp->{data}}, "The format of initrd for the target node is \'lzma\', but this management node has not xz command."; xCAT::MsgUtils->message("E", $rsp, $callback); return (); } @@ -2698,7 +2705,7 @@ sub insert_dd { xCAT::Utils->runcmd($cmd, -1); if ($::RUNCMD_RC != 0) { my $rsp; - push @{$rsp->{data}}, "Handle the driver update failed. Could not generate the depdency for the drivers in the initrd."; + push @{$rsp->{data}}, "Handle the driver update failed. Could not generate the drivers depdency for $kernelver in the initrd."; xCAT::MsgUtils->message("I", $rsp, $callback); } } @@ -3004,7 +3011,7 @@ sub insert_dd { if ($initrdfmt eq "gzip") { $cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|gzip -9 -c - > $dd_dir/initrd.img"; } elsif ($initrdfmt eq "lzma") { - $cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|lzma -C crc32 -9 > $dd_dir/initrd.img"; + $cmd = "cd $dd_dir/initrd_img; find .|cpio -H newc -o|xz --format=lzma -C crc32 -9 > $dd_dir/initrd.img"; } xCAT::Utils->runcmd($cmd, -1); @@ -3072,13 +3079,23 @@ sub insert_dd { my $rsp; if (@dd_list) { - push @{$rsp->{data}}, "Inserted the driver update disk:".join(',',@inserted_dd)."."; + push @{$rsp->{data}}, "The driver update disk:".join(',',@inserted_dd)." have been injected to initrd."; } - if (@driver_list) { - push @{$rsp->{data}}, "Inserted the drivers:".join(',', sort(@rpm_drivers))." from driver packages."; - } elsif (@rpm_list && ($Injectalldriver || @driver_list)) { - push @{$rsp->{data}}, "Inserted the drivers from driver packages:".join(',', sort(@rpm_list))."."; + # remove the duplicated names + my %dnhash; + foreach (@rpm_drivers) { + $dnhash{$_} = 1; } + @rpm_drivers = keys %dnhash; + + if (@rpm_list) { + if (@driver_list) { + push @{$rsp->{data}}, "The drivers:".join(',', sort(@rpm_drivers))." from ".join(',', sort(@rpm_list))." have been injected to initrd."; + } elsif ($Injectalldriver) { + push @{$rsp->{data}}, "All the drivers from :".join(',', sort(@rpm_list))." have been injected to initrd."; + } + } + xCAT::MsgUtils->message("I", $rsp, $callback); return @inserted_dd; diff --git a/xCAT-server/lib/xcat/plugins/geninitrd.pm b/xCAT-server/lib/xcat/plugins/geninitrd.pm index ec13e052a..a364a6210 100644 --- a/xCAT-server/lib/xcat/plugins/geninitrd.pm +++ b/xCAT-server/lib/xcat/plugins/geninitrd.pm @@ -7,6 +7,7 @@ BEGIN use strict; use lib "$::XCATROOT/lib/perl"; +use File::Path; use File::Copy; use xCAT::MsgUtils; use xCAT::TableUtils; @@ -127,6 +128,9 @@ sub geninitrd { $tftpdir = $t_entry; } my $tftppath = "$tftpdir/xcat/osimage/$osimage"; + unless (-d $tftppath) { + mkpath $tftppath; + } if ($arch =~ /x86/) { if ($osvers =~ /(^ol[0-9].*)|(centos.*)|(rh.*)|(fedora.*)|(SL.*)/) { $kernelpath = "$tftppath/vmlinuz"; diff --git a/xCAT-server/lib/xcat/plugins/sles.pm b/xCAT-server/lib/xcat/plugins/sles.pm index 75d31229b..b2e9cf4c1 100644 --- a/xCAT-server/lib/xcat/plugins/sles.pm +++ b/xCAT-server/lib/xcat/plugins/sles.pm @@ -1802,9 +1802,9 @@ sub insert_dd () { } # get the new kernel if it exists in the update distro - my @new_kernels = <$dd_dir/rpm/boot/vmlinuz*>; + my @new_kernels = <$dd_dir/rpm/boot/vmlinu*>; foreach my $new_kernel (@new_kernels) { - if (-r $new_kernel && $new_kernel =~ /\/vmlinuz-(.*(x86_64|ppc64))$/) { + if (-r $new_kernel && $new_kernel =~ /\/vmlinu[zx]-(.*(x86_64|ppc64|default))$/) { $new_kernel_ver = $1; $cmd = "/bin/mv -f $new_kernel $dd_dir/rpm/newkernel"; xCAT::Utils->runcmd($cmd, -1); @@ -1928,34 +1928,32 @@ sub insert_dd () { } } } # end of loading drivers from rpm packages - } - # Create the dir for driver update disk - mkpath("$dd_dir/initrd_img/cus_driverdisk"); + # Create the dir for driver update disk + mkpath("$dd_dir/initrd_img/cus_driverdisk"); - # insert the driver update disk into the cus_driverdisk dir - foreach my $dd (@dd_list) { - copy($dd, "$dd_dir/initrd_img/cus_driverdisk"); - } + # insert the driver update disk into the cus_driverdisk dir + foreach my $dd (@dd_list) { + copy($dd, "$dd_dir/initrd_img/cus_driverdisk"); + } - # Repack the initrd - # In order to avoid the runcmd add the '2>&1' at end of the cpio - # cmd, the echo cmd is added at the end - $cmd = "cd $dd_dir/initrd_img; find . -print | cpio -H newc -o > $dd_dir/initrd | echo"; - xCAT::Utils->runcmd($cmd, -1); - if ($::RUNCMD_RC != 0) { - my $rsp; - push @{$rsp->{data}}, "Handle the driver update disk failed. Could not pack the hacked initrd."; - xCAT::MsgUtils->message("E", $rsp, $callback); - return (); - } + # Repack the initrd + # In order to avoid the runcmd add the '2>&1' at end of the cpio + # cmd, the echo cmd is added at the end + $cmd = "cd $dd_dir/initrd_img; find . -print | cpio -H newc -o > $dd_dir/initrd | echo"; + xCAT::Utils->runcmd($cmd, -1); + if ($::RUNCMD_RC != 0) { + my $rsp; + push @{$rsp->{data}}, "Handle the driver update disk failed. Could not pack the hacked initrd."; + xCAT::MsgUtils->message("E", $rsp, $callback); + return (); + } - # zip the initrd - #move ("$dd_dir/initrd.new", "$dd_dir/initrd"); - $cmd = "gzip -f $dd_dir/initrd"; - xCAT::Utils->runcmd($cmd, -1); + # zip the initrd + #move ("$dd_dir/initrd.new", "$dd_dir/initrd"); + $cmd = "gzip -f $dd_dir/initrd"; + xCAT::Utils->runcmd($cmd, -1); - if ($arch =~/ppc/ || (@rpm_list && ($Injectalldriver || @driver_list))) { if ($arch =~/ppc/) { if (-r "$dd_dir/rpm/newkernel") { # if there's new kernel from update distro, then use it @@ -1999,12 +1997,21 @@ sub insert_dd () { my $rsp; if (@dd_list) { - push @{$rsp->{data}}, "Inserted the driver update disk:".join(',', sort(@dd_list))."."; + push @{$rsp->{data}}, "The driver update disk:".join(',',@dd_list)." have been injected to initrd."; } - if (@driver_list) { - push @{$rsp->{data}}, "Inserted the drivers:".join(',', sort(@rpm_drivers))." from driver packages."; - } elsif (@rpm_list && ($Injectalldriver || @driver_list)) { - push @{$rsp->{data}}, "Inserted the drivers from driver packages:".join(',', sort(@rpm_list))."."; + # remove the duplicated names + my %dnhash; + foreach (@rpm_drivers) { + $dnhash{$_} = 1; + } + @rpm_drivers = keys %dnhash; + + if (@rpm_list) { + if (@driver_list) { + push @{$rsp->{data}}, "The drivers:".join(',', sort(@rpm_drivers))." from ".join(',', sort(@rpm_list))." have been injected to initrd."; + } elsif ($Injectalldriver) { + push @{$rsp->{data}}, "All the drivers from :".join(',', sort(@rpm_list))." have been injected to initrd."; + } } xCAT::MsgUtils->message("I", $rsp, $callback);