Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Hardware
User Name
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?


  Search this Thread
Old 09-26-2006, 07:41 PM   #1
Registered: Apr 2004
Distribution: Debian
Posts: 143

Rep: Reputation: 15
Determine BIOS Drive Order

Hello, all. I was wondering if anyone had a clue as to how to determine BIOS drive ordering from within Linux. I'm essentially looking for a way to take a device name (i.e., /dev/hda1) and translate it into a GRUB style device description (i.e., "(hd0,0)"). I ask this particularly because my machine, for instance, tends to order its SATA controllers in a rather peculiar way (i.e., (hd0,0) => /dev/sde under 2.6.17, (hd0,0) => /dev/sdc under 2.6.14, etc.).

The real reason I want this information is because I am currently in the process of essentially trying to remake the rescue disk portion of Norton Ghost out of a bootable Linux CD, ntfsprogs, and some of my own added scripts. I see a lot of potential here, since using Linux would allow one to include a number of different storage mechanisms for writing the image file (SSH, NFS, Samba, ext3, etc.) and also allows me access to ntfsprogs, which has pretty much done all of the work for me. I have successfully saved and restored a bootable rescue image using dd (for the MBR), ntfsclone, ntfsresize, and relocntfs. So far, I have had no trouble restoring the image to partitions of different sizes and drives of different geometries than the original.

The problem comes in when I change the partition on which the restore is occurring (i.e., image created using /dev/hda1 and restored onto /dev/hda2). The Windows bootloader file C:\boot.ini needs to know which drive it should mount as C: and it wants a description in the format "multi(0)disk(0)rdisk(0)partition(1)" which is kind of similar to GRUB's "(hd0,0)". I need to be able to generate the former given a device name (such as /dev/sda1).

Suggestions and thoughts are most welcome. Thanks for reading!
Old 09-26-2006, 10:02 PM   #2
Registered: Apr 2004
Distribution: Debian
Posts: 143

Original Poster
Rep: Reputation: 15
I found something.

If you install the "edd" module, a directory tree pops up: /sys/firmware/edd. Inside of that directory is one directory for each of the INT13-accessible BIOS drives. In each of those directories, there is a file, "mbr_signature", containing four bytes of the drive's data starting at byte offset 440 (part of the drive's boot sector, almost right before the MBR). One can then use dd to read the various Linux devices and match up the results to pair Linux device names with BIOS drive numbers.

I wrote a little script to do it. I thought I'd share. On my machine, executing this script with the parameter "/dev/sde" produces the output "/sys/firmware/edd/int13_dev80". Note that I had to run "modprobe edd" first.


lsmod | grep edd >& /dev/null
if [ "$?" -ne "0" ]; then
    echo "edd module not loaded"
    exit 1

if [ -z "$linuxdev" ]; then
    echo "Please specify Linux device name."
    exit 2

# Establish linux device signature
temp="`dd if=$linuxdev bs=1 count=4 skip=440 2>/dev/null | od -A n -t x1`";
temp="${temp// /}"
while [ "${#temp}" -ge "2" ]; do

# Search the BIOS devices for a matching signature
for biosdev in `ls -1d /sys/firmware/edd/int13*`; do
    biossig="`cat "$biosdev/mbr_signature"`"
    if [ "$linuxsig" = "$biossig" ]; then
        echo $biosdev
Old 09-27-2006, 12:09 AM   #3
LQ Guru
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
No need to use any scripts or fancy software. Just go into grub prompt and type root (hd<tab> and it should list the avaliable drives. If you do root (hd0,<tab> for an example, it will do the same for partitions too. By using grub you can view files too.

You can fix drives to certain names by editing under /boot/grub.
Old 09-27-2006, 03:23 PM   #4
Registered: Apr 2004
Distribution: Debian
Posts: 143

Original Poster
Rep: Reputation: 15
Indeed I can. Unfortunately, I doubt that advice will apply in this situation. What I actually need is a one-to-one mapping between Linux device names and BIOS drive numbers. The purpose of this task is to create an automated NTFS drive ghosting system; I want the amount of user knowledge required to be as little as possible. So while I can already obtain a list of available drives and partitions, I need a way to map those devices (e.g., "/dev/hdb3") onto Windows bootloader names (e.g., "multi(0)disk(1)rdisk(0)partition(3)". And this mapping isn't always consistent, since Linux doesn't always name the drives in the same order as the BIOS.

Thanks for the response, though; I didn't know GRUB would autocomplete drive names.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
IBM NetVista no boot order in BIOS true_atlantis Linux - Hardware 5 04-04-2008 12:01 PM
nv_sata driver order doesn't agree with BIOS tvynr Linux - Hardware 9 11-01-2006 07:29 PM
how do I determine the order modules get loaded? Simon Bridge Linux - General 6 04-26-2006 09:15 AM
USB boot order BIOS settings NovaBurst Linux - Hardware 1 03-27-2005 11:23 PM
old BIOS (1992) won't detect my cdrom drive; BIOS says: neither IDE prots enabled carbono Linux - Hardware 5 05-18-2004 11:07 AM > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 02:01 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration