PDA

View Full Version : [edubuntu] Back up and restore GRUB



viktorjano
March 19th, 2012, 01:21 PM
Hi!

I have a machine with Windows XP and Edubuntu 11.10. Now I want to install Windows Server 2003 on place of WIndows XP. But I had problem with backing up and restoring the GRUB. I've searched on internet for some good tutorial but have no luck. Will someone be that nice to send some link or write down the sequence of backing up and restoring the GRUB.

Thanx!!!

darkod
March 19th, 2012, 01:55 PM
Backup is not necessary since windows will only overwrite a small part of grub2 that is on the MBR.

You can reinstall that part back from live mode in terminal with:

sudo mount /dev/sda5 /mnt
sudo grub-install --root-directory=/mnt /dev/sda

NOTE: In the first command you need to use your correct root partition instead of /dev/sda5 if it's different. In the second command there should not be a number in /dev/sda, you install onto the MBR not a partition.

viktorjano
March 19th, 2012, 02:17 PM
OK thanks,

that's something. You know so far all the time I came accross to some really cumbersome explanations. OK I'll give a try, hopefully it works!


Backup is not necessary since windows will only overwrite a small part of grub2 that is on the MBR.

You can reinstall that part back from live mode in terminal with:

sudo mount /dev/sda5 /mnt
sudo grub-install --root-directory=/mnt /dev/sda

NOTE: In the first command you need to use your correct root partition instead of /dev/sda5 if it's different. In the second command there should not be a number in /dev/sda, you install onto the MBR not a partition.

viktorjano
April 3rd, 2012, 01:42 PM
Hey Darko!!!
Listen, I've tried the code that you wrote earlier, but it does not work!
I've booted in live mode with SystemRescueCD, and mounted the root partition of my installed Ubuntu 11.10 on the /mnt folder. So far, it all went good. After that I've run the grub-install command exactly as you wrote, but when I rebooted, it couldn't run nothing. It only initiates the grub stage 1.5 and stays only grub, like

grub>

waiting for a command.
Please help, because I can not use my computer now!!!

shumifan50
April 3rd, 2012, 05:47 PM
You have lost your grub configuration file and this will have to be rebuilt. I don't know of a shortcut to d this. A lot depends on how much work you have on your Linux after installation.
IF ANYBODY EVER TELLS YOU TO OVERWRITE YOUR MBR IGNORE THEM!!!!!!!!!!!!
I think re-installing Linux might recover your GRUB install, depends on whether the install finds the WINDOWS partition and boot code.

Alternatively you can try to fix the grub config file:
Boot from Ubuntu CD and select 'Try Ubuntu'.

The grub configuration file is located at <boot partition>/boot/grub/grub.cfg. The boot partition is most likely /dev/sda1.
1. Find available partitions and device names
ls -l /dev/disk/by-uuid
This will give a list of UUIDs and device names. Although not guaranteed /dev/sda3 is most likely your Windows partition(the boot one, you might have more). You can check this by mounting it and looking for the Windows directory (dont make any changes on the mounted directory).
sudo mkdir /test
sudo mount /dev/sdax /test (vary sdax as sda1, sda2 sda3 etc)
ls /test
Note which partition the windows directory is on.
Now do a similar thing to find the Linux partitions and note them. Look for vmlinuz.

Now you can set up grub.cfg. Normally making a backup is advised, but as yours is already broken there is no need. Fix the UUID to reflect the UUID of the partitions you found the Windows and Ubuntu on and save the file then try to boot.
An example file follows with UUIDs marked in red:


#
# 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 ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set 096429b0-2da7-4fdb-8a45-2956cceafa35
if loadfont /usr/share/grub/unicode.pf2 ; then
set gfxmode=640x480
load_video
insmod gfxterm
fi
terminal_output gfxterm
insmod part_msdos
insmod ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set 096429b0-2da7-4fdb-8a45-2956cceafa35
set locale_dir=($root)/boot/grub/locale
set lang=en
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 ###
menuentry 'Ubuntu, with Linux 2.6.35-32-generic' --class ubuntu --class gnu-linux --class gnu --class os {

recordfail
insmod part_msdos
insmod ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set 096429b0-2da7-4fdb-8a45-2956cceafa35
linux /boot/vmlinuz-2.6.35-32-generic root=UUID=096429b0-2da7-4fdb-8a45-2956cceafa35 ro quiet splash
initrd /boot/initrd.img-2.6.35-32-generic
}
menuentry 'Ubuntu, with Linux 2.6.35-32-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod part_msdos
insmod ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set 096429b0-2da7-4fdb-8a45-2956cceafa35
echo 'Loading Linux 2.6.35-32-generic ...'
linux /boot/vmlinuz-2.6.35-32-generic root=UUID=096429b0-2da7-4fdb-8a45-2956cceafa35 ro single
echo 'Loading initial ramdi096429b0-2da7-4fdb-8a45-2956cceafa35 ro single
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-2.6.35-32-generic
}
menuentry 'Ubuntu, with Linux 2.6.35-22-generic' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod part_msdos
insmod ext2
set root='(hd0,msdos2)'
search --no-floppy --fs-uuid --set 096429b0-2da7-4fdb-8a45-2956cceafa35
linux /boot/vmlinuz-2.6.35-22-generic root=UUID=096429b0-2da7-4fdb-8a45-295096429b0-2da7-4fdb-8a45-2956cceafa35 ro quiet splash
initrd /boot/initrd.img-2.6.35-22-generic
}

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Microsoft Windows XP Professional (on /dev/sda1)" {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set 989436CE9436AF1E
drivemap -s (hd0) ${root}
chainloader +1
}
### END /etc/grub.d/30_os-prober ###

oldfred
April 3rd, 2012, 06:08 PM
You must not have followed Darko's instructions as those are for reinstalling grub2's boot loader to the MBR of sda and 11.10 should be using grub2.

But your error message if grub stage 1.5 is from grub legacy. It is now best with grub2 version 1.99 to use the same version to reinstall, so the Ubuntu liveCD is preferred. You may now have both grub legacy & grub2 installed and have to cleanly uninstall both and reinstall just grub2.

Using system rescue may require a full chroot to use the internal commands of your install to repair.

Download this into your liveCD and post the link to a run of bootinfoscript.
Boot Repair:
https://help.ubuntu.com/community/Boot-Repair
You can repair many boot issues with this or post the link to a run of boot info script so we can see your exact configuration.

If you have to houseclean both grubs.
HOWTO: Purge and Reinstall Grub 2 from the Live CD
http://ubuntuforums.org/showthread.php?t=1581099

Reinstall grub2 - Short version & full chroot version
https://help.ubuntu.com/community/Grub2#Reinstalling%20GRUB2
Grub2 info & full chroot version - also see METHOD 3 - CHROOT:
https://wiki.ubuntu.com/Grub2#Recover%20Grub%202%20via%20LiveCD