Richard W.M. Jones
2019-Apr-18 20:07 UTC
[syslinux] Installing syslinux on a purely virtual disk
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. 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. 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. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
> > 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. > > 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. > > 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.Under Linux, SYSLINUX (for BIOS) can be installed by means of alternative official installers: _ extlinux acts on a mounted filesystem; _ syslinux-nomtools requires root privileges; _ syslinux (using mtools) depends on mtools (which also means it depends on its quirks too) but it doesn't require root privileges. See www.syslinux.org/wiki/index.php/Install . Alternatively, SYSLINUX could be installed be means of unofficial methods. One example is RUFUS; although it is a program working under Windows (not Linux), it is open source and it uses its own way of installing SYSLINUX (different than the way the upstream official installers do it, and independently of the specific version of SYSLINUX). One potentially-relevant note: the Linux-based tool "ms-sys" (version 2.6.0 recently released, https://sf.net/p/ms-sys ) can be used to install SYSLINUX boot code (among several others). Whether any of the above is of any actual help for your case/conditions, I don't know, but perhaps they might be some kind of starting point for your own method. If you come up with some alternative way, please let us (members of the Syslinux mailing list) know. HTH, Ady.
Dany St-Amant
2019-Apr-19 16:10 UTC
[syslinux] Installing syslinux on a purely virtual disk
Interesting challenge. The floppy plugin limitations don't seem to play nice with syslinux normal installation and loading - no write support - no MBR code, no VBR code - cluster/LBA location not fixed (will change if files added to source location) - no dynamic refresh of added file at source location Here floppy seems to be a misnomer as floppy do not have partition table, it's more a 'single FAT partition hard disk' plugin. The location of the first sector of ldlinux.sys must be known to the VBR, and the location of remaining ldlinux.sys sectors must be known to ldlinux.sys. (Note that ldlinux.sys also contains another modifiable section.) If I were you, I'd explore using the "wasted" sectors between the MBR and VBR (sector 1 to 2047), to make ldlinux.sys available through a fixed location in that area (either as a real region or as a remapping toward the file ldlinux.sys). Such fixed location has the advantage of not requiring the floppy plugin to know about the internals of syslinux. By modifying/cloning linux/syslinux.c, one could easily get a 'fixlinux --at 1024' to produce a virtual VBR and ldlinux.sys which can then then be used by the floppy plugin to provide the VBR (sector 2048 aka floppy->bootsect) and data for read issued at sector 1024+ for ldlinux.sys. If this new 'fixlinux' output to stdout a concat of the VBR (always 512 bytes) and ldlinux.sys, the floppy plugin could dynamically create the proper information without the need of intermediary files. Disclaimer: I am not one of the main syslinux developer, so my understanding of its behaviour might be flawed. Regards, Dany> Le 18 avr. 2019 ? 16:07, Richard W.M. Jones via Syslinux <syslinux at syslinux.org> a ?crit : > > > 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. > > 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. > > 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. > > -- > Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones > Read my programming and virtualization blog: http://rwmj.wordpress.com > virt-df lists disk usage of guests without needing to install any > software inside the virtual machine. Supports Linux and Windows. > http://people.redhat.com/~rjones/virt-df/ > _______________________________________________ > Syslinux mailing list > Submissions to Syslinux at syslinux.org > Unsubscribe or set options at: > https://lists.syslinux.org/syslinux
Sebastian Herbszt
2019-Apr-22 16:26 UTC
[syslinux] Installing syslinux on a purely virtual disk
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"?> 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. Sebastian
Richard W.M. Jones
2019-Apr-23 10:21 UTC
[syslinux] Installing syslinux on a purely virtual disk
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