setup_harddisks2 patch

Paul Lussier p.lussier at comcast.net
Mon Feb 5 17:48:19 CET 2007


Hi all,

I've been playing around with setting up raid using FAI (v. 2.8.4)
with the setup_harddisks 2 script from:

   http://faiwiki.informatik.uni-koeln.de/index.php/Setup_harddisks_2

in which I've found a bug where sfdisk bails out immediately upon not
being able to query a non-existant drive.  On line 480 of
setup_harddisks is the following line:

    $result = `sh -c "LC_ALL=C sfdisk /dev/sd[a-z] /dev/hd[a-z] -g -q" 2>&1`;

If this is run on a system with *only* IDE PATA drives, which use
the /dev/hdX nomenclature, sfdisk will fail to return a list of
drives in the system because it first fails when it encounters a
lack of /dev/sdX drives.

Similarly, the command will bail out whenever it encounters a device
file for which there is no actuall corresponding device.

Here's a patch which solves the problem:

  # diff setup_harddisks~ setup_harddisks
  472a473,480
  > sub findDisks {
  >   my @stdout = split(/\n/,`sfdisk -s`);
  >   my @disks = grep { !/md/ } @stdout;
  >   @disks = sort grep(/dev/, at disks);
  >   map { s/(.*):.*/$1/ } @disks;
  >   wantarray ? return @disks : return \@disks;
  > }
  > 
  475c483,488
  <     my $line=""; my $disk=""; my $device=""; my $rest; my $result; my $divi;
  ---
  >     my $line  ="";
  >     my $disk  ="";
  >     my $device        ="";
  >     my $rest;
  >     my $result;
  >     my $divi;
  480c493,506
  <     $result = `sh -c "LC_ALL=C sfdisk /dev/sd[a-z] /dev/hd[a-z] -g -q" 2>&1`;
  ---
  >     my @drives = findDisks();
  >     my @driveGeometries;
  >     my @drivePartitions;
  > 
  >     foreach my $hardDriveFound (@drives) {
  >       push(@driveGeometries,
  >          `sh -c "LC_ALL=C sfdisk $hardDriveFound -g -q" 2>&1`,
  >         );
  >       push(@drivePartitions,
  >          `sh -c "LC_ALL=C sfdisk -d -q $hardDriveFound" 2>&1`
  >         );
  >     }
  >     chomp(@driveGeometries);
  >     chomp(@drivePartitions);
  482c508
  <     foreach my $line(split(/\n/,$result)){
  ---
  >     foreach my $line (@driveGeometries) {
  504,505d529
  <     $result = `sh -c "LC_ALL=C sfdisk -d -q /dev/sd[a-z] /dev/hd[a-z] " 2>&1`;
  < 
  508c532
  <     foreach my $line(split(/\n/,$result)){
  ---
  >     foreach my $line (@drivePartitions){
  554d577
  < 

The key is not to query every possible drive in the system and depend
upon sfdisk dying (possibly prematurely), but rather, to first ask
sfdisk which drives it knows about, and query only those drives.

I hope this helps someone.
-- 
Seeya,
Paul
--
Key fingerprint = 1660 FECC 5D21 D286 F853  E808 BB07 9239 53F1 28EE

A: Yes.                                                               
> Q: Are you sure?                                                    
>> A: Because it reverses the logical flow of conversation.           
>>> Q: Why is top posting annoying in email?



More information about the linux-fai-devel mailing list