WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How do I detect what device syslinux booted from?  (Read 2915 times)

Offline ost

  • Newbie
  • *
  • Posts: 41
How do I detect what device syslinux booted from?
« on: October 07, 2011, 08:23:08 AM »
Im using microlinux-4.0 and I wonder how I can interpret the system to find out what drive I booted from.
In worst case, there will be two identical usb sticks present. A challenge (non real) case would be two identical sticks with two identical ISO's on.
Depending on BIOS settings, the stick will usually get the name sda or sdb and I need to find out which with as little complications as possible.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14790
Re: How do I detect what device syslinux booted from?
« Reply #1 on: October 07, 2011, 08:41:53 AM »
It's maybe better to tell your machine which stick to boot from using label or uuid?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: How do I detect what device syslinux booted from?
« Reply #2 on: October 07, 2011, 08:49:32 AM »
Hi ost
If you are loading extensions from the stick you are booting from,  /opt/.tce_dir  will tell you.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: How do I detect what device syslinux booted from?
« Reply #3 on: October 07, 2011, 10:29:09 AM »
A direct answer to the question:
There is no way to tell what device syslinux bootde from.
The boot loader copies the kernel and initrd into RAM and jumps to the entry point.
The kernel has no way to tell how that was done.

You can do things to give direction to your programs though.
You can add bootcodes  or use existing bootcodes that you can examine in /proc/cmdline.

Offline ost

  • Newbie
  • *
  • Posts: 41
Re: How do I detect what device syslinux booted from?
« Reply #4 on: October 10, 2011, 04:13:42 AM »
A direct answer to the question:
There is no way to tell what device syslinux bootde from.

Ok, so tinycore cant, but maybe there is a specific bootloader that can pass it to a /proc/cmdline comment or similar?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11573
Re: How do I detect what device syslinux booted from?
« Reply #5 on: October 10, 2011, 11:07:40 AM »
Hi ost
Be more specific abut the environment. Are these bootable USB sticks, or are you using a boot
loader located somewhere else to select one of the sticks? Do the sticks have  /tce directories
on them? If you give some details you'll get a better answer.

Offline ost

  • Newbie
  • *
  • Posts: 41
Re: How do I detect what device syslinux booted from?
« Reply #6 on: October 11, 2011, 03:13:10 AM »
Be more specific abut the environment. Are these bootable USB sticks, or are you using a boot
loader located somewhere else to select one of the sticks? Do the sticks have  /tce directories
on them? If you give some details you'll get a better answer.

Well, I didnt want to be specific because I wanted a general solution, not a specific.

Let me describe a case:
I have a bootstick with microcore and all the needed tce's built into the core archive, so the bootoptions will only contain tce=/

On this stick I also have a windows executable that I run on a pc. This executable saves some config files and I need to read these files from microcore when I boot the stick on a different pc.

Now, imagine a second stick in place that could be a accidential leftover stick in a second usb port that doesnt get boot priority. I want to make sure that I load the correct config file.

Also, I prefer a static syslinux.cfg (or other config file in case of another bootloader) to prevent issues when used on pc's with different hardware and/or BIOS settings.

If syslinux had some option to pass the drive or bus information, it would enable me to pick up the drive. Maybe some other bootloaders has this option?


Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: How do I detect what device syslinux booted from?
« Reply #7 on: October 11, 2011, 02:20:16 PM »
tce=/ is a poor choice.
Use an actual tce directory on the stick.
Specify the UUID and you can be sure the correct drive will be mounted ( providing you loop mount extensions ).
You can determine the drive from the contents of /opt/.tce_dir.

Offline ost

  • Newbie
  • *
  • Posts: 41
Re: How do I detect what device syslinux booted from?
« Reply #8 on: October 12, 2011, 04:27:57 AM »
tce=/ is a poor choice.
Use an actual tce directory on the stick.
Well that depends on usage. For my use its the best choise. I want a clean and repeatable environment where I know what tce's are present at boot independant on other files on the stick. Adding the tce's to the corefiles works great.

Specify the UUID and you can be sure the correct drive will be mounted ( providing you loop mount extensions ).
You can determine the drive from the contents of /opt/.tce_dir.
Specify where? In the syslinux.cfg? I guess that would somewhat work, but would require different syslinux.cfg on clones of the stick?

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: How do I detect what device syslinux booted from?
« Reply #9 on: October 12, 2011, 12:40:24 PM »
tc-install builds an extlinux boot config that uses UUIDs.
If you clone the stick, you also clone the UUID.
"onboot.lst" ensures that you know what tczs get loaded at boot, independant on other files on the stick.

You will have a much better experience working within the tc design than you will trying to fight it.

Offline ost

  • Newbie
  • *
  • Posts: 41
Re: How do I detect what device syslinux booted from?
« Reply #10 on: October 13, 2011, 07:48:40 AM »
tc-install builds an extlinux boot config that uses UUIDs.
If you clone the stick, you also clone the UUID.
"onboot.lst" ensures that you know what tczs get loaded at boot, independant on other files on the stick.
Ok, I may not clone them direct in practice, just reinstall the default microcore, then overwrite the microcore.gz file. I dont know where the UUID is stored and it doesnt make a diference if its changed or not. I still cant identify the real boot stick from a similar plugged one, wether it has same or different UUID, without manual differenciating.

You will have a much better experience working within the tc design than you will trying to fight it.
Im not fighting this. Ive just moved my tce folder to ram instead of usb. My problem is isolated from this, and moving the tce folder to the fat fs does not solve the problem.

I think a solution is to generate and save a random hash at a controlled boot environment that gets embedded into the script..

But thanks for engaging in the problem :)