Enhanced config.c32 (econfig.c32) and whichsys.c32

Post your suggestions here if there are new features or applications that you would like added to the Ultimate Boot CD.

Moderators: Icecube, StopSpazzing

Post Reply
Message
Author
Icecube
Posts: 1278
Joined: Fri Jan 11, 2008 2:52 pm
Contact:

Enhanced config.c32 (econfig.c32) and whichsys.c32

#1 Post by Icecube » Tue Mar 31, 2009 6:38 am

I have written (together with Erwan Velu, developer of the Hardware Detection Tool) an enhanced config.c32 (econfig.c32) module for syslinux/isolinux.

It can load a different config file, depending if a menu entry is booted from isolinux or syslinux.

My post on the syslinux mailing list (Changed a bit, (renamed config.c32 to econfig.c32)):

Code: Select all

For UBCD, we have a lot of config files.

Isolinux will load /boot/isolinux/isolinux.cfg, which will load /ubcd/menus/isolinux/main.cfg
Syslinux will load /boot/syslinux/syslinux.cfg, which will load /ubcd/menus/syslinux/main.cfg

The /ubcd/menus/syslinux/main.cfg loads several other config files when you select the appropriate menu.
From all those menus you can go back to  /ubcd/menus/syslinux/main.cfg.

The  /ubcd/menus/syslinux/main.cfg needs to be different for isolinux and syslinux:
- 'localboot -1' doesn't work with syslinux
- The contents for the config files for booting certain linux distro's differ when you run them from CD (isolinux)
  or from USB/HDD (syslinux)

To make this work, I did need to put the specific main.cfg (adapted for isolinux and syslinux in respectively,
/boot/isolinux or /boot/syslinux, but this is quite ugly because all other config files are in /ubcd/menus/syslinux/ 
(19 config files).


With a lot of help of Erwan Velu, I have now a com32 module that loads a config file depending on the running
syslinux variant. It is based on the config.c32 module.

  Usage: econfig.c32 <filename>
         econfig.c32 ext=<filename> iso=<filename> pxe=<filename> sys=<filename>


It supports the current style of loading a new config file:

  econfig.c32 another.cfg


And it support the "bootloader variant dependend" loading of a config:

  econfig.c32 iso=file1.cfg sys=file2.cfg

  This will load file1.cfg file, when this command is run from isolinux.
  It will load file2.cfg, when run from syslinux.


Now I can use it in UBCD a different config file for the "main.cfg" file (/ubcd/menus/mainiso.cfg or /ubcd/menus/mainsys.cfg):

/boot/isolinux/isolinux.cfg:
==================================
DEFAULT main 
 
LABEL main 
COM32 /boot/syslinux/menu.c32 
APPEND /ubcd/menus/isolinux/main.cfg
==================================

/boot/syslinux/syslinux.cfg:
==================================
DEFAULT main 
 
LABEL main 
COM32 /boot/syslinux/menu.c32 
APPEND /ubcd/menus/syslinux/main.cfg
==================================


In a entry (e.g..: in '/boot/menus/syslinux/bios.cfg') that does need to go back to the 'main.cfg' file
(/ubcd/menus/mainiso.cfg or /ubcd/menus/mainsys.cfg), I can use now:

========================================================================
LABEL - 
MENU LABEL .. 
COM32 /boot/syslinux/config.c32 
APPEND iso=/ubcd/menus/isolinux/main.cfg sys=/ubcd/menus/syslinux/main.cfg
========================================================================


Gert Hulselmans




Probably it won't be that useful for other people, but just in case someone else needs this functionality:

/* ----------------------------------------------------------------------- *
 *
 *   Copyright 2009 H. Peter Anvin - All Rights Reserved
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 *   Boston MA 02110-1301, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

/*
 * econfig.c
 *
 * Loads a new configuration file
 *
 * Usage: econfig.c32 <filename>
 *        econfig.c32 ext=<filename> iso=<filename> pxe=<filename> sys=<filename>
 *
 * Examples:
 *
 * - The following will load the config file 'another.cfg':
 *
 *     econfig.c32 another.cfg
 *
 * - The following will load 'file1.cfg' when you run it from isolinux,
 *   and it will load 'file2.cfg' when you run it from syslinux.
 *
 *     econfig.c32 iso=file1.cfg sys=file2.cfg
 *
 */

#include <stdio.h>
#include <console.h>
#include <string.h>
#include <stdbool.h>
#include <syslinux/boot.h>
#include "syslinux/config.h"

char bootlinux[255];
char extlinux[255];
char isolinux[255];
char pxelinux[255];
char syslinux[255];
bool extlinux_param;
bool isolinux_param;
bool pxelinux_param;
bool syslinux_param;
const struct syslinux_version *sv;

/*
 * Detect which variant of syslinux is running.
 */
int detect_syslinux()
{
  sv = syslinux_version();
  switch (sv->filesystem) {
    case SYSLINUX_FS_EXTLINUX:
    strncpy(bootlinux,extlinux,sizeof(bootlinux));
    extlinux_param=true;
      break;
    case SYSLINUX_FS_ISOLINUX:
    strncpy(bootlinux,isolinux,sizeof(bootlinux));
    isolinux_param=true;
      break;
    case SYSLINUX_FS_PXELINUX:
    strncpy(bootlinux,pxelinux,sizeof(bootlinux));
    pxelinux_param=true;
      break;
    case SYSLINUX_FS_SYSLINUX:
    strncpy(bootlinux,syslinux,sizeof(bootlinux));
    syslinux_param=true;
      break;
    case SYSLINUX_FS_UNKNOWN:
    default:
      return 1;
  }
return 0;
}

/*
 * Detect which parameters are passed to our module and store them.
 */
void detect_parameters(const int argc, const char *argv[])
{
  for (int i = 1; i < argc; i++) {
    if (strncmp(argv[i], "ext=", 4) == 0) {
        strncpy(extlinux, argv[i] + 4, sizeof(extlinux));
    } else if (strncmp(argv[i], "iso=", 4) == 0) {
        strncpy(isolinux, argv[i] + 4, sizeof(isolinux));
    } else if (strncmp(argv[i], "pxe=", 4) == 0) {
        strncpy(pxelinux, argv[i] + 4, sizeof(pxelinux));
    } else if (strncmp(argv[i], "sys=", 4) == 0) {
        strncpy(syslinux, argv[i] + 4, sizeof(syslinux));
    } else if (argc == 2) {
        strncpy(extlinux, argv[1], sizeof(extlinux));
        strncpy(isolinux, argv[1], sizeof(isolinux));
        strncpy(pxelinux, argv[1], sizeof(pxelinux));
        strncpy(syslinux, argv[1], sizeof(syslinux));
    }
  }
}

void init_structs() {
  memset(bootlinux,0,sizeof(bootlinux));
  memset(extlinux,0,sizeof(extlinux));
  memset(isolinux,0,sizeof(isolinux));
  memset(pxelinux,0,sizeof(pxelinux));
  memset(syslinux,0,sizeof(syslinux));

  extlinux_param=false;
  pxelinux_param=false;
  isolinux_param=false;
  syslinux_param=false;
}

void show_usage() {
  fprintf(stderr, "Usage: econfig.c32 <filename>\n");
  fprintf(stderr, "       econfig.c32 ext=<filename> iso=<filename> pxe=<filename> sys=<filename> \n");
}

int main(int argc, const char *argv[])
{
  openconsole(&dev_null_r, &dev_stdcon_w);

  if (argc < 2) {
    fprintf(stderr, "No config file specified.\n\n");
    show_usage();
    return 1;
  }

  init_structs();
  detect_parameters(argc,argv);
  if (detect_syslinux() == 1) {
    fprintf(stderr, "No valid bootloader found..\n\n");
    show_usage();
    return 1;
  }

  if (strlen(bootlinux) > 0 ) {
    syslinux_run_kernel_image(bootlinux, "", 0, IMAGE_TYPE_CONFIG);
    fprintf(stderr, "econfig.c32: failed to load '%s' (missing file?).\n\n", bootlinux);
    show_usage();
    return 1;
  } else if (extlinux_param | isolinux_param | pxelinux_param | syslinux_param) {
    fprintf(stderr, "No config file specified for the current bootloader.\n\n");
    show_usage();
    return 1;
  }

  return 0;
}
You can download the sourcecode and the compiled version from: http://ubcd.partedmagic.com/downloads/e ... config.zip

@ Victor:
Can you send me all the current config files for the next beta of UBCD50 so I can adapt them at the right place.

We can use it for making to different main.cfg files: mainiso.cfg and mainsys.cfg.

'localboot -1' does only work with isolinux
For syslinux we need to use:

Code: Select all

COM32 /boot/syslinux/chain.c32
APPEND hd1 swap
The bug in the Hardware Detection Tool (didn't run with syslinux, but did run with isolinux on my PC) is solved. And the working version will be included in syslinux 3.74.
It is a very nice program and it works great.
http://syslinux.zytor.com/wiki/index.ph ... on_Tool%29
Last edited by Icecube on Wed Jul 08, 2009 1:51 am, edited 1 time in total.
Download Ultimate Boot CD v5.0: http://www.ultimatebootcd.com/download.html
Use Parted Magic for handling all partitioning task: http://partedmagic.com/

Victor Chew
Posts: 1359
Joined: Mon Feb 21, 2005 10:59 pm
Contact:

#2 Post by Victor Chew » Thu Apr 02, 2009 6:09 pm

Can you send me all the current config files for the next beta of UBCD50 so I can adapt them at the right place.
It's probably easier if you give me a list of the parts that need to be changed, since I am in the midst of updating for b13.

Thanks!

Icecube
Posts: 1278
Joined: Fri Jan 11, 2008 2:52 pm
Contact:

Re: Enhanced config.c32 (econfig.c32) and whichsys.c32

#3 Post by Icecube » Mon Jul 05, 2010 2:51 pm

I wrote another module whichsys.c32, which is much better.
It doesn't accept another configfile (at least not directly), but it accepts labels and commands.

Code: Select all

Detemine which command to execute, based on the Syslinux bootloader variant
from which you run it.

  Usage:    whichsys.c32 [-iso- command] [-pxe- command] [-sys- command]
  Examples: whichsys.c32 -iso- chain.c32 hd0 -sys- chain.c32 hd1 swap
            whichsys.c32 -iso- config iso.cfg -sys- sys.cfg -pxe- pxe.cfg
Using this module instead of econfig.c32 will make it possible to remove ubcd/menus/isolinux/main.cfg and it will remove the need to load econfig.c32 for the ".." entries that point back to ubcd/menus/isolinux/main.cfg or ubcd/menus/syslinux/main.cfg.

Source code can be downloaded from:
http://git.zytor.com/?p=users/gerth/sys ... e23342b98f

Binaries can be downloaded from (currently only compiled for Syslinux 4.01):
http://ubcd.stopspazzing.com/downloads/ ... /whichsys/
Download Ultimate Boot CD v5.0: http://www.ultimatebootcd.com/download.html
Use Parted Magic for handling all partitioning task: http://partedmagic.com/

Victor Chew
Posts: 1359
Joined: Mon Feb 21, 2005 10:59 pm
Contact:

Re: Enhanced config.c32 (econfig.c32) and whichsys.c32

#4 Post by Victor Chew » Mon Sep 06, 2010 9:56 pm

@IceCube: I am using whichsys.c32 from syslinux V4.02.

When I use this command:

Code: Select all

COM32 whichsys.c32 -iso- config /pmagic/boot/isolinux/isolinux.cfg -sys- config /pmagic/boot/syslinux/syslinux.cfg
I get this error:

Code: Select all

Could not find kernel image: config
This doesn't work as well:

Code: Select all

COM32 whichsys.c32 -sys- chain.c32 hd1 swap -iso- localboot -1
I get this error:

Code: Select all

Could not find kernel image: localboot
Any idea what I did wrong?

Icecube
Posts: 1278
Joined: Fri Jan 11, 2008 2:52 pm
Contact:

Re: Enhanced config.c32 (econfig.c32) and whichsys.c32

#5 Post by Icecube » Tue Sep 07, 2010 2:47 am

"config" and "localboot" only work directly from the config file as keyword.
If you want to run them from the command line or with whichsys.c32, you need to add the modules config.c32 and localboot.c32.

For clarity, you can best change, the commands too:

Code: Select all

COM32 whichsys.c32 -iso- config.c32 /pmagic/boot/isolinux/isolinux.cfg -sys- config.c32 /pmagic/boot/syslinux/syslinux.cfg

Code: Select all

COM32 whichsys.c32 -sys- chain.c32 hd1 swap -iso- localboot.c32 -1
Download Ultimate Boot CD v5.0: http://www.ultimatebootcd.com/download.html
Use Parted Magic for handling all partitioning task: http://partedmagic.com/

Post Reply