3

I am booting from USB media, and I am using syslinux EFI boot.

I am booting the same media on 2 different laptops, and I have 2 menu options in syslinux.cfg, one for each laptop.

Currently, I have to manually select the right menu option for each laptop.

Is there some way to automate this, and have syslinux automatically recognize on which laptop it is booting? Perhaps based on some unique HW identifier?

How could I do this?

this is my EFI/BOOT/syslinux.cfg:

DEFAULT menu.c32
PROMPT 0
MENU TITLE UEFI boot menu
MENU AUTOBOOT Booting AAA in # seconds

LABEL AAA
MENU LABEL AAA
KERNEL menu.c32
APPEND /AAA/menu

LABEL BBB
MENU LABEL BBB
KERNEL menu.c32
APPEND /BBB/menu

the files /AAA/menu and /BBB/menu then have the correct boot options for each laptop.

so basically, I would need on laptop A, to automatically boot /AAA/menu, and on laptop B /BBB/menu

8
  • 1
    Can you explain the reasoning behind needing to boot from USB? Why can you not install 2 copies of syslinux, one on each laptop.... Commented Feb 12, 2024 at 21:32
  • I don't have any experience with syslinux personally. However, could you not install syslinux on each laptop separately and just set different default boot options for each? I.e. it might be easier to give each laptop its own local syslinux and config file, rather than trying to get syslinux to detect the laptop hardware from the USB. Commented Feb 13, 2024 at 15:30
  • What is the difference between the two notebooks? I mean, what pieces of hardware information will the decision be made on? Is it possible for you you to share the two sets of boot options? Commented Feb 13, 2024 at 21:23
  • I need to boot these laptops from external USB media. I need one master USB media, that works on multiple devices. The devices will have different boot options, such as different kernel and different boot parameters. Commented Feb 14, 2024 at 6:57
  • 1
    I suppose it should be possible to write some COMBOOT module ( syslinux.org/old/comboot.php inspired from the Hardware Detection Tool unfortunately discontinued since 2015. ( github.com/geneC/syslinux/tree/master/com32/hdt ) Commented Feb 16, 2024 at 10:26

1 Answer 1

2
+500

From what I have read on arch wiki: link

I think it is possible, but difficult, using extlinux that comes with syslinux package, and chain loading twice a syslinux. But I haven't tested it.

And it is a lot of work if you have to do it for more than 2 different computers. Because you will need for 10 different computers, 10 different partitions on the usb drive, each with a copy of the kernel and initrd, as well as some syslinux files.

Each laptop must have the esp boot partition: /dev/sda1 or at the same /dev/sdaX. If no, this method won't work.

Here is the way to proceed:

1. Install extlinux on laptop A:

On the laptop A, assuming esp boot partition is /dev/sda1:

mkdir ./mntefi
sudo mount /dev/sda1 ./mntefi
sudo mkdir ./mntefi/boot
sudo mkdir ./mntefi/boot/syslinux

# install extlinux:
sudo extlinux -i ./mntefi/boot/syslinux/ 

# copy *.c32 files:
sudo cp /usr/lib/syslinux/bios/*.c32 ./mntefi/boot/syslinux

Create a file ./mntefi/boot/syslinux/syslinux.cfg

TIMEOUT 0

UI menu.c32

LABEL MAIN
    COM32 chain.c32
    APPEND hd1 3

This file will chain to the third partition on the usb drive (hd1 if the laptop A have only one internal drive), where there will be the syslinux.cfg for laptop A.

2. Create partition 3 (/dev/sdb3) on the usb drive:

The partition can be small, it just have to contain a syslinux and the kernel and initrd.

3. Install extlinux on partition 3 of the usb drive:

mkdir ./mnt3
sudo mount /dev/sdb3 ./mnt3
sudo mkdir ./mnt3/boot
sudo mkdir ./mnt3/boot/syslinux

# install extlinux:
sudo extlinux -i ./mnt3/boot/syslinux/ 

# copy *.c32 files:
sudo cp /usr/lib/syslinux/bios/*.c32 ./mnt3/boot/syslinux

Create a file ./mnt3/boot/syslinux/syslinux.cfg

DEFAULT menu.c32
PROMPT 0
MENU TITLE UEFI boot menu
MENU AUTOBOOT Booting AAA in # seconds

LABEL AAA
MENU LABEL AAA
KERNEL menu.c32
APPEND /AAA/menu

This file will display the menu for laptop A, the menu file is located on partition 3 in the directory /AAA.

In the menu file, the kernel must have the following parameters: root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx rw, with the UUID of the partition where the linux is installed on the usb drive.

4. Main syslinux.cfg, of the usb drive:

On the usb drive, where the linux system is installed, assuming on partition /dev/sda2, create a file EFI/BOOT/syslinux.cfg:

TIMEOUT 0

UI menu.c32

LABEL MAIN
    COM32 chain.c32
    APPEND hd0 1

This file will chain on the internal drive of the laptop, on the esp boot partition, assuming it is the first partition on the laptop internal drive.

It will always chain the syslinux found on first partition of the internal drive in the laptop.

But maybe syslinux number the drives beginning by the one where it boots, if it does, then it needs to append hd1 1 instead of hd0 1

5. Repeat the steps 1, 2, and 3, for each laptop.

Be carefull, that on step 1, the syslinux.cfg must chain to the new partition created on step 2.

3
  • Clever idea indeed and +1 for that. BTW, wouldn't resorting to COM32 restrict this to x86 arches ? Commented Feb 16, 2024 at 12:16
  • I don't know, but maybe COM32 could be replaced by KERNEL that seems to be also able to run .c32 files. Commented Feb 16, 2024 at 12:36
  • @Bertrand125 - thank you for the effort. But this will not work. The solution cannot depend on the laptop's boot partition. The whole point in booting from external USB media is to be able to boot the device irrespective what is installed on the HDD, or even if HDD exists (ie booting rescue system). I appreciate your effort, and I will award the bounty anyway, if no better solution is offered. But this will not work for me. Thanks Commented Feb 17, 2024 at 10:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.