This program helps you convert between boot loaders. It reads a configuration file for syslinux (or isolinux) and outputs a configuration file for grub-legacy (GRUB with version number less than 1, such as GRUB 0.97).
The conversion is not automatic. You will still have to edit the resulting output manually. This also means you have to understand how the grub-legacy boot loader works.
This program will not follow include or config commands, so if you have multiple syslinux config files, you may want to concatenate them before passing to this program.
In fact, we don't implement most of the syslinux commands, but pass unknown commands through verbatim. Commands the program knows about are: label, menu label, kernel, append.
Source code follows.
#!perl
# sysl2grub.pl -- Convert syslinux config file to grub-l config file.
# This tool attempts to convert syslinux (isolinux etc) config file to
+
# grub-l config file. The conversion is not fully automated, you need
# to edit the resulting file afterwards. In particular, you may want
# to add a "default" and "timeout" declaration.
# I use this on Debian live disks.
use warnings; use 5.010; use strict;
no warnings "uninitialized";
our %r;
sub out {
if (my $l = delete $r{label}) {
print $l;
} elsif ($r{id}) {
warn "warning: missing menu title, inventing one";
print "title $r{id}\n";
}
if (my $i = delete $r{id}) {
print "# syslinux label $i\n";
}
print delete $r{early};
if (my $k = delete $r{kernel}) {
print $k . delete($r{append}) . "\n";
}
print delete $r{initrd};
print delete $r{other};
if (%r) {
warn "internal warning: unused fields (" . join(" ", keys %r)
+. ")";
}
}
while (<>) {
if (/^\s*label\s+(.*)/i) {
out();
%r = ();
$r{id} = $1;
} elsif (/^\s*menu\s+label\s+(.*)/i) {
$r{label} and warn "warning: second menu label line, ignoring
+first ($r{id}) ($r{label})";
$r{label} = "title $1\n";
} elsif (/^\s*(kernel\s+.*)/i) {
$r{kernel} and warn "warning: second kernel line, ignoring fir
+st ($r{id}) ($r{kernel})";
$r{kernel} = $1;
} elsif (/^\s*append(\s+.*)/i) {
my $a = $1;
while ($a =~ s/\sinitrd=(\S+)//) {
$r{initrd} and warn "warning: second initrd param, ignorin
+g first ($r{id}) ($r{initrd})";
$r{initrd} = "initrd $1\n";
}
$r{append} .= $a;
} else {
($r{kernel} ? $r{other} : $r{early}) .= $_;
}
}
eof or warn "warning: error reading input file: $!";
out();
__END__
Example input follows (taken from a Debian boot disk).
label live
menu label Live
kernel /live/vmlinuz
append initrd=/live/initrd.img boot=live config quiet
label livefailsafe
menu label Live (failsafe)
kernel /live/vmlinuz
append initrd=/live/initrd.img boot=live config noapic noapm nod
+ma nomce nolapic nomodeset nosmp vga=normal
label live-686
menu label Live 686
kernel /live/vmlinuz2
append initrd=/live/initrd2.img boot=live config quiet
label live-686failsafe
menu label Live 686 (failsafe)
kernel /live/vmlinuz2
append initrd=/live/initrd2.img boot=live config noapic noapm no
+dma nomce nolapic nomodeset nosmp vga=normal
label install
menu label Text Install
kernel /install/vmlinuz
append initrd=/install/initrd.gz vga=normal quiet
label expert
menu label Text Expert
kernel /install/vmlinuz
append initrd=/install/initrd.gz priority=low vga=normal
label rescue
menu label Text Rescue
kernel /install/vmlinuz
append initrd=/install/initrd.gz rescue/enable=true vga=normal qui
+et
label auto
menu label Text Auto
kernel /install/vmlinuz
append initrd=/install/initrd.gz auto=true priority=critical vga=n
+ormal quiet
label installgui
menu label GUI Install
kernel /install/gtk/vmlinuz
append initrd=/install/gtk/initrd.gz video=vesa:ywrap,mtrr vga=788
+ quiet
label expertgui
menu label GUI Expert
kernel /install/gtk/vmlinuz
append initrd=/install/gtk/initrd.gz priority=low video=vesa:ywrap
+,mtrr vga=788
label rescuegui
menu label GUI Rescue
kernel /install/gtk/vmlinuz
append initrd=/install/gtk/initrd.gz rescue/enable=true video=vesa
+:ywrap,mtrr vga=788 quiet
label autogui
menu label GUI Auto
kernel /install/gtk/vmlinuz
append initrd=/install/gtk/initrd.gz auto=true priority=critical v
+ideo=vesa:ywrap,mtrr vga=788 quiet
label memtest
menu label Memory test
kernel /live/memtest
Example output generated from above input follows.
title Live
# syslinux label live
kernel /live/vmlinuz boot=live config quiet
initrd /live/initrd.img
title Live (failsafe)
# syslinux label livefailsafe
kernel /live/vmlinuz boot=live config noapic noapm nodma nomce nolap
+ic nomodeset nosmp vga=normal
initrd /live/initrd.img
title Live 686
# syslinux label live-686
kernel /live/vmlinuz2 boot=live config quiet
initrd /live/initrd2.img
title Live 686 (failsafe)
# syslinux label live-686failsafe
kernel /live/vmlinuz2 boot=live config noapic noapm nodma nomce nola
+pic nomodeset nosmp vga=normal
initrd /live/initrd2.img
title Text Install
# syslinux label install
kernel /install/vmlinuz vga=normal quiet
initrd /install/initrd.gz
title Text Expert
# syslinux label expert
kernel /install/vmlinuz priority=low vga=normal
initrd /install/initrd.gz
title Text Rescue
# syslinux label rescue
kernel /install/vmlinuz rescue/enable=true vga=normal quiet
initrd /install/initrd.gz
title Text Auto
# syslinux label auto
kernel /install/vmlinuz auto=true priority=critical vga=normal quiet
initrd /install/initrd.gz
title GUI Install
# syslinux label installgui
kernel /install/gtk/vmlinuz video=vesa:ywrap,mtrr vga=788 quiet
initrd /install/gtk/initrd.gz
title GUI Expert
# syslinux label expertgui
kernel /install/gtk/vmlinuz priority=low video=vesa:ywrap,mtrr vga=788
+
initrd /install/gtk/initrd.gz
title GUI Rescue
# syslinux label rescuegui
kernel /install/gtk/vmlinuz rescue/enable=true video=vesa:ywrap,mtrr v
+ga=788 quiet
initrd /install/gtk/initrd.gz
title GUI Auto
# syslinux label autogui
kernel /install/gtk/vmlinuz auto=true priority=critical video=vesa:ywr
+ap,mtrr vga=788 quiet
initrd /install/gtk/initrd.gz
title Memory test
# syslinux label memtest
kernel /live/memtest
#label floppy
# localboot 0x00
#label disk1
# localboot 0x80
#label disk2
# localboot 0x81
#label nextboot
# localboot -1
Update 2011-12-18: in case you want a grub-l to grub2 converter, the Debian installer has one, so look there.