SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-10-26 14:25:12

machinebacon
#! unstable
From: PRC
Registered: 2009-07-02
Posts: 6,272
Website

GRUB repair script

Ikey Doherty of SolusOS has written a nice little script that can rebuild your GRUB from a live CD. Thought I share it here, it's a useful little thing that should be a default on every live CD/USB.

http://main.solusos.com/entry.php?32-Se … air-Script

#!/bin/bash
 
GRUB_TARGET="/mnt/repairs"
 
setup () {
if [[ ! -d "$GRUB_TARGET" ]]; then
mkdir -p "$GRUB_TARGET"
fi
}
 
bind_it () {
mount --bind $1 $2
}
 
 
read -p "Please enter the device you wish to install grub to (MBR): "
DEVICE_INST="$REPLY"
read -p "Please enter the partition device node on which your installation exists (Your linux install): "
PARTITION_INST="$REPLY"
setup
 
# Attempt mount
mount "$PARTITION_INST" "$GRUB_TARGET"
if [[ $? != 0 ]]; then
echo "Could not mount the device. Aborting"
exit 1
fi
 
for mountpoint in "/dev/" "/dev/pts" "/dev/shm" "/proc" "/sys"; do
bind_it "$mountpoint" "$GRUB_TARGET$mountpoint"
done
 
# run teh commands
chroot "$GRUB_TARGET" "grub-install" "$DEVICE_INST"
chroot "$GRUB_TARGET" "update-grub"
 
for mountpoint in "/dev/pts" "/dev/shm" "/dev" "/proc" "/sys"; do
umount "$GRUB_TARGET$mountpoint"
done
 
umount "$GRUB_TARGET"

Kudos to Ikey!

(To find out which of your drives and partitions carries which device name, use 'blkid' or 'fdisk -l')

Last edited by machinebacon (2012-10-26 14:26:19)


Start Distrohopping here! -> Roast your ownVSIDO | LinuxCNC | AntiX | <-

Keep it what way?

Offline

Be excellent to each other!

#2 2012-10-26 15:12:50

VastOne
#! Ranger
From: #! Fringe Division
Registered: 2011-04-26
Posts: 9,891
Website

Re: GRUB repair script

Kudos to Ikey!  + 100

Thanks for sharing it machinebacon! cool


I agree, it should be a part of every Live/CD and repair tool CD

Heading over to SolusOS and thank Ikey!


VSIDO | LinuxBBQ
If you build it, they will come...
Words That Build Or Destroy

Offline

#3 2012-10-26 15:50:15

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 820

Re: GRUB repair script

I assume from this line that this script only works if you have GRUB installed to MBR on a MBR disk?

read -p "Please enter the device you wish to install grub to (MBR): "

Offline

#4 2012-10-26 16:10:13

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,493

Re: GRUB repair script

You can use  the script to install GRUB to a partition too - though it is not recommended. There are no validations in the script, so you can enter sda (for MBR) or sda1 (for PBR).

Last edited by xaos52 (2012-10-26 16:11:16)

Offline

#5 2012-10-26 21:59:18

ikey
Member
Registered: 2010-07-09
Posts: 31

Re: GRUB repair script

xaos52 wrote:

You can use  the script to install GRUB to a partition too - though it is not recommended. There are no validations in the script, so you can enter sda (for MBR) or sda1 (for PBR).

xaos52 is right, I never bothered adding any form of validation to it. Its essentially a simple wrapper around
an annoying fix. Lot of users aren't comfortable with faffing around with chroots. Wouldn't blame them,
If its wanted by people I dont mind making a simple tool with GUI and CLI for repairing GRUB. Possibly
add some auto-detection and error-handling

(Thanks for sharing it machinebacon smile)


If I were in America I could say "I love you, dad", the way they do in the films. But in Limerick they'd laugh at you. In Limerick you are only allowed to say you love God, and babies, and horses that win. Anything else is softness in the head

Offline

#6 2012-10-26 22:03:30

VastOne
#! Ranger
From: #! Fringe Division
Registered: 2011-04-26
Posts: 9,891
Website

Re: GRUB repair script

^ Thanks for the work ikey...

Top shelf Mate!


VSIDO | LinuxBBQ
If you build it, they will come...
Words That Build Or Destroy

Offline

#7 2012-10-26 22:05:08

ikey
Member
Registered: 2010-07-09
Posts: 31

Re: GRUB repair script

No problem good sir smile


If I were in America I could say "I love you, dad", the way they do in the films. But in Limerick they'd laugh at you. In Limerick you are only allowed to say you love God, and babies, and horses that win. Anything else is softness in the head

Offline

#8 2012-10-27 09:23:17

dan158
#! Member
Registered: 2012-06-08
Posts: 50

Re: GRUB repair script

I have a slight grub prob with two #! OS instances on this notebook. nothing serious it just is showing a Linux OS on my /sda MBA partition ... it even lets me boot to it but cant find a /home directory to open so it opens a root terminal prompt.

Would this script reinstall grub to my MBA? and:
where this script asks for your linx install partition; What do I do for 2 os's? is that even a prob?
(I'm assuming "update-grub would find the second OS, but I've learned to ask before pushing buttons... sometimes ... smile today anyways).

Offline

#9 2012-10-27 15:20:02

VastOne
#! Ranger
From: #! Fringe Division
Registered: 2011-04-26
Posts: 9,891
Website

Re: GRUB repair script

^ Are you saying that grub is installed and is running from the linux install that is only booting to terminal?

If you are on the working linux OS... all you have to do to install grub to the MBA is:

sudo grub-install /dev/sda

It does an update-grub when it installs and finds everything, including the one that is not booting correctly.

If you no longer want that OS to not show up in grub, you will need to either remove (format) the partition it is on or remove the kernel files from it's /etc/boot directory.


VSIDO | LinuxBBQ
If you build it, they will come...
Words That Build Or Destroy

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo