Author: Not specified Language: text
Description: Not specified Timestamp: 2012-07-18 15:21:08 -0400
View raw paste Reply
  1.  
  2. There may be times when a user needs to either move or reinstall a GRUB 2 installation. GRUB 2 needs to be reinstalled when a user is presented with a blank screen with only the word "GRUB", no prompt, and no ability to enter commands. This often happens when the MBR of the booting device is altered and GRUB 2 is removed, such as when Windows is installed after Ubuntu. Additionally, if a user cannot boot into an operating system at all, even using the rescue mode mode, a complete reinstallation of GRUB 2 may be necessary.
  3.  
  4. If you cannot boot from GRUB 2 review the section Rescue Mode ("grub rescue>") Booting.
  5.  
  6. Methods of Reinstalling
  7.  
  8. There are various methods; some require booting from a LiveCD. The simplest method is presented first. If the first method does not work, follow the second or subsequent methods, which are more complex and contain more options and instructions.
  9.  
  10. As GRUB 2 has changed with each release, please try to use a LiveCD that has the same version of Grub2 as the installed version. However, since this is a reinstall it 'should' be possible to use older (or newer) versions too.
  11.  
  12. Use Boot-Repair Graphical Tool
  13.  
  14. To reinstall GRUB, just use the following graphical tool : Boot-Repair.
  15.  
  16. Boot-repair can be used either from a live-CD or from a normal session.
  17.  
  18. http://pix.toile-libre.org/upload/original/1299426403.png
  19.  
  20. Copy LiveCD Files
  21.  
  22. This is a quick and simple method of restoring a broken system's GRUB 2 files. The terminal is used for entering commands and the user must know the device name/partition of the installed system (sda1, sdb5, etc). The problem partition is located and mounted from the LiveCD. The files are then copied from the LiveCD libraries to the proper locations and MBR. It requires the least steps and fewer command line entries than the following methods. If for example Windows is on sda1 and Ubuntu is on sda5, and Windows has overwritten the MBR, then the target for grub installation will be /dev/sda5, and the MBR in the boot sector of sda will be re written for grub.
  23.  
  24. This operation will write to the MBR and restore the modules and core.img to /boot/grub. It will not replace or restore grub.cfg or fix corrupted files.
  25.  
  26.    1. Boot the LiveCD Desktop.
  27.    2.
  28.  
  29.       Open a terminal by selecting Applications, Accessories, Terminal from the menu bar.
  30.    3.
  31.  
  32.       Determine the partition with the Ubuntu installation. The fdisk option "-l" is a lowercase "L".
  33.          1.
  34.  
  35.             sudo fdisk -l
  36.  
  37.             If the user isn't sure of the partition, look for one of the appropriate size or formatting.
  38.  
  39.             Running sudo blkid may provide more information to help locate the proper partition, especially if the partitions are labeled. The device/drive is designated by sdX, with X being the device designation. sda is the first device, sdb is the second, etc. For most users the MBR will be installed to sda, the first drive on their system. The partition is designated by the Y. The first partition is 1, the second is 2. Note the devices and partitions are counted differently.
  40.    4. Mount the partition containing the Ubuntu installation.
  41.  
  42.       sudo mount /dev/sdXY /mnt
  43.  
  44.       Example: sudo mount /dev/sda1 Note: If the user has a separate /boot partition, this must be mounted to /mnt/boot Note: If the user has a separate /home partition, this must be mounted to /mnt/home. Encrypted home partitions should work.
  45.    5.
  46.  
  47.       Run the grub-install command as described below. This will reinstall the GRUB 2 files on the mounted partition to the proper location and to the MBR of the designated device.
  48.  
  49.       sudo grub-install --root-directory=/mnt /dev/sdX
  50.  
  51.       Example: sudo grub-install --root-directory=/mnt /dev/sda
  52.  
  53. In Grub 1.99, introduced with Ubuntu 11.04, Natty Narwhal, a new switch is available which more clearly defines where the grub folder is placed. The command above will still work with Grub 1.99, but the following command is preferred by the developers. The target directory in the command is the command into which the grub folder will be installed. By default, and without the switch, the location is /boot/grub. In these instructions, since the Ubuntu partition is mounted on /mnt, the target would be /mnt/boot/grub.
  54.  
  55.     *
  56.  
  57.       sudo grub-install --boot-directory=/mnt/boot /dev/sdX
  58.  
  59.       Example: sudo grub-install --boot-directory=/mnt /dev/sda
  60.     * Reboot
  61.     *
  62.  
  63.       Refresh the GRUB 2 menu with sudo update-grub
  64.     *
  65.  
  66.       If the user wishes to explore why the system failed, refer to Post-Restoration Commands section below.
  67.  
  68. Copy Partition Files
  69.  
  70. This is a quick and simple method of restoring a broken system's GRUB 2 files. The problem partition is located and mounted from the LiveCD. The files are then copied from the broken system's /boot/grub directory to the proper locations and MBR. It requires fewer steps and fewer command line entries than the following CHROOT method. For users with separate system partitions, such as a separate /boot partition, or other special circumstances, using the CHROOT method may provide better results.
  71.  
  72.    1. Boot to the LiveCD Desktop.
  73.    2. Mount the partition with your Ubuntu installation.
  74.          1.
  75.  
  76.             From the Places menu, select and click the partition containing your Ubuntu installation to mount it.
  77.                 *
  78.  
  79.                   grub2.places.devices.png
  80.                 * If the partition isn't recognized, look for one of the appropriate size or label.
  81.                 *
  82.  
  83.                   Once mounted, the user should see Ubuntu system directories such as /boot
  84.    3.
  85.  
  86.       Open a terminal by selecting Applications, Accessories, Terminal from the menu bar.
  87.    4.
  88.  
  89.       Run the grub-setup -d command as described below. This will reinstall the GRUB 2 files on the mounted partition to the proper location and to the MBR of the designated device.
  90.          1.
  91.  
  92.             Determine the mount point by referring to the location box in Places. Replace XXXX in the command with the UUID, or replace /media/XXXX with the correct location if the partition is not mounted in /media. The designation may be a UUID, or a label, if the user has created one (see note).
  93.          2. If the location window is not in the format shown, click on the icon to the left to change the presentation.
  94.                 *
  95.  
  96.                   grub2.places.location.png
  97.          3.
  98.  
  99.             When ready to copy the UUID/location, by highlighting it with the mouse. Paste it into the terminal by pressing the middle mouse button. If using the keyboard, use CTRL-SHIFT-arrow to select and CTRL-C to copy the location and CTRL-SHIFT-V to paste it into the terminal.
  100.          4.
  101.  
  102.             The device/drive is designated by sdX, with X being the device designation. sda is the first device, sdb is the second, etc. For most users the MBR should be installed to sda, the first drive on their system.
  103.  
  104.             sudo grub-setup -d /media/XXXX/boot/grub /dev/sda
  105.  
  106.             Example:
  107.  
  108.             sudo grub-setup -d /media/7848138a-41a0-4eba-8aed-d1b625ac8759/boot/grub /dev/sda
  109.          5.
  110.  
  111.             If the user gets a "error: Cannot open /boot/grub/device.map" message, add the -m switch and path to the device.map to the command as follows:
  112.  
  113.             sudo grub-setup -d /media/XXXXX/boot/grub -m /media/XXXXX/boot/grub/device.map /dev/sda
  114.  
  115.             Example:
  116.  
  117.             sudo grub-setup -d /media/7848138a-41a0-4eba-8aed-d1b625ac8759/boot/grub -m /media/7848138a-41a0-4eba-8aed-d1b625ac8759/boot/grub/device.map /dev/sda
  118.          6.
  119.  
  120.             Other switches are available for use with the grub-setup command. In a terminal, type grub-setup --help for a list of available options.
  121.          7.
  122.  
  123.             You may find you get a repeated "error: Cannot open /boot/grub/device.map" message. If this happens try rebooting. The UUID method may actually work but throws an error message falsely. Using the label name does not seem to evoke the same repeated error message.
  124.    5. Reboot
  125.    6.
  126.  
  127.       Refresh the GRUB 2 menu with sudo update-grub
  128.    7.
  129.  
  130.       If the user wishes to explore why the system failed, refer to Post-Restoration Commands section below.
  131.  
  132.       info.png Ubuntu 9.10 introduced a new application which can easily assign labels to existing partitions. Access Disk Utility from the System, Administration menu.
  133.  
  134. ChRoot
  135.  
  136. This method of installation uses the chroot command to gain access to the broken system's files. Once the chroot command is issued, the LiveCD treats the broken system's / as its own. Commands run in a chroot environment will affect the broken systems filesystems and not those of the LiveCD.
  137.  
  138.    1. Boot to the LiveCD Desktop. The CD should be the same release and architecture (32/64 bit).
  139.    2.
  140.  
  141.       Open a terminal - Applications, Accessories, Terminal.
  142.    3. Determine your normal system partition - (the switch is a lowercase "L")
  143.  
  144.       sudo fdisk -l
  145.  
  146.           *
  147.  
  148.             If you aren't sure, run df -Th. Look for the correct disk size and ext3 or ext4 format.
  149.    4. Mount your normal system partition:
  150.           * Substitute the correct partition: sda1, sdb5, etc.
  151.  
  152.       sudo mount /dev/sdXX /mnt
  153.  
  154.           *
  155.  
  156.             Example: sudo mount /dev/sda1 /mnt
  157.    5.
  158.  
  159.       Only if you have a separate boot partition:
  160.           * sdYY is the /boot partition designation
  161.  
  162.       sudo mount /dev/sdYY /mnt/boot
  163.  
  164.           * Example: sudo mount /dev/sdb6 /mnt/boot
  165.    6. Mount the critical virtual filesystems. Run the following as a single command:
  166.  
  167.       for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
  168.  
  169.    7. Chroot into your normal system device:
  170.  
  171.       sudo chroot /mnt
  172.  
  173.    8. If there is no /boot/grub/grub.cfg or it's not correct, create one using
  174.  
  175.       update-grub
  176.  
  177.    9. Reinstall GRUB 2:
  178.           *
  179.  
  180.             Substitute the correct device - sda, sdb, etc. Do not specify a partition number.
  181.  
  182.       grub-install /dev/sdX
  183.  
  184.   10.
  185.  
  186.       Verify the install (use the correct device, for example sda. Do not specify a partition):
  187.  
  188.       grub-install --recheck /dev/sdX
  189.  
  190.   11.
  191.  
  192.       Exit chroot: CTRL-D on keyboard
  193.   12. Unmount virtual filesystems. Run the following as a single command:
  194.  
  195.       for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done
  196.  
  197.   13. If you mounted a separate /boot partition:
  198.           *
  199.  
  200.             sudo umount /mnt/boot
  201.  
  202.   14. Unmount the LiveCD's /usr directory:
  203.  
  204.       sudo umount /mnt/usr
  205.  
  206.   15. Unmount last device:
  207.  
  208.       sudo umount /mnt
  209.  
  210.   16. Reboot.
  211.  
  212.       sudo reboot
  213.  
  214. Purge & Reinstall
  215.  
  216. This procedure also uses the chroot command to gain access to the broken system's files. Once the chroot command is issued, the LiveCD treats the broken system's / as its own. Commands run in a chroot environment will affect the broken systems filesystems and not those of the LiveCD.
  217.  
  218. If certain GRUB 2 files become corrupted or are removed by the user, a simple reinstall of GRUB 2 may not return the system to a bootable condition. To completely restore the GRUB 2 filesystem, it may be necessary to completely remove and reinstall the grub-pc and grub-common packages (and grub-gfxpayload-lists in Grub 1.99/Natty).
  219.  
  220. important.png During this operation the user will be temporarily left with no bootloader. Ensure you have a working Internet connection and access to the repositories before purging the GRUB 2 packages.
  221.  
  222.    1. Boot to the LiveCD Desktop. The CD should be the same release and architecture (32/64 bit).
  223.    2.
  224.  
  225.       Open a terminal - Applications, Accessories, Terminal.
  226.    3. Determine your normal system partition - (the switch is a lowercase "L")
  227.  
  228.       sudo fdisk -l
  229.  
  230.           *
  231.  
  232.             If you aren't sure, run df -Th. Look for the correct disk size and ext3 or ext4 format.
  233.    4. Mount your normal system partition:
  234.           * Substitute the correct partition: sda1, sdb5, etc.
  235.  
  236.       sudo mount /dev/sdXX /mnt
  237.  
  238.           *
  239.  
  240.             Example: sudo mount /dev/sda1 /mnt
  241.    5.
  242.  
  243.       Only if you have a separate boot partition:
  244.           * sdYY is the /boot partition designation
  245.  
  246.       sudo mount /dev/sdYY /mnt/boot
  247.  
  248.           *
  249.  
  250.             Example: sudo mount /dev/sda6 /mnt/boot
  251.    6. Mount the critical virtual filesystems:
  252.  
  253.       for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
  254.  
  255.    7. Chroot into your normal system device:
  256.  
  257.       chroot /mnt
  258.  
  259.    8. You should now be at a "root" prompt. The use of "sudo" is no longer required. Ensure you have a working Internet connection and access to the repositories. If you do not, STOP!
  260.  
  261.       apt-get update
  262.  
  263.    9.
  264.  
  265.       Purge grub-pc and grub-common (and grub-gfxpayload-lists in Grub 1.99/Natty). You will be warned you are removing the bootloader. TAB to OK.
  266.  
  267.       apt-get purge grub-common
  268.  
  269.   10. Reinstall GRUB 2. You will be given the opportunity to add kernel options. TAB to OK. Next you will be given the opportunity to select the devices/drives on which to install GRUB 2. Select the appropriate drive(s) with the SPACEBAR. Normally you do NOT want to select any partitions. TAB to OK after selecting the drive(s), then press ENTER.
  270.  
  271.       apt-get install grub-pc
  272.  
  273.   11.
  274.  
  275.       Exit chroot:
  276.  
  277.       exit
  278.  
  279.           * You should be back at your normal command prompt.
  280.   12. Unmount virtual filesystems*:
  281.  
  282.       for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done
  283.  
  284.   13. Unmount the Ubuntu partition:
  285.  
  286.       sudo umount /dev/sdXY
  287.  
  288.   14. Reboot.
  289.  
  290. Post-Restoration Commands
  291.  
  292. Once the user can boot to a working system, try to determine why the system failed to boot. The following commands may prove useful in locating and/or fixing the problem.
  293.  
  294.     *
  295.  
  296.       To refresh the available devices and settings in /boot/grub/grub.cfg
  297.           o
  298.  
  299.             sudo update-grub
  300.       To look for the bootloader location.
  301.           o
  302.  
  303.             grub-probe -t device /boot/grub
  304.  
  305.       To install GRUB 2 to the sdX partition's MBR (sda, sdb, etc.)
  306.           o
  307.  
  308.             sudo grub-install /dev/sdX
  309.       To recheck the installation. (sda, sdb, etc.)
  310.           o
  311.  
  312.             sudo grub-install --recheck /dev/sdX
  313.  
  314. Purge & Reinstall
  315.  
  316. This procedure also uses the chroot command to gain access to the broken system's files. Once the chroot command is issued, the LiveCD treats the broken system's / as its own. Commands run in a chroot environment will affect the broken systems filesystems and not those of the LiveCD.
  317.  
  318. If certain GRUB 2 files become corrupted or are removed by the user, a simple reinstall of GRUB 2 may not return the system to a bootable condition. To completely restore the GRUB 2 filesystem, it may be necessary to completely remove and reinstall the grub-pc and grub-common packages (and grub-gfxpayload-lists in Grub 1.99/Natty).
  319.  
  320. important.png During this operation the user will be temporarily left with no bootloader. Ensure you have a working Internet connection and access to the repositories before purging the GRUB 2 packages.
  321.  
  322.    1. Boot to the LiveCD Desktop. The CD should be the same release and architecture (32/64 bit).
  323.    2.
  324.  
  325.       Open a terminal - Applications, Accessories, Terminal.
  326.    3. Determine your normal system partition - (the switch is a lowercase "L")
  327.  
  328.       sudo fdisk -l
  329.  
  330.           *
  331.  
  332.             If you aren't sure, run df -Th. Look for the correct disk size and ext3 or ext4 format.
  333.    4. Mount your normal system partition:
  334.           * Substitute the correct partition: sda1, sdb5, etc.
  335.  
  336.       sudo mount /dev/sdXX /mnt
  337.  
  338.           *
  339.  
  340.             Example: sudo mount /dev/sda1 /mnt
  341.    5.
  342.  
  343.       Only if you have a separate boot partition:
  344.           * sdYY is the /boot partition designation
  345.  
  346.       sudo mount /dev/sdYY /mnt/boot
  347.  
  348.           *
  349.  
  350.             Example: sudo mount /dev/sda6 /mnt/boot
  351.    6. Mount the critical virtual filesystems:
  352.  
  353.       for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
  354.  
  355.    7. Chroot into your normal system device:
  356.  
  357.       chroot /mnt
  358.  
  359.    8. You should now be at a "root" prompt. The use of "sudo" is no longer required. Ensure you have a working Internet connection and access to the repositories. If you do not, STOP!
  360.  
  361.       apt-get update
  362.  
  363.    9.
  364.  
  365.       Purge grub-pc and grub-common (and grub-gfxpayload-lists in Grub 1.99/Natty). You will be warned you are removing the bootloader. TAB to OK.
  366.  
  367.       apt-get purge grub-common
  368.  
  369.   10. Reinstall GRUB 2. You will be given the opportunity to add kernel options. TAB to OK. Next you will be given the opportunity to select the devices/drives on which to install GRUB 2. Select the appropriate drive(s) with the SPACEBAR. Normally you do NOT want to select any partitions. TAB to OK after selecting the drive(s), then press ENTER.
  370.  
  371.       apt-get install grub-pc
  372.  
  373.   11.
  374.  
  375.       Exit chroot:
  376.  
  377.       exit
  378.  
  379.           * You should be back at your normal command prompt.
  380.   12. Unmount virtual filesystems*:
  381.  
  382.       for i in /sys /proc /dev/pts /dev; do sudo umount /mnt$i; done
  383.  
  384.   13. Unmount the Ubuntu partition:
  385.  
  386.       sudo umount /dev/sdXY
  387.  
  388.   14. Reboot.
  389.  
  390. Post-Restoration Commands
  391.  
  392. Once the user can boot to a working system, try to determine why the system failed to boot. The following commands may prove useful in locating and/or fixing the problem.
  393.  
  394.     *
  395.  
  396.       To refresh the available devices and settings in /boot/grub/grub.cfg
  397.           o
  398.  
  399.             sudo update-grub
  400.       To look for the bootloader location.
  401.           o
  402.  
  403.             grub-probe -t device /boot/grub
  404.  
  405.       To install GRUB 2 to the sdX partition's MBR (sda, sdb, etc.)
  406.           o
  407.  
  408.             sudo grub-install /dev/sdX
  409.       To recheck the installation. (sda, sdb, etc.)
  410.           o
  411.  
  412.             sudo grub-install --recheck /dev/sdX
View raw paste Reply