LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-18-2015, 07:11 AM   #1
mangya
Member
 
Registered: Jul 2015
Distribution: CentOS
Posts: 89

Rep: Reputation: Disabled
Installing GRUB in MBR


Hello

I'm trying to install grub to a broken mbr. This is the part of my learning and the linux distro is CentOS 7 minimal running in virtualbox.

I want to try this in various ways.

First I booted from CentOS DVD's Rescue mode and installed mbr successfully by grub2-install command.

Then, I tried through SystemRescueCD. Installed GRUB perfectly. Following are the steps:

Code:
% mkdir linux

% vgchange -a y VolGroup

% mount /dev/mapper/VolGroup-root linux
% mount /dev/sda1 linux/boot

% mount -o bind /proc linux/proc
% mount -o bind /dev linux/dev
% mount -o bind /sys linux/sys

% chroot linux /bin/bash

# grub2-install /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported
However, when I tried this in Knoppix Rescue DVD, even though every step is exactly same, I'm getting error at chroot

Code:
# mkdir linux

# vgchange -a y VolGroup

# mount /dev/mapper/VolGroup-root linux
# mount /dev/sda1 linux/boot

# mount -o bind /proc linux/proc
# mount -o bind /dev linux/dev
# mount -o bind /sys linux/sys

# chroot linux /bin/bash
chroot: failed to run command `/bin/bash': Exec format error

# chroot linux /bin/sh
chroot: failed to run command `/bin/sh': Exec format error

# chroot linux
chroot: failed to run command `/bin/bash': Exec format error
What I'm doing wrong? Please help.

Thanks
 
Old 07-18-2015, 10:51 AM   #2
Aia
Member
 
Registered: Jun 2006
Posts: 66

Rep: Reputation: 21
Quote:
The error Exec format error means that the binary being executed is made for a different architecture than the environment currently booted. It usually occurs when the system has been booted on a 32-bit system when a 64-bit environment is trying to load.
Source
 
1 members found this post helpful.
Old 07-18-2015, 11:16 AM   #3
mangya
Member
 
Registered: Jul 2015
Distribution: CentOS
Posts: 89

Original Poster
Rep: Reputation: Disabled
@Aia Thanks man! it was really very helpful. Booted Knoppix with boot-code knoppix64 and it worked flawlessly.

Thanks
 
Old 07-18-2015, 11:16 AM   #4
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
You need to be running a 64 bit kernel to chroot into a 64 bit linux. You could use grub on a USB stick and boot the install on the device on bare metal instead of doing the chroot. If grub is on that device but not the MBR, you can chainload the other grub's configuration in grub. And other options.

GRUB> configfile (hd0,1)/boot/grub/grub.cfg

where the (hd0,1) is the device and partition for the other grub. As hinted to from GRUB> ls
 
Old 07-18-2015, 11:36 AM   #5
mangya
Member
 
Registered: Jul 2015
Distribution: CentOS
Posts: 89

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Shadow_7 View Post
You need to be running a 64 bit kernel to chroot into a 64 bit linux. You could use grub on a USB stick and boot the install on the device on bare metal instead of doing the chroot. If grub is on that device but not the MBR, you can chainload the other grub's configuration in grub. And other options.

GRUB> configfile (hd0,1)/boot/grub/grub.cfg

where the (hd0,1) is the device and partition for the other grub. As hinted to from GRUB> ls
Thanks for your reply. But till now, I am trying to repair Grub at stage 1. So I don't even get GRUB> prompt. I am getting 'No bootable medium found' error.

I'm deliberately removing mbr by
Code:
dd if=/dev/zero of=/dev/sda bs=446 count=1
I think I can use your solution at grub's stage 2 error. I'm still learning grub.

Anyway, thanks.
 
Old 07-18-2015, 06:00 PM   #6
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
Grub is just a boot loader, which can exist on ANY bootable medium. You can select which drive to boot as primary in most BIOS/UEFI implementations. And you can boot USB devices on most x86 machines since 2006. A grub implentation can exist on said USB mediums. If a linux also exists on said medium you can boot the linux on usb, run update-grub and boot the usb again and select the thing to boot from grubs menu (the grub on the USB drive). Mostly the same as your chroot method. Except you actually boot the distro instead of using chroot. Back in the day you'd have to use grub on a cdrom to boot from usb for machines that didn't support booting usb. Many means to an end.
 
  


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
Re-installing Grub on the MBR satyakb Mandriva 1 02-29-2008 06:07 AM
help on installing grub on mbr Paxmaster Linux - Software 6 01-10-2007 10:47 PM
Installing grub to root not mbr. acidblue Fedora 4 05-24-2006 07:48 PM
will installing grub to my MBR screw up anything? colinexl Linux - Newbie 2 01-13-2005 11:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:33 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