Page 1 of 22 12311 ... LastLast
Results 1 to 10 of 211

Thread: HOWTO: Purge and Reinstall Grub 2 from the Live CD

  1. #1
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    HOWTO: Purge and Reinstall Grub 2 from the Live CD

    HOWTO: Purge and Reinstall Grub 2 from the Live CD


    There are several ways to repair Grub 2. In this post, we will completely remove and then reinstall Grub 2 using an Ubuntu Desktop Installation CD, which I will refer to as the Live CD.

    Note: If you can get to your normal installation without using a Live CD the chroot procedure is not necessary and you need only Steps 2-5.

    I would recommend this procedure only after running meierfra's boot info script and finding no obvious discrepancies. The reasons for this include:
    • During this procedure, you will temporarily have no bootloader on your system.
    • If you designated the wrong drive/partition during the initial install, you may make the same mistake again.
    • You will lose any customizations you have made to your Grub 2 configuration files.
    • Other methods, such as "grub-install" or "grub-install --reinstall" are less intrusive on your system. Doing the least necessary to fix a system is generally a good idea.

    This thread is primarily for reference. If you need help interpreting the output of the boot info script, please start your own thread in one of the other forums. Depending on your experience level, Absolute Beginners or Installation & Upgrades might be appropriate forums.

    What can I try first?

    Boot Repair (GUI)
    There is a GUI application created by forum member YannBuntuthat can, among other things, reinstall Grub2 (rewrite to the MBR and generate a new core.img file), or to completely purge and reinstall Grub 2 in the Advanced Options (you will still have to enter one command in the terminal). The "Boot Repair" information for now can be found in Post #171 of this thread:
    http://ubuntuforums.org/showthread.p...7#post10871917

    From the Normal OS (not Live CD).
    • Change the BIOS boot order. If you installed Grub 2 from another device, changing the boot order to the original installing device may find a bootable Grub installation. Once booted and in your normal Ubuntu system, run "sudo dpkg-reconfigure grub-pc" and select additional devices on which to write Grub 2. Example: If you installed to your interneal hard drive from a USB drive, change the BIOS to boot from the USB drive first. If Ubuntu now boots, run the dpkg-reconfigure command and be sure to include the internal drive in the "Grub install devices" options.
    • Reinstalling Grub 2 may be another option. A reinstall will rewrite the MBR and refresh the modules in the boot/grub folder. The "update-grub" command should be run as root after installing Grub 2, as the grub.cfg file is not generated by the installation.
    • Replace the X value (sda, sdb, etc). This is normally the drive with the Ubuntu OS. This should be the drive the computer's BIOS boots. The command assumes the /boot folder is not on a separate partition. These commands should not be run from a Live CD.
      Code:
      sudo grub-install --recheck /dev/sdX
      sudo update-grub

    From the Live CD:

    Important Note on Using a LiveCD:
    Please use a LiveCD with the same version of Grub 2 as the OS if you are going to run "grub-install" without 'chrooting'. Not doing so may break or fail to fix the problem. Natty uses Grub 1.99RC. Lucid/Maverick use Grub 1.98. If Grub files are to be copied or installed to the actual OS, users of Lucid/Maverick should use a Lucid or Maverick LiveCD to repair Grub. Natty users should use a Natty LiveCD. Once 'chrooted' into the real installation, the installation's repositories will be used if packages are downloaded and installed regardless of the CD.

    • If the Ubuntu OS cannot be accessed through the normal boot process (see above), boot a compatible installation CD/Live CD. The Grub 2 files are by default installed in the partition's /boot/grub folder and will be placed in this folder if the commands are run as instructed.

      Note 1: Running "update-grub" from the Live CD will not update the grub.cfg file of the normal installation. If the grub.cfg file is damaged or missing, the user should use the chroot procedure below to update the grub.cfg file.

      Note 2: In the following commands, the Ubuntu partition (sda1, sda5, etc) is mounted in the first command, but only the drive (sda, sdb, etc) is designated in the 'grub-install' command.

      Note 3: The middle commands are to be run only if the operating system has a separate partition specifically for /boot. This would normally not be the case.

      If you have a separate /boot partition run these two commands first. Most users do not have a separate /boot partition. sdXZ is the boot partition.
      Code:
      ### Run these two commands only if you have a separate /boot partition
      sudo mkdir /mnt/boot
      sudo mount /dev/sdXZ /mnt/boot  # Example: sudo mount /dev/sda6 /mnt/boot
      
      Code:
      sudo mount /dev/sdXY /mnt  # Example: sudo mount /dev/sda5 /mnt
      sudo grub-install --root-directory=/mnt /dev/sdX # Example: sudo grub-install --root-directory=/mnt /dev/sda



    Purge & Reinstall without Chroot
    If you wish to purge and reinstall Grub 2 from a normally running installation it is not necessary to use the chroot instructions. Following a normal boot (without the Live CD):
    • Complete only steps 2 through 5.
    • Include "sudo" at the start of each command. Example: sudo apt-get purge grub grub-pc grub-common


    Chroot

    The following is the textual explanation of how to 'chroot' and install Grub 2 from the LiveCD. For an easy-to-understand summary including graphics, the following site does a very good job - complete with illustrations:
    http://opensource-sidh.blogspot.com/...ubuntu-cd.html

    Since you will boot from the Live CD, commands executed in the normal manner would act on the Live CD's temporary system files and not the files on your real installation's partition. By 'chroot-ing' into your Ubuntu partition, the commands will act on your installation and remain after you remove the CD and reboot. Use a LiveCD with the same version of Grub 2 (see note near the top of this post).

    Procedure: *
    Boot to the Live CD Desktop and open a terminal (Applications, Accessories, Terminal).

    * If you can boot to your normal Ubuntu installation and wish to purge and reinstall Grub 2, see the section "Purge & Reinstall without Chroot".

    A note about copying: Copying these commands is easier and more accurate than typing. To paste into a linux terminal, highlight the text with your mouse, then click in the terminal with your middle mouse button to paste the contents. It's that simple!. If you prefer to use the keyboard, paste into the terminal with CTRL-SHIFT-V.


    Important: All instances of sdX and sdXY must be replaced with the correct drive/partition for your system. (sda, sdb, sda1, sda5, sdb5, etc). X is the drive letter. Y is the partition number. The first drive is "a" and the first partition is "1". Example: sda1


    1. Chroot into your real system. The following set of commands will mount the necessary system files to allow the chroot and place you in a terminal where the commands will work on your real installation. Note the middle two commands are to be run ONLY IF you have a separate partition specifically for /boot. Copying the resolv.conf file may help establish an Internet connection.

    Note: The "for i in ... line is a command that needs to be run. It is an efficient way to mount multiple items using a single line of code. I have added a section at the end of this post showing what the command does. *

    Change sdXY to correct value (for example, sda5, sdb1, etc.).

    Mounting Instructions:
    When mounting the partitions, use A (separate /boot partition), B (Wubi only), or C (normal installtion).
    Once you have completed the mounting instructions in the section that applies to your installation, go to Continue.

    1. Only If You Have a Separate /boot partition.
      If you have a separate /boot partition run these commands. Most users do not have a separate /boot partition and should go to the normal partition section. sdXY is the main partition. sdXZ is the boot partition.
      Code:
      sudo mkdir /mnt/temp /mnt/temp/boot  
      sudo mount /dev/sdXY /mnt/temp  # Mount the main Ubuntu partition. Example: sudo mount /dev/sda5 /mnt/temp
      sudo mount /dev/sdXZ /mnt/temp/boot  # Mount the /boot partition. Example: sudo mount /dev/sda6 /mnt/temp/boot
    2. Only If You Are Running WUBI (Ubuntu inside Windows)
      It is possible to chroot into a Wubi install by first mounting your Windows partition, and then mounting the Windows Wubi file, root.disk. The user must determine the value of the Window partition (sda1, sda2, etc). This section only applies to users booting an Ubuntu OS installed within Windows.
      Code:
      sudo mkdir /mnt/windows /mnt/temp  # Make the mount points
      sudo mount /dev/sdXY /mnt/windows  # Mount the Windows partition. Example: sudo mount /dev/sda1 /mnt/windows
      sudo mount -o loop /mnt/windows/ubuntu/disks/root.disk /mnt/temp  # Mount the root.disk file.
    3. If You Have a Normal Installation. No separate /boot partition, not a Windows/Wubi installation.
      Code:
      sudo mkdir /mnt/temp 
      sudo mount /dev/sdXY /mnt/temp  # Example: sudo mount /dev/sda5 /mnt/temp


    Continue from A, B or C.
    At this point the Ubuntu installation should be mounted on /mnt/temp. The next step is to mount certain items in preparation of the chroot. The "for i in ..." is a command that will mount these items and must be run.
    Code:
    for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt/temp$i;  done
    sudo cp /etc/resolv.conf /mnt/temp/etc/resolv.conf  # May be required to connect to the Internet.
    sudo chroot /mnt/temp
    If the commands ran successfully, the terminal prompt should include "root" ( root@ubuntu:/# ), which indicates you are in the chroot environment.


    2. Confirm an Internet connection.*** This is necessary to retrieve the necessary Grub packages.
    Code:
    
    apt-get update   # ***
    • *** Unless an Internet connection can be established, do not run the Section 3 commands - the packages will not download and you will be left without a bootloader! For an alternative procedure, see "Reconfiguring Grub 2 without an Internet Connection" near the end of this post.
    • Internet failure means that your computer cannot connect to the Internet. If any repositories update you may safely continue to Section 3.



    3. Purge Grub 2 packages. The next command will remove grub, grub-pc (Grub 2) and grub-common.* Here is what you will do:
    1. Press ENTER to continue.
    2. Read the warning during the install about removing the bootloader. TAB to highlight "<Yes>" and press ENTER.

    * If you are sure you have never had Grub legacy on the current installation you may omit "grub" from the next command (apt-get purge grub-pc grub-common).

    Code:
     
    apt-get purge grub grub-pc grub-common

    4. Reinstall the grub packages. Here is what will happen:
    1. You will be given the opportunity to add extra kernel options to the kernel line. If you don't know, you probably don't need them ; TAB to highlight "<OK>" and press ENTER.
    2. Read the installation notes. TAB to "<OK>" to continue.
    3. When presented with the device option, use the UP/DN keys to select the correct drive (sdX).
      • Make sure the installation drive [*] /dev/sdX has an asterisk next to it ( example: [*] /dev/sda ). If it doesn't, highlight it and press the SPACE bar to select it.
      • Do not select a partition ( example: [ ] /dev/sda5 , etc).
    4. TAB to "<OK>" and press ENTER. When it has finishing the installation, you should have Grub 2 installed.


    Code:
    apt-get install grub-common grub-pc

    5. Update the Grub 2 files . This command shouldn't be necessary, but it won't hurt to update Grub once more before exiting.
    Code:
     
    update-grub 

    6. Exit the chroot environment.
    Code:
    exit
    If you have successfully exited chroot, the terminal prompt should return to the Ubuntu Live CD prompt ( ubuntu@ubuntu:~$ )


    7. Unmount what you previously mounted.*
    Code:
    for i in /dev/pts /dev /proc /sys; do sudo umount /mnt/temp$i ; done
    * If you mounted a separate /boot partition, run this instead:
    Code:
    for i in /dev/pts /dev /proc /sys /boot; do sudo umount /mnt/temp$i ; done

    8. Reboot your system.


    Reconfiguring Grub 2 without an Internet Connection.

    1. Complete Sections 1 and 2 above. If the update-grub command fails to connect to the Internet after chrooting, use the procedures below while still in the chroot environment.

      *** Caution: Running the Step 3 commands above without an Internet connection will leave you without a bootloader!

    2. If you entered the chroot without copying the /etc/resolv.conf file, you can try to correct the Internet problem by doing so now. The following commands will exit chroot, copy the additional file, and then return to the chroot environment.
      Code:
      exit  
      sudo cp /etc/resolv.conf /mnt/temp/etc/resolv.conf
      sudo chroot /mnt/temp 
      update-grub
      If you can now connect to the Internet, return to Step 3. With no connection, run only the remaining commands below.

    3. Review the notes in Step 4 above, as you will be presented with several screens awaiting user input.
      Code:
      dpkg-reconfigure grub-pc
    4. Update the Grub 2 files . This command shouldn't be necessary, but it won't hurt to update Grub once more before exiting.
      Code:
       
      update-grub 
    5. Exit the chroot environment:
      Code:
      exit
      If you have successfully exited chroot, the terminal prompt should return to the Ubuntu Live CD prompt ( ubuntu@ubuntu:~$ )

    6. Unmount what you previously mounted.
      Code:
      for i in /dev/pts /dev /proc /sys ; do sudo umount /mnt/temp$i ; done
    7. Reboot your system.


    * Explanation of the "for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt/temp$i; done"
    This command is the equivalent of:
    Code:
    sudo mount --bind /dev /mnt/temp/dev
    sudo mount --bind /dev/pts /mnt/temp/dev/pts
    sudo mount --bind /proc /mnt/temp/proc
    sudo mount --bind /sys /mnt/temp/sys
    Last edited by drs305; June 11th, 2011 at 12:20 AM. Reason: LiveCD version compatibility.
    Back to Xorg...

    Retired.

  2. #2
    Join Date
    Aug 2007
    Location
    a puddle in Manchester
    Beans
    9,198
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: HOWTO: Purge and Reinstall Grub 2 from the Live CD

    Nice one D. Got me out of the mire again!
    MacBook Pro 10,1 retina

  3. #3
    Join Date
    Sep 2010
    Beans
    3
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: HOWTO: Purge and Reinstall Grub 2 from the Live CD

    Well I insert the live cd it seems like its going to work
    Then I get this issue
    (Initramfs) mount: mounting /dev/loop0 on //filesystem.squashfs failed: input/output error
    Can not mount /dev/loop0 (/cdrom/casper/filesystem.squashfs) on //filesystem.squashfs

    What should I do?

  4. #4
    Join Date
    Oct 2010
    Beans
    2

    Re: HOWTO: Purge and Reinstall Grub 2 from the Live CD

    What to do if the LVM is encrypted?

  5. #5
    Join Date
    Oct 2010
    Beans
    1

    Lightbulb Re: HOWTO: Purge and Reinstall Grub 2 from the Live CD

    For me, I have the boot partition on sda1 and the root partition on sda2.

    In this case, I first had to mount the _root_ fs of sda2 and also /dev, /dev/pts, /proc and /sys of the root fs as described here, and then, before continuing, I _additionally_ had to mount the boot fs:

    mount sda1 /mnt/temp/boot

    Otherwise I got a grub prompt with no kernes found.

  6. #6
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: HOWTO: Purge and Reinstall Grub 2 from the Live CD

    Quote Originally Posted by holgerhom View Post
    For me, I have the boot partition on sda1 and the root partition on sda2.

    In this case, I first had to mount the _root_ fs of sda2 and also /dev, /dev/pts, /proc and /sys of the root fs as described here, and then, before continuing, I _additionally_ had to mount the boot fs:

    mount sda1 /mnt/temp/boot

    Otherwise I got a grub prompt with no kernes found.
    holgerhom, thanks for contributing. I have instructions on separate /boot partitions on some of my other Grub2 guides but didn't include them here. When I have a bit of time I'll include a mention here as well. Thank you for pointing this out.
    Back to Xorg...

    Retired.

  7. #7
    Join Date
    Dec 2009
    Location
    Provo
    Beans
    9
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Purge and Reinstall Grub 2 from the Live CD

    I did the apt-get update, and thought I had an Internet connection. The terminal said:
    Code:
    Fetched 150kB in 6s (24.1kB/s)
    So, then I ran the purge command, and when I try to run
    Code:
    apt-get install grub-common grub-pc
    the output says
    Code:
    E: Unable to locate package grub-common
    E: Package 'grub-pc' has no installation candidate
    So, I'm kind of stuck at this point. I tried an ifconfig while still in chroot, and it shows connectivity, but I don't know if that means that the mounted drive has connectivity or just the live CD (or in my case Live USB drive). At any rate, I need help. Thanks.

  8. #8
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: HOWTO: Purge and Reinstall Grub 2 from the Live CD

    Quote Originally Posted by smfoote View Post
    So, I'm kind of stuck at this point. I tried an ifconfig while still in chroot, and it shows connectivity, but I don't know if that means that the mounted drive has connectivity or just the live CD (or in my case Live USB drive). At any rate, I need help. Thanks.
    Did you run the apt-get command from within the chroot and did the normal repository lists sroll down the screen? If you aren't sure if your chroot has Internet, "ping google.com", CTRL-c to stop the returns.

    If you don't have a connection, take a look at Section 8 about copying resolv.conf and try it again. You can also check your repository list in the chroot environment with:
    Code:
    cat /etc/apt/sources.list | grep -v "#"
    Make sure you have main enabled.

    It's ok to exit and enter the chroot environment, but don't reboot the system until we can get grub-pc reinstalled.

    Added: Your profile shows Maverick, so my assumption is that you are using Grub2. You can always try running "apt-get install grub" if Grub legacy is what you are really running.
    Last edited by drs305; October 15th, 2010 at 12:45 AM.
    Back to Xorg...

    Retired.

  9. #9
    Join Date
    Dec 2009
    Location
    Provo
    Beans
    9
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Purge and Reinstall Grub 2 from the Live CD

    I definitely have Internet connection. The ping worked just fine. Here is the output of the cat /etc/apt/sources.list

    deb http://us.archive.ubuntu.com/ubuntu/ maverick main restricted
    deb-src http://us.archive.ubuntu.com/ubuntu/ maverick main restricted
    deb http://us.archive.ubuntu.com/ubuntu/ maverick-updates main restricted
    deb-src http://us.archive.ubuntu.com/ubuntu/ maverick-updates main restricted
    deb http://us.archive.ubuntu.com/ubuntu/ maverick universe
    deb-src http://us.archive.ubuntu.com/ubuntu/ maverick universe
    deb http://us.archive.ubuntu.com/ubuntu/ maverick-updates universe

    Copying from the terminal seems to have messed up the formatting a bit. sorry. Trying to install grub-common and grub-pc continues to fail for the same reasons mentioned above, and trying to install grub also fails.
    Last edited by smfoote; October 15th, 2010 at 02:12 AM. Reason: Formatting

  10. #10
    Join Date
    Jan 2007
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: HOWTO: Purge and Reinstall Grub 2 from the Live CD

    The repositories look correct and grub-common and grub-pc are contained therein - I checked.

    Try downloading the files from this location. I don't know if your install has the dependencies already but we can see:

    Maverick 32-bit:
    Code:
    wget http://mirrors.kernel.org/ubuntu/pool/main/g/grub2/grub-common_1.98+20100804-5ubuntu3_i386.deb  # grub-common
    wget http://mirrors.kernel.org/ubuntu/pool/main/g/grub2/grub-pc_1.98+20100804-5ubuntu3_i386.deb  # grub-pc 32-bit
    Maverick 64-bit:
    Code:
    wget http://mirrors.kernel.org/ubuntu/pool/main/g/grub2/grub-common_1.98+20100804-5ubuntu3_amd64.deb  # 64-bit grub-common
    wget http://mirrors.kernel.org/ubuntu/pool/main/g/grub2/grub-pc_1.98+20100804-5ubuntu3_amd64.deb  # 64-bit grub-pc
    Install grub-common first, then grub-pc, with:
    dpkg -i <filename.deb>
    You can use TAB-completion to complete the filename. (Example: type dpkg -i grub-common then TAB to complete the name.
    Back to Xorg...

    Retired.

Page 1 of 22 12311 ... LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •