added two .imgcapture.exlist files for rh/sles;

updated the manpage of "imgcapture";
improved the output of "imgcapture";
added one option to "imgcapture" to support imgname;

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9113 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
mxi1 2011-03-21 06:31:21 +00:00
parent bec3dc5f51
commit 05882d7e80
4 changed files with 100 additions and 13 deletions

View File

@ -1,6 +1,6 @@
=head1 NAME
B<imgcapture> - Captures an image from one running diskful Linux node, prepares the rootimg directory, kernel and initial ramdisks for the B<liteimg>/B<packimage> command to generate the statelite/stateless rootimg.
B<imgcapture> - Captures an image from a Linux diskful node and create a diskless image on the management node.
=head1 SYNOPSIS
@ -20,11 +20,11 @@ The default files/directories excluded in the image are specified by /opt/xcat/s
The image captured will be extracted into the /<I<installroot>>/netboot/<B<osver>>/<B<arch>>/<B<profile>>/rootimg directory.
After the B<imgcapture> command returns without any errors, you can customize the rootimg and run the B<liteimg>/B<packimage> command for your own request.
After the B<imgcapture> command returns without any errors, you can customize the rootimg and run the B<liteimg>/B<packimage> command with the options you want.
=head1 OPTIONS
=over 12
=over 4
=item B<-p|--profile> I<profile>
@ -82,15 +82,15 @@ B<node1> is one diskful Linux node, which is managed by xCAT.
1. In order to create the image, run the following command:
imgcapture node1
imgcapture node1
2. In order to create the image with B<hpc> as profile, run the command:
imgcapture node1 -p hpc
imgcapture node1 -p hpc
3. Create the image: its profile is B<hpc>, and the network interface the diskless node will boot over is B<eth0>, the driver modules for this network interface is B<e1000e>.
imgcapture node1 -p hpc -i eth0 -n e1000e
imgcapture node1 -p hpc -i eth0 -n e1000e
=head1 FILES

View File

@ -43,13 +43,14 @@ sub process_request {
@ARGV = @{$request->{arg}} if (defined $request->{arg});
my $argc = scalar @ARGV;
my $usage = "Usage: imgcapture <node> [-p | --profile <profile>] [-i <nodebootif>] [-n <nodenetdrivers>] [-V | --verbose] \n imgcapture [-h|--help] \n imgcapture [-v|--version]";
my $usage = "Usage: imgcapture <node> [-p | --profile <profile>] [-o|--osimage <osimage>] [-i <nodebootif>] [-n <nodenetdrivers>] [-V | --verbose] \n imgcapture [-h|--help] \n imgcapture [-v|--version]";
my $os;
my $arch;
my $profile;
my $bootif;
my $netdriver;
my $osimg;
my $help;
my $version;
@ -57,6 +58,7 @@ sub process_request {
"profile|p=s" => \$profile,
"i=s" => \$bootif,
'n=s' => \$netdriver,
'osimage|o=s' => \$osimg,
"help|h" => \$help,
"version|v" => \$version,
"verbose|V" => \$verbose
@ -91,12 +93,57 @@ sub process_request {
unless($profile) {
$profile = $ref_nodetype->{profile};
}
# check whether the osimage exists or not
if($osimg) {
my $osimgtab=xCAT::Table->new('osimage', -create=>1);
unless($osimgtab) {
# the osimage table doesn't exist
my $rsp = {};
$rsp->{data}->[0] = qq{Cannot open the osimage table};
$xCAT::MsgUtils->message("E", $rsp, $callback);
return;
}
my $linuximgtab = xCAT::Table->new('linuximage', -create=>1);
unless($linuximgtab) {
# the linuximage table doesn't exist
my $rsp = {};
$rsp->{data}->[0] = qq{Cannot open the linuximage table};
$xCAT::MsgUtils->message("E", $rsp, $callback);
return;
}
my ($ref) = $osimgtab->getAttribs({imagename => $osimg}, 'osvers', 'osarch', 'profile');
unless($ref) {
my $rsp = {};
$rsp->{data}->[0] = qq{Cannot find $osimg from the osimage table.};
xCAT::MsgUtils->message("E", $rsp, $callback);
return;
}
my ($ref1) = $linuximgtab->getAttribs({imagename => $osimg}, 'comments');
unless($ref1) {
my $rsp = {};
$rsp->{data}->[0] = qq{Cannot find $osimg from the linuximage table};
xCAT::MsgUtils->message("E", $rsp, $callback);
return;
}
# make sure the "osvers" and "osarch" attributes match the node's attribute
unless($os eq $ref->{'osvers'} and $arch eq $ref->{'osarch'}) {
my $rsp = {};
$rsp->{data}->[0] = qq{The 'osvers' or 'osarch' attribute of the "$osimg" table doesn't match the node's attribute};
xCAT::MsgUtils->message("E", $rsp, $callback);
return;
}
}
imgcapture($node, $os, $arch, $profile, $bootif, $netdriver, $callback, $doreq);
imgcapture($node, $os, $arch, $profile, $osimg, $bootif, $netdriver, $callback, $doreq);
}
sub imgcapture {
my ($node, $os, $arch, $profile, $bootif, $netdriver, $callback, $subreq) = @_;
my ($node, $os, $arch, $profile, $osimg, $bootif, $netdriver, $callback, $subreq) = @_;
if($verbose) {
my $rsp = {};
$rsp->{data}->[0] = "nodename is $node; os is $os; arch is $arch; profile is $profile";
@ -164,6 +211,7 @@ sub imgcapture {
while(<$exlist>) {
$_ =~ s/^\s+//;
chomp $_;
unless($_ =~ m{^#}) {
$excludestr .= qq{ ! -path "$_"};
}
@ -172,7 +220,7 @@ sub imgcapture {
close $exlist;
} else {
# the following directories must be exluded when capturing the image
my @default_exlist = ("./tmp*", "./proc*", "./sys*", "./dev*", "./xcatpost*", "./install*");
my @default_exlist = ("./tmp/", "./proc/", "./sys/", "./dev/", "./xcatpost/", "./install/");
foreach my $item (@default_exlist) {
$excludestr .= qq{ ! -path "$item"};
}
@ -201,13 +249,18 @@ sub imgcapture {
return;
}
xCAT::Utils->runxcmd({command => ["xdsh"], node => [$node], arg => [$excludestr]}, $subreq, -1, 1);
my $rsp = {};
$rsp->{data}->[0] = qq{Capturing image on $node...};
xCAT::MsgUtils->message("D", $rsp, $callback);
if($verbose) {
my $rsp = {};
$rsp->{data}->[0] = qq{running "$excludestr" on $node via the "xdsh" command};
xCAT::MsgUtils->message("D", $rsp, $callback);
}
xCAT::Utils->runxcmd({command => ["xdsh"], node => [$node], arg => [$excludestr]}, $subreq, -1, 1);
if($::RUNCMD_RC) { # the xdsh command fails
my $rsp = {};
$rsp->{data}->[0] = qq{The "xdsh" command fails to run "$excludestr" on $node};
@ -215,6 +268,10 @@ sub imgcapture {
return;
}
$rsp = {};
$rsp->{data}->[0] = qq{Transfering the image captured on $node back...};
xCAT::MsgUtils->message("D", $rsp, $callback);
# copy the image captured on $node back via the "scp" command
xCAT::Utils->runcmd("scp $node:$xcat_imgcapture_tmpfile $xcat_imgcapture_tmpfile");
if($verbose) {
@ -230,6 +287,8 @@ sub imgcapture {
return;
}
xCAT::Utils->runxcmd({command => ["xdsh" ], node => [$node], arg => ["rm -f $xcat_imgcapture_tmpfile"]}, $subreq, -1, 1);
# extract the $xcat_imgcapture_tmpfile file to /install/netboot/$os/$arch/$profile/rootimg
my $rootimgdir = "$installroot/netboot/$os/$arch/$profile/rootimg";
@ -276,16 +335,25 @@ sub imgcapture {
# the next step is to call "genimage"
my $platform = getplatform($os);
if( -e "$::XCATROOT/share/xcat/netboot/$platform/genimage" ) {
my $cmd = "$::XCATROOT/share/xcat/netboot/$platform/genimage -o $os -a $arch -p $profile ";
my $cmd;
if( $osimg ) {
$cmd = "$::XCATROOT/share/xcat/netboot/$platform/genimage $osimg";
} else {
$cmd = "$::XCATROOT/share/xcat/netboot/$platform/genimage -o $os -a $arch -p $profile ";
}
if($bootif) {
$cmd .= "-i $bootif ";
}
if($netdriver) {
$cmd .= "-n $netdriver";
}
my $rsp = {};
$rsp->{data}->[0] = qq{Generating kernel and initial ramdisks};
$rsp->{data}->[0] = qq{Generating kernel and initial ramdisks...};
xCAT::MsgUtils->message("D", $rsp, $callback);
if($verbose) {
my $rsp = {};
$rsp->{data}->[0] = qq{"The genimage command is: $cmd"};
@ -298,6 +366,13 @@ sub imgcapture {
xCAT::MsgUtils->message("E", $rsp, $callback);
return;
}
my $rsp = {};
$rsp->{data}->[0] = qq{"Done."};
xCAT::MsgUtils->message("D", $rsp, $callback);
unlink $xcat_imgcapture_tmpfile;
return 0;
}

View File

@ -0,0 +1,6 @@
./tmp*
./proc*
./dev*
./sys*
./install*
./xcatpost*

View File

@ -0,0 +1,6 @@
./tmp*
./proc*
./dev*
./sys*
./install*
./xcatpost*