diff --git a/xCAT-client/pods/man1/imgcapture.1.pod b/xCAT-client/pods/man1/imgcapture.1.pod index 46d0cb4bd..067839f6a 100644 --- a/xCAT-client/pods/man1/imgcapture.1.pod +++ b/xCAT-client/pods/man1/imgcapture.1.pod @@ -1,6 +1,6 @@ =head1 NAME -B - Captures an image from one running diskful Linux node, prepares the rootimg directory, kernel and initial ramdisks for the B/B command to generate the statelite/stateless rootimg. +B - 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 />/netboot/>/>/>/rootimg directory. -After the B command returns without any errors, you can customize the rootimg and run the B/B command for your own request. +After the B command returns without any errors, you can customize the rootimg and run the B/B command with the options you want. =head1 OPTIONS -=over 12 +=over 4 =item B<-p|--profile> I @@ -82,15 +82,15 @@ B 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 as profile, run the command: - imgcapture node1 -p hpc +imgcapture node1 -p hpc 3. Create the image: its profile is B, and the network interface the diskless node will boot over is B, the driver modules for this network interface is B. - imgcapture node1 -p hpc -i eth0 -n e1000e +imgcapture node1 -p hpc -i eth0 -n e1000e =head1 FILES diff --git a/xCAT-server/lib/xcat/plugins/imgcapture.pm b/xCAT-server/lib/xcat/plugins/imgcapture.pm index 643dd4342..fdd048bf2 100644 --- a/xCAT-server/lib/xcat/plugins/imgcapture.pm +++ b/xCAT-server/lib/xcat/plugins/imgcapture.pm @@ -43,13 +43,14 @@ sub process_request { @ARGV = @{$request->{arg}} if (defined $request->{arg}); my $argc = scalar @ARGV; - my $usage = "Usage: imgcapture [-p | --profile ] [-i ] [-n ] [-V | --verbose] \n imgcapture [-h|--help] \n imgcapture [-v|--version]"; + my $usage = "Usage: imgcapture [-p | --profile ] [-o|--osimage ] [-i ] [-n ] [-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; } diff --git a/xCAT-server/share/xcat/netboot/rh/compute.imgcapture.exlist b/xCAT-server/share/xcat/netboot/rh/compute.imgcapture.exlist new file mode 100644 index 000000000..bba98b33c --- /dev/null +++ b/xCAT-server/share/xcat/netboot/rh/compute.imgcapture.exlist @@ -0,0 +1,6 @@ +./tmp* +./proc* +./dev* +./sys* +./install* +./xcatpost* diff --git a/xCAT-server/share/xcat/netboot/sles/compute.imgcapture.exlist b/xCAT-server/share/xcat/netboot/sles/compute.imgcapture.exlist new file mode 100644 index 000000000..bba98b33c --- /dev/null +++ b/xCAT-server/share/xcat/netboot/sles/compute.imgcapture.exlist @@ -0,0 +1,6 @@ +./tmp* +./proc* +./dev* +./sys* +./install* +./xcatpost*