LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 06-24-2011, 03:18 AM   #1
defaultyeti
LQ Newbie
 
Registered: Mar 2011
Posts: 7

Rep: Reputation: 0
Question Grub: If exists sdb, then boot sdb, else sda


Hi,

not quite sure how to ask this, so I will explain my problem (maybe there is another solution to this):

Setup:
I've got a PC with a build-in HDD and one external HDD (eSATA). Its running Ubuntu and Windows 7 in dualboot with fusefs.

Problem:
When the external eSATA drive is powered on, Ubuntu won't boot. It is because the bootloader try's to boot /dev/sda3, but when eSATA is connected, /dev/sda3 is /dev/sdb3 and /dev/sda is the external drive.

Solution:
Not sure. How would I make grub load /dev/sdb3 if it is available? How do I tell grub to boot from a device by UUID (does it even work)?

This is (part of) my /boot/grub/grub.cfg

menuentry "Ubuntu, Linux 2.6.38-8-generic" {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos3)'
search --no-floppy --fs-uuid --set 50B45BE4B45BCB5C
loopback loop0 /ubuntu/disks/root.disk
set root=(loop0)
linux /boot/vmlinuz-2.6.38-8-generic root=UUID=50B45BE4B45BCB5C loop=/ubuntu/disks/root.disk ro quiet splash
initrd /boot/initrd.img-2.6.38-8-generic
}
 
Old 06-24-2011, 10:13 AM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,540

Rep: Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496
It's not really clear to me what your situation is. Do you have windows 7 on the internal drive?
Ubuntu on the external?
Trying to boot both with Ubuntu Grub2?
Booting windows 7 with its bootloader?
Where did you install Grub2 during the installation process?
Are you unable to boot Ubuntu at all?
Are you able to boot windows 7?
Do you want to use Grub2 to boot Ubuntu and windows 7?

What happens when you change the set root='(hd0,msdos3)', replacing hd0 with hd1?
Could you boot the install CD and open a terminal and run the command: sudo blkid to see if the correct UUID is in the menuentry for Ubuntu?

Last edited by yancek; 06-24-2011 at 10:15 AM.
 
Old 06-24-2011, 10:23 AM   #3
defaultyeti
LQ Newbie
 
Registered: Mar 2011
Posts: 7

Original Poster
Rep: Reputation: 0
I'm sorry, english is not my native thong, so I guess I did not make myself clear enough

There is just data on the external drive and Win7+Ubuntu on the internal drive.
When the system boots, it will first go into the Windows Bootloader, then into Grub if I choose "Linux". I used the Ubuntu installer and it created it that way.

Everything works fine (boot Win7 / boot Ubuntu) EXCEPT, when the external drive is turned on and connected. I will try to explain it in detail:

External drive not connected:
System boot -> Windows Bootmanager -> I chose Linux -> Ubuntu grub -> I choose Ubuntu 2.6.38 Kernel -> Ubuntu is up and running

External drive connected:
System boot -> Windows Bootmanager -> I chose Linux -> Ubuntu grub -> I choose Ubuntu 2.6.38 Kernel -> Systems hangs somewhere in initramfs or something (I am no Linux Guru) and gives me a /bin/sh without editor. It is because Ubuntu tried to chroot to the external drive (where it should have used the internal one) and there is no /root on the external. At least I believe that this is happening.

Does it make sense now?


Edit: The UUID is correct, and I guess (I cannot tell for sure, because I am not at home atm), if I changed hd0 to hd1, it will boot correctly. But the external drive is not always connected, so I would like to have something like "if [ -f /dev/sdb ] ; then <some magic bash commands here>". Is the grub.cfg bash-syntax-like?

Last edited by defaultyeti; 06-24-2011 at 10:36 AM.
 
Old 06-24-2011, 01:29 PM   #4
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,540

Rep: Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496
Quote:
Does it make sense now?
No. Is this a wubi install inside windows?
Looking at the menuentry you posted originally for Ubuntu, it doesn't look right at all. You have "insmod ntfs". It should be ext2. Why do you have a loopback line? Are you trying to boot an iso image of Ubuntu? You have two "set root" lines and I would expect there to be one, not a loop entry. Your uuid number also does not look right. Can you post the output of "sudo fdisk -l"(lower case letter L in the command) so we can see your partition information? Also the output of "sudo blkid" (both commands without quotes).
 
Old 06-27-2011, 03:20 AM   #5
defaultyeti
LQ Newbie
 
Registered: Mar 2011
Posts: 7

Original Poster
Rep: Reputation: 0
Yes, I think it is a wubi install.

Here comes the fun part. Yesterday I updated the system (suddenly there were 50+ updates for Ubuntu 10.10) and grub was updated, too. Now it works out of the box (??!). Some Ubuntu developer in here who read my post and fixed something??

I will post my configuration when I am at home just for the completeness of this thread later on.
 
Old 06-27-2011, 09:34 AM   #6
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,540

Rep: Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496Reputation: 2496
Quote:
Some Ubuntu developer in here who read my post and fixed something??
Your menuentry for your original Grub was messed up. I expect that updating Grub solved the problem by correcting the entry.
 
Old 06-28-2011, 02:38 AM   #7
defaultyeti
LQ Newbie
 
Registered: Mar 2011
Posts: 7

Original Poster
Rep: Reputation: 0
This is my grub.cfg




Quote:
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
set have_grubenv=true
load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fi

function savedefault {
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
}

function recordfail {
set recordfail=1
if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}

function load_video {
insmod vbe
insmod vga
}

insmod part_msdos
insmod ntfs
set root='(hd0,msdos3)'
search --no-floppy --fs-uuid --set 50B45BE4B45BCB5C
loopback loop0 /ubuntu/disks/root.disk
set root=(loop0)
if loadfont /usr/share/grub/unicode.pf2 ; then
set gfxmode=640x480
load_video
insmod gfxterm
fi
terminal_output gfxterm
insmod part_msdos
insmod ntfs
set root='(hd0,msdos3)'
search --no-floppy --fs-uuid --set 50B45BE4B45BCB5C
loopback loop0 /ubuntu/disks/root.disk
set root=(loop0)
set locale_dir=($root)/boot/grub/locale
set lang=de
insmod gettext
if [ "${recordfail}" = 1 ]; then
set timeout=-1
else
set timeout=10
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/10_lupin ###
menuentry "Ubuntu, Linux 2.6.38-8-generic" {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos3)'
search --no-floppy --fs-uuid --set 50B45BE4B45BCB5C
loopback loop0 /ubuntu/disks/root.disk
set root=(loop0)
linux /boot/vmlinuz-2.6.38-8-generic root=UUID=50B45BE4B45BCB5C loop=/ubuntu/disks/root.disk ro quiet splash
initrd /boot/initrd.img-2.6.38-8-generic
}
menuentry "Ubuntu, Linux 2.6.38-8-generic (recovery mode)" {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos3)'
search --no-floppy --fs-uuid --set 50B45BE4B45BCB5C
loopback loop0 /ubuntu/disks/root.disk
set root=(loop0)
linux /boot/vmlinuz-2.6.38-8-generic root=UUID=50B45BE4B45BCB5C loop=/ubuntu/disks/root.disk ro single
initrd /boot/initrd.img-2.6.38-8-generic
}
menuentry "Ubuntu, Linux 2.6.35-28-generic" {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos3)'
search --no-floppy --fs-uuid --set 50B45BE4B45BCB5C
loopback loop0 /ubuntu/disks/root.disk
set root=(loop0)
linux /boot/vmlinuz-2.6.35-28-generic root=UUID=50B45BE4B45BCB5C loop=/ubuntu/disks/root.disk ro quiet splash
initrd /boot/initrd.img-2.6.35-28-generic
}
menuentry "Ubuntu, Linux 2.6.35-28-generic (recovery mode)" {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos3)'
search --no-floppy --fs-uuid --set 50B45BE4B45BCB5C
loopback loop0 /ubuntu/disks/root.disk
set root=(loop0)
linux /boot/vmlinuz-2.6.35-28-generic root=UUID=50B45BE4B45BCB5C loop=/ubuntu/disks/root.disk ro single
initrd /boot/initrd.img-2.6.35-28-generic
}
### END /etc/grub.d/10_lupin ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Windows Vista (loader) (on /dev/sda1)" {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set F2CC58E6CC58A69F
chainloader 1
}
menuentry "Windows 7 (loader) (on /dev/sda2)" {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set 3A165A0B1659C911
chainloader 1
}
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###
 
  


Reply



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
sda / sdb after boot anika.ella Linux - Newbie 1 04-29-2011 10:59 AM
[SOLVED] Install grub for a filesystem on sdb from a rescue system on sda simonb Linux - General 4 08-27-2009 11:39 PM
How do I keep sda from changing its name to sdb? kinetic Linux - Hardware 3 06-22-2008 08:01 PM
Just installed F9 on sdb but lost the ability to boot F7 on sda Iltbreg Fedora 2 06-09-2008 12:26 PM
sda or sdb? stevest SUSE / openSUSE 7 12-18-2007 11:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 12:24 PM.

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