[SOLVED] Grub: If exists sdb, then boot sdb, else sda
Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
}
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?
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.
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).
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.
#
# 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 ###
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.