#!/usr/bin/perl

my $root_part;
if($#ARGV != -1)
{
  $root_part = $ARGV[0];
}
else
{
  $root_part = `awk '{ if (\$2=="/") print \$1}' </etc/fstab`;
}
my $lilo_root_part;
foreach $item (split("\n", $root_part))
{
  if(not $item =~ /#/)
  {
    $lilo_root_part = $item;
  }
}
if($lilo_root_part =~ /\/dev\/md/)
{
  my $mdname = $lilo_root_part;
  $mdname =~ s/\/dev\///;
  $mdname =~ s/\///;
  my $md = `grep $mdname /proc/mdstat`;
  my @devices = split(" ", $md);
  @devices = sort(@devices[4..$#devices]);
  $lilo_root_part = "/dev/" . $devices[0];
  $lilo_root_part =~ s/\[.*$//;
}
my $lilo_root_disk = $lilo_root_part;
$lilo_root_disk =~ s/\d+$//;
$lilo_root_disk =~ s/part$/disc/;

print $lilo_root_disk . "\n";
