[syslinux] Installing syslinux on a purely virtual disk

Richard W.M. Jones rjones at redhat.com
Tue Apr 23 03:21:45 PDT 2019


On Mon, Apr 22, 2019 at 06:26:43PM +0200, Sebastian Herbszt wrote:
> Richard W.M. Jones via Syslinux wrote:
> > I'm trying to add boot support to
> > https://github.com/libguestfs/nbdkit/tree/master/plugins/floppy
> >
> > This NBD server plugin generates a completely virtual FAT filesystem
> > and partition table.  Nothing is ever written to a file, and it must
> > run without anything needing to be root, loop mounting etc.  Running
> > "syslinux --install <something>" is a non-starter.
> >
> > So I've looked at how syslinux works and I see that it adds the files
> > LDLINUX.SYS and LDLINUX.C32 to the FAT filesystem -- I can easily
> > emulate this bit in the plugin since we are already creating a full
> > FAT32 filesystem on the fly.
> 
> How flexibel do you want this to be? Will users be allowed to supply
> their own SYSLINUX files or are those fixed and provided by "nbdkit"?

It has to be said I didn't think about this aspect.  On Linux
ldlinux.c32 is available in /usr/share/syslinux.

> > However the problem is that syslinux also creates a boot sector [ie.
> > core/bios/diskboot.inc in the syslinux source] and I suppose it must
> > encode the offset of the LDLINUX.SYS file.  I haven't quite worked out
> > the details.
> 
> Syslinux provides the following required files:
> 
> MBR - "mbr.bin" and "mbr_bin.c"
> boot sector - "ldlinux.bss" and "bootsect_bin.c"
> ldlinux - "ldlinux.sys" and "ldlinux_bin.c"
> ldlinux COM32 - "ldlinux.c32" and ldlinuxc32_bin.c
> 
> Those c files can be used in "virtual-floppy.c".
> 
> The installer "linux/syslinux.c" uses "libinstaller/syslxmod.c" to
> modify the content (boot sector and ldlinux).
> 
> > The question, is there a way to simulate the work that syslinux does
> > in a reasonably supportable way that won't break on future updates of
> > syslinux?
> >
> > Rich.
> >
> 
> The Sect1Ptr0_VAL and Sect1Ptr1_VAL magic values didn't change in
> almost a decade. So a simple search and replace approach should work
> for a while. On the other hand the required offsets are embedded in
> "ldlinux.sys" (Sect1Ptr0, Sect1Ptr1 with Sect1Ptr0Ptr and Sect1Ptr1Ptr
> in the extended patch area). Since "ldlinux.sys" requires patching
> anyway this approach should work even longer since it is also used by
> the installer itself.
> 
> If you want to use a fixed SYSLINUX version you can use pre-patched
> files. I tried that and got "ldlinux.sys" running but it failed to load
> ldlinux.c32.
> 
> I used "syslinux_mbr" in "create_mbr" and made the partition bootable.
> "create_partition_boot_sector" was modified to use "syslinux_bootsect"
> with Sect1Ptr0 = 0x80 and Sect1Ptr1 = 0. The value 0x80 was chosen
> because the plugin put the first file (ldlinux.sys) there.
> "ldlinux.sys" itself was pre-patched by the official installer.
> Therefore I created a compatible temporary file system with "mkfs.vfat
> -f 1 -F 32 -R 32 -s 32 -v".
> "ldlinux.c32" was copied to the directory to be also served by "nbdkit"
> but it didn't fully work. Hope this helps anyway.

Yes it's pretty helpful.  It does sound like I would end up with
something that depends a bit too much on internals of syslinux :-(

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html


More information about the Syslinux mailing list