You are not logged in.
Pages: 1
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 own | VSIDO | LinuxCNC | AntiX | Frugalware | <-
Online
Kudos to Ikey! + 100
Thanks for sharing it machinebacon! 
I agree, it should be a part of every Live/CD and repair tool CD
Heading over to SolusOS and thank Ikey!
VSIDO
If you build it, they will come...
Words That Build Or Destroy
Offline
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
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)
bootinfoscript - emacs primer - I ♥ #!
Offline
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
)
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
No problem good sir 
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
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 ...
today anyways).
Offline
^ 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/sdaIt 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
If you build it, they will come...
Words That Build Or Destroy
Offline
Pages: 1
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.