File: device2grub

package info (click to toggle)
fai 2.8.4sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,284 kB
  • ctags: 176
  • sloc: sh: 3,362; perl: 1,591; makefile: 142
file content (35 lines) | stat: -rwxr-xr-x 748 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /usr/bin/perl
# copyright Thomas Lange 2001, lange@debian.org
# map "normal" device notation to grub notation

# TODO: read from stdin if no parameter given

use strict;
my $grubdevice;
my %map;

my $device=shift;
my $devicemap="$ENV{target}/boot/grub/device.map";

open (DEVICEMAP,"<$devicemap") || die "Can't open $devicemap\n";
while (<DEVICEMAP>) {
  my ($grubdevice,$olddevice) = split;
  $map{$olddevice} = $grubdevice;
}

$device=~ m#^(/dev/[sh]d\D)(\d*)$# || die "Can't match device: $device\n";
my ($disk,$partition) = ($1,$2);

if ($map{$disk}) {
  $grubdevice=$map{$disk};
} else {
  die "No match in $devicemap for $disk\n"; 
}

if ($partition) {
  $partition--;
  $grubdevice=~s/\)/,$partition\)/;
}

print "$grubdevice\n";
exit 0;