LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   [solved] Yet another bootloader thread (https://www.linuxquestions.org/questions/linux-newbie-8/%5Bsolved%5D-yet-another-bootloader-thread-4175455063/)

oskar 03-21-2013 06:53 PM

[solved] Yet another bootloader thread
 
After my experience failed me and web instructions lead me nowhere, I'm sorry to have to resort to this.

I had a
1TB drive with Ubuntu and
160GB with win7(32)

I added a 1TB drive and installed win7(64) which replaced the bootloader on the 160gig win7(32) drive which I ultimately want to get rid of.

I tried boot-repair from a ubuntu live cd which got stuck detecting drives for an hour before I killed it.
I tried EasyBCD which worked for win7 and win7(32) but won't boot ubuntu. It asks for a drive letter for an ext4 partition...
And apparently there are some inherent problems with ubuntu 10.04+ and easybcd.

I never understood why it's so difficult to do something that every linux distro's installer does fully automated. :(
Thinking about it maybe I should just install some distro to the 160gig drive, tell it to install the bootloader on the 1TB ubuntu drive and then remove it... would that work?

grail 03-21-2013 08:13 PM

I might be missing something here, but why not just have Ubuntu update the grub loader to boot all 3 systems?

oskar 03-21-2013 10:17 PM

I guess I could do that if I knew how to boot into ubuntu.
and if the solution is to chroot into it, I'd rather just install another distro on top of it just for the bootloader... it's more simple like that :P

I guess the solution is simple, but I'd rather not mess things up. It takes a fortnight to reset the mbr on win7.

Erik_FL 03-21-2013 11:39 PM

Automatic things are very easy until they don't work. Then you end up learning how to do things manually. I prefer to do things manually to start with so that I can learn how to handle the problems that might come up.

Sometimes you do have to install and configure boot loaders manually, especially if you have a mixture of partition types. Windows and Linux do not create partitions on the same boundaries and you may find that partitions are not detected correctly. That is much more likely to be a problem in an extended partition.

It is usually a bad idea to have a boot loader on a different disk than where you install the boot sector. Having GRUB on the 160gig drive install its boot sector to the 1TB drive will require that both drives are present in order to boot.

What you want to do is "chroot" to the 1TB drive Ubuntu or boot the 1TB drive Ubuntu and then use the GRUB install script, "grub-install". When you are installing GRUB, make sure that the "/boot/grub" directory is on the same hard disk where you are installing the grub boot sector. You only have to install GRUB once. Just use "grub-mkconfig" when you want to create or update the boot configuration (menu).

What boot loaders are you trying to install? Which boot loader do you want to start first? Are you using a computer with UEFI booting or BIOS booting? Are you using GPT or an MBR partition table?

The Windows UEFI boot loader won't chain to another boot loader. You have to make ELILO, GRUB 2 (or an updated GRUB) boot first on a UEFI machine. Then have the boot loader chain to the Windows boot loader. All UEFI boot loaders go in the EFI System Partition under the "EFI" directory.

To chain from the Windows boot loader to a different boot loader using BIOS booting, you must copy the other boot loader's boot sector into a file. The Windows boot loader can chain to a file using an "APPLICATION BOOTSECTOR" menu entry. If you are installing both boot loaders to the same primary partition, install the Linux boot loader, copy the boot sector and then install or repair the Windows boot sector.

Windows does sometimes mistake Linux partitions for some other kind of partition, and then assigns a drive letter to the partition. That can make software hang if it expects a drive letter to be assigned to a valid file-system. To avoid the problem, remove the drive letter using the Computer Management console (available in the control panel).

Make sure that you are installing boot loaders to the first hard disk in the BIOS boot device list. Also, boot loaders should be installed in a primary partition, using the primary partition's boot sector. I know that a lot of Linux distros install the boot sector code to the MBR. That is really not correct, and it can cause problems booting Windows. Leave the default software in the MBR and set the "boot" flag for the partition that you want to be booted first. Install each boot loader to the boot sector in the primary partition that contains the boot loader. You can create a small primary partition for each boot loader and put the operating systems in separate extended partitions if you have a lot of them.

Don't change the BIOS device boot order (especially for hard disks) after you have installed and configured boot loaders. That changes the BIOS drive IDs (GRUB hard disk numbers). Windows can't start the boot manager from any disk except the first (ID 0x80) unless you manually patch the boot sector. If you are going to move disks around, it's best to make a disk be the first boot device when you are installing its boot loaders, and then put the boot loaders on the same disk. At least then the boot loader will start, even if it can't find the operating system on some other disk to load it. GRUB's command mode is handy if you can make sure that some copy of GRUB will start up.

BCDEDIT in Windows is a pain, but it isn't that difficult to use it with all the tutorials and the built-in help. Copy and paste the UUIDs or use the synonyms like "{bootmgr}" and "{current}". You can list UUIDs with "BCDEDIT /ENUM ALL /V". GRUB 2 is also very well documented. It's a little more work to type in the commands but you will be able to troubleshoot problems more easily.

The trick to installing Windows for multi-booting is to install it in the first primary partition on the first hard disk so that drive letter C is assigned to the Windows partition by setup. To make sure that happens you can create the first partition on the hard disk as NTFS before you install Windows and then move (or copy) the Windows partition later. You can copy or move the "boot" folder where you want the boot loader and then use the command line from the setup disc to run BCD and BOOTSECT or BCDBOOT.

If you are going to create partitions before the Windows partition, make them EFI system partitions, Microsoft System Reserved partitions, or a Linux-only file-system. After you have installed Windows then you can move things around. If you move the Windows boot loader, you have to use BCDEDIT to change the partition location of the boot manager. If the Windows OS partition is the same one as the boot manager, then you can set the Windows entry "device" and "osdevice" to "partition=boot". Then you only have to change the partition for the boot manager when you move it and Windows somewhere else.

Installing a boot loader to the MBR can write over the disk signature used by Windows to identify the disk. You may have to run BCDEDIT to set the partition location of the boot manager, patch the disk signature into the MBR, or both. If Windows doesn't find a disk signature it writes one. That can actually make booting suddenly fail until you use BCDEDIT to set the partition again. Partitions in the Windows boot database are identified by the disk signature and a partition number. That's true whether you identify the partition by drive letter or a Windows device name like "\Device\HarddiskVolume1". The specified drive letters or devices must be those seen by the OS being used to run "BCDEDIT". They are not necessarily the same as the normal Windows OS would see.

Erik_FL 03-22-2013 12:19 AM

Quote:

Originally Posted by oskar (Post 4916331)
I guess I could do that if I knew how to boot into ubuntu.
and if the solution is to chroot into it, I'd rather just install another distro on top of it just for the bootloader... it's more simple like that :P

I guess the solution is simple, but I'd rather not mess things up. It takes a fortnight to reset the mbr on win7.

  • Boot the Ubuntu live CD
  • Start a command shell
  • Change to the root account
    Code:

    sudo su -
  • Mount your Ubuntu partition on the 1TB disk
    Code:

    mkdir /mysys
    mount /dev/sda1 /mysys

  • Change the root to your Ubuntu system
    Code:

    mount --bind /dev /mysys/dev
    mount --bind /proc /mysys/proc
    mount --bind /sys /mysys/sys
    chroot /mysys

  • Install GRUB
    Code:

    grub-install /dev/sda
  • Configure GRUB
    Code:

    grub-mkconfig -o /boot/grub/grub.cfg
  • Exit from the root file-system shell
    Code:

    exit
  • Dismount everything
    Code:

    umount /mysys/sys
    umount /mysys/proc
    umount /mysys/dev
    umount /mysys

  • Boot from your 1TB hard disk
  • Type in GRUB commands if the OS doesn't load or repeat the above steps

When you install GRUB to the MBR as above, GRUB will always start first, and you must select a GRUB menu entry to chain to the Windows boot manager. Windows probably installed "bootmgr" to the first hard disk. If you moved the hard disk after installing Windows, "bootmgr" may no longer be on the first hard disk. To chain to the Windows "bootmgr" on some other hard disk you will need to have GRUB swap the BIOS IDs (grub disk numbers) so that the Windows disk is first. The Windows boot sector can only start "bootmgr" from the first hard disk.

If you want to install GRUB to the partition boot sector instead of the MBR then use "/dev/sda1" or whatever Linux partition is correct instead of "/dev/sda" for "grub-install". Use "fdisk" to set the "boot" flag for either the GRUB or the "bootmgr" partition to determine which starts first. Windows writes standard boot code in the MBR on the first hard disk (that looks at the "boot" flags). Windows writes its boot sector to the first primary partition on the first hard disk (the partition contains "bootmgr").

Most people don't know about the command mode in the Windows setup CD. You can press Shift + F10 to run a command prompt after booting the Windows setup CD. You can download setup CDs for some versions of Windows from the Digital River web site. A CD key is not required to use the command prompt or repair Windows. Look for information about these commands for repairing Windows booting.
  • BCDEDIT
  • BCDBOOT
  • BOOTREC
  • FIXMBR
  • BOOTSECT

oskar 03-22-2013 08:23 AM

You are a maniac.
Thanks a bunch!

The shift-F10 on the windows cd is really helpful. I already wondered where that thing went.

Madhu Desai 03-22-2013 08:37 AM

If i had two hdd as you have, i would have done:
  1. disconnect 160GB HDD. create two partition on 1TB HDD, install Win7 32 and 64 bit.
  2. disconnected 1TB and connect 160GB HDD, install Ubuntu.
  3. connect all and during boot i would press F12 and select OS type. no unnecessary grub/bootloader problem.

Erik_FL 03-22-2013 01:17 PM

Quote:

Originally Posted by mddesai (Post 4916530)
If i had two hdd as you have, i would have done:
  1. disconnect 160GB HDD. create two partition on 1TB HDD, install Win7 32 and 64 bit.
  2. disconnected 1TB and connect 160GB HDD, install Ubuntu.
  3. connect all and during boot i would press F12 and select OS type. no unnecessary grub/bootloader problem.

Connecting one disk at a time is a good suggestion to avoid accidentally writing over the Windows boot sectors. It also allows the default Ubuntu setup to be used to install GRUB to the MBR of the first hard disk.

It is possible to install Ubuntu to the second disk by using the advanced options in Ubuntu setup. The boot sector has to be installed to the MBR of the second hard disk.

What you suggest is close to what I would do with that boot configuration. There are a few caveats.

I'm assuming that you mean to end up with the 1TB disk as the first, and the 160GB as the second. Windows can't be the second hard disk because it won't boot.

It may be necessary to change the "root=" kernel parameter for Ubuntu to boot it from the second hard disk. Ubuntu may use the UUID to identify the disk, in which case there is no problem.

You are assuming that the BIOS has an F12 key to select the boot device. Some use a different key and some do not have a boot selection menu. However, it is possible to change the boot device order. It's a question of how easy or difficult it is to switch the boot disk.

I would copy the boot sector of the second hard disk (Ubuntu) into a file and put that file in the root directory of the Windows partition on the first hard disk. Then use BCDEDIT in Windows to add Ubuntu as a "/APPLICATION BOOTSECTOR" menu entry in the Windows boot menu.

Code:

bcdedit /create /d "Ubuntu Linux" /application bootsector
bcdedit /set {created-uuid} device partition=boot
bcdedit /set {created-uuid} path \bootsect.lnx
bcdedit /set {created-uuid} description "Ubuntu Linux"

Replace "created-uuid" with the UUID assigned by "/create". The curly braces are required. The last line is not necessary. It's just an example of how to change the description later if you need to. Using "partition=boot" says that the file is in the same partition with "bootmgr". To put the file in a different partition, use "partition=X:" where X is the partition letter. The path can be any path or file name in the partition. It must be enclosed in quotes if it contains special characters. I recommend using simple 8.3 file names in the root directory. Also the partition containing the file must be FAT or NTFS.

The easiest way to create the file is with "dd" in Linux.

Code:

dd if=/dev/sdb of=/tmp/bootsect.lnx bs=512 count=1
As an alternative you can use a program called "dskprobe.exe" under Windows that is available in the Windows XP Support Tools. That program works on XP, Vista and Windows 7 without any changes. Open the Ubuntu disk as a physical device handle, and then save a copy of the MBR (sector 0) or partition boot sector (usually 63).

I usually add Linux to my Windows boot menu to avoid accidentally breaking Windows booting. I am much more likely to change Linux than Windows. Also, I primarily use Windows. No offense to those who primarily use Linux.

If you are using LILO, you must update the boot sector after each time you use the "lilo" command. I recommend using GRUB if you are going to chain from Windows to Linux.

To avoid the LILO problem you can install LILO to the partition boot sector, set the "boot" flag for that partition, and then save the default MBR software in the "bootsect.lnx" file. After saving the file, set the "boot" flag for the Windows partition so that Windows boots first. To use the default MBR software from the second hard disk you may have to patch "bootsect.lnx" to specify BIOS ID 0x81. LILO's boot sectors detect the "boot disk" BIOS ID and adjust correctly as long as all the files are on the same disk with the boot sector. The default MBR software usually assumes BIOS ID 0x80.

oskar 03-22-2013 01:28 PM

Quote:

Originally Posted by mddesai (Post 4916530)
If i had two hdd as you have, i would have done:
  1. disconnect 160GB HDD. create two partition on 1TB HDD, install Win7 32 and 64 bit.
  2. disconnected 1TB and connect 160GB HDD, install Ubuntu.
  3. connect all and during boot i would press F12 and select OS type. no unnecessary grub/bootloader problem.

That's a good idea.
I could just disconnect all but the ubuntu drive, do a boot-repair from a live cd, then only connect the win7(64) drive and do a fixmbr, and then I can toss out the 160gig drive and just boot select with F8 on startup (it's F8 on my motherboard)... and then I can easily update grub later if I want to.

It's really cool that you guys give so much detail. Even if I don't end up using it, I can bookmark and use as reference. ♥

I'll mark OP as solved since we have three workable solutions already :D
So thanks again!


All times are GMT -5. The time now is 12:30 AM.