WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Determine boot device  (Read 4111 times)

Offline innominate

  • Newbie
  • *
  • Posts: 12
Determine boot device
« on: November 21, 2012, 05:08:46 PM »
Hi,

I think the way Tiny Core loads a file system into memory is complicating what would otherwise be a simple Linux question:

Is there a simple way to determine the device that Tiny Core booted from?  I'm concerned about corner cases such as booting from a USB device and then another one being inserted before this query is run.

Thanks,
Dave

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11284
Re: Determine boot device
« Reply #1 on: November 21, 2012, 05:46:18 PM »
Hi innominate
This question has come up at least once before. As I recall, there is no way to tell which device you booted from.
Furthermore, I don't think this is unique to Tinycore. I think all Linuxs load the kernel into RAM and there is no way
to tell where it was loaded from.

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: Determine boot device
« Reply #2 on: November 21, 2012, 06:29:10 PM »
The bootloader actually loads the kernel and optional initrd into RAM and then jumps to the entry point.
Therefore, there is no way for the linux kernel to know how it was loaded.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Determine boot device
« Reply #3 on: November 21, 2012, 06:45:04 PM »
Before TC i was using SLAX. There inside the very first setup shell script I could identify bootup partition.  Do not remember details :(
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: Determine boot device
« Reply #4 on: November 21, 2012, 07:00:56 PM »
Sure you can identify a partition by label or uuid, but that is no proof that the kernel was loaded from that partition.
You can use a USB drive to boot one version of Linux, and the hard drive can contain a completely different version.
Just because you see a boot partition with a linux kernel in it, it does not mean
that that was the one that was loaded even if it is the same version.

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: Determine boot device
« Reply #5 on: November 21, 2012, 07:13:54 PM »
In addition to above, I couldn't see any relevance of "device".
The device could possibly be disconnected as soon as the kernel is loaded, also there is no requirement that the kernel would have the capability to recognize it.
In case of optical or floppy disks there is no direct relation between device and medium, while in case of NIC, medium is unrelated to the device.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline innominate

  • Newbie
  • *
  • Posts: 12
Re: Determine boot device
« Reply #6 on: November 29, 2012, 09:10:30 AM »
Gents,  Thanks for the feedback. 

In case you're curious, here's the kludge I arrived at:
Without a closed-form solution, I just used the UUID stashed in /proc/cmdline... basically I look around to see if a device with a partition labeled with that UUID is around and if so, figure that was most likely what I booted from.

Thanks again,
Dave

Offline fmarinonj

  • Newbie
  • *
  • Posts: 3
Re: Determine boot device
« Reply #7 on: December 11, 2012, 11:43:49 AM »
I'm a little late to the thread, but here is how I am determining the boot device...

BOOTDEV=`cat /etc/sysconfig/backup_device | cut -d "/" -f1`

I don't think that the above works if you use the norestore boot code.

Regards.
« Last Edit: December 11, 2012, 11:45:49 AM by fmarinonj »

Offline netnomad

  • Hero Member
  • *****
  • Posts: 1026
Re: Determine boot device
« Reply #8 on: December 11, 2012, 12:05:00 PM »
hi fmarinonj,

cat /etc/sysconfig/backup_device | cut -d "/" -f1
reports the backup_device and this needs not to be the boot_device.
in my configuration i boot with /dev/sdb1, but my backup is located on /dev/sdb2.
for that reason i really enjoy to use uuid in my boot-codes, uuid offers so many flexible configurations.

never mind, it stays exiting :)
« Last Edit: December 11, 2012, 12:08:30 PM by netnomad »