LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   is hd0 = /dev/sda (https://www.linuxquestions.org/questions/linux-software-2/is-hd0-%3D-dev-sda-732956/)

centguy 06-14-2009 11:52 PM

is hd0 = /dev/sda
 
I use GRUB bootloader on the MBR on an internal hard drive to
boot a Linux OS on a portable hard drive.

After booting to OS on the portable hard drive, /dev/sda corresponds to the portable hard drive.
Now, I want to install GRUB on the MBR of the portable hard drive so that
I can boot the portable hard drive directly without relying on MBR of the internal hard drive.

Can I do

root (hd0,0)
setup (hd0)

for the job ?
I just don't want to overwrite the MBR on the internal drive.

Cheers!

Shadow_7 06-15-2009 12:05 AM

It's hard to say. hd0 could be /dev/sda or /dev/hda. On my desktop hd0 was /dev/sda, when it only had SATA drives. I recently transfered an old 500GB IDE HDD to the system and hd0 is now /dev/hda, with all of the manual grub updates to keep on chugging. Which you can avoid if you use that virtual thing and partition labels, yada yada yada.

I'd recommend a grub boot CD at a minimum (el-torito). (or flash drive if your mobo allows that boot option). Boot it, enter grubs command mode, and poke around to see what it sees as it's options. help, and tab completion are available in command mode. It helps if the drives are somewhat unique, filesystem types differ between relative partitions and such. Worst case scenario, dd an image of the MBR that is in peril before making changes. And restore it if things go bad. Of course it helps to have a knoppix cd or gentoo live cd around. Or other options.

HTH

grepmasterd 06-15-2009 12:17 AM

this is all pretty well documented, isn't it?

http://www.gnu.org/software/grub/man...ub.html#device

also look inside /boot/grub/devices.map

centguy 06-15-2009 01:49 AM

waow!! I am really amazed by the community's help. /boot/grub/device.map seems to unambiguosly tell me the mapping.

I have:

# this device map was generated by anaconda
(hd0) /dev/sda

so I guess what I should do.

Thanks a lot!!

grepmasterd 06-15-2009 02:08 AM

a follow-up suggestion: thoroughly read and understand the grub documentation. errors while using could put you in a sticky corner.

Shadow_7 06-15-2009 08:23 AM

Quote:

Originally Posted by centguy (Post 3574042)
waow!! I am really amazed by the community's help. /boot/grub/device.map seems to unambiguosly tell me the mapping.

I have:

# this device map was generated by anaconda
(hd0) /dev/sda

so I guess what I should do.

Thanks a lot!!

You can't always rely on that. As you can tell by the # comment, it wasn't even generated by grub. Which MIGHT mean, that grub has already been installed (and installed to the MBR in peril, had it said /dev/hda).

Back in the early days I've had a few times where /boot/grub/devices.map didn't exist, or was just plain wrong. Certainly adding or manipulating it manually doesn't always yield expected results. And if you reconfigure your hardware like I did, it may not automatically update to reflect those changes. Although less of an issue these days with better and better releases. Until you take the road less traveled.

centguy 06-16-2009 10:45 PM

Yes. sda and sdb could be mapped to internal drive or external drive "randomly". So the reliability of /boot/grub/devices.map is zero (I think).

Just a quick update. I use gparted to figure out the exact drives mapping (hey, i use gparted a lot just to see the partition table).

I issued a "grub" command
and typed:

device (hd0) /dev/sdb
root (hd0,2)
setup (hd0,2)

to install a boot loader on /dev/sdb3. Everything works as expected. Thanks!

grepmasterd 06-16-2009 11:28 PM

Quote:

Yes. sda and sdb could be mapped to internal drive or external drive "randomly". So the reliability of /boot/grub/devices.map is zero (I think).
just to be clear
http://www.gnu.org/software/grub/man...evice-map.html

glad you got it working :)

shrinivasjoshi 06-16-2009 11:42 PM

Hi,

As long as I know, sda & sdb not get allocated "Randomly",

"sda" stands for SCSI device connected as a Primary Master. Here in your case its SATA.
"sdb" stands for SCSI device connected as a Primary Slave.

If the disk is IDE ATA, It will show "hda" and "hdb"

centguy 06-17-2009 08:27 AM

shrinivasjoshi:

so what are the names of sdc, sdd, ... ? second primary slave ? third primary slave.. ? I run out of imagination. thanks for the comments anyway.

jlinkels 06-17-2009 06:44 PM

When you install grub you can query grub for the device mapping and install accordingly. It won't change during installation.

However, when adding or removing disks, the next time you boot things can look differently.

In this post I wrote everything I know about disk UUID so grub recognizes your disk by signature instead by location in the hda/sda chain.

jlinkels

centguy 06-17-2009 10:02 PM

jlinkels:

Thanks. Your post is very detailed and very useful. I wish people can write replies just like you. Straight to the point and full of useful information.

Shadow_7 06-18-2009 09:57 AM

after the fact, you can always use /proc for most of that information.

$ cat /proc/partitions

or sfdisk -l
or cfdisk / gparted / others...

I just cat /proc/partitions, since there's a delay between when I stick a usb drive in and it registers. cat lets me know when it registers and as what device. Since I don't run dbus/hal/avahi, it allocates somewhat randomly for non-primary drives. If I boot with USB drive in place, it's /dev/sdb. If I plug it in after the fact it is /dev/sdf. Although the second USB drive always seems to get /dev/sdg. Not really a grub thing, just saying. Since my docking station drives are all ext3, and all of my flash cards are Fat32, it makes fstab a dynamic file for me. There's ways to keep it stable, just saying it's easier / simpler for me to mod as needed. But I need to monitor (/proc/partitions) to know what specifically needs a mod. Since I take the stance that if it's not currently used, and can be turned off, it is off / unplugged / yada yada yada.


All times are GMT -5. The time now is 05:39 AM.