Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Convert syslinux (isolinux) config to grub-legacy config

by ambrus (Abbot)
on Sep 27, 2011 at 15:21 UTC ( #928102=CUFP: print w/ replies, xml ) Need Help??

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.

Comment on Convert syslinux (isolinux) config to grub-legacy config
Select or Download Code
Re: Convert syslinux (isolinux) config to grub-legacy config
by zentara (Archbishop) on Sep 27, 2011 at 16:17 UTC

      As you can see, the problem with isolinux config files is that it has the name of the initrd file among the kernel parameters, despite that it's obviously not a kernel parameter but something the bootloader must handle. As both GRUB-l and LILO (and also GRUB1) handles initrd as a separate configuration option, modifying my script could be a good start if you wanted to convert an isolinux config file to a LILO config file. (Incidentally, loadlin also has the initrd among kernel parameters, but that's only because loadlin receives all the configuration in a single line and all but three kind of them are used directly as kernel parameters.)

Reaped: Re: Convert syslinux (isolinux) config to grub-legacy config
by NodeReaper (Curate) on Sep 28, 2011 at 12:54 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://928102]
Approved by ww
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2014-12-26 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls