-- MikeGore - 02 Mar 2010

GRUB2 Repair

Grub 2 Documents

Grub 2 commands and important files

  • grub-install - reinstall/install grub
  • grub-mkconfig - rebuild /boot/grub/grub.cfg
  • /boot/grub/grubenv - grub persistent environment
  • /etc/default/grub - system-wide grub defaults
  • /boot/grub/grub.cfg - automatically created config file - some sections will persist across updates
  • /boot/grub/default - default boot image choice
  • /etc/grub.d/ - grub scripts that automatically parse the contents of /boot
    • Note - some of these scripts will keep track of the previous contents of a config file and update it - persistence

Grub 2 Changes from V1 - Important - please read

  • /boot/grub/menu.lst is NOT the main config file any more - now is grub.cfg
  • /etc/default/grub now contains grub defaults
  • See next section on Grub 2 configuration update notes

Grub 2 configuration update notes

  • If you want to change this file you should
    1. ) Update /etc/default/grub
    2. ) Then use grub-mkconfig -o /boot/grub/grub.cfg to update it.

Grub 2 Adding Custom Rules

  • If you wish to add custom rules you can use /etc/grub.d/40_custom
    • Or Create a new files - read the man pages and documentation from grub2 before you try this option.
  • /etc/grub.d/ contains rules used to automatically create menu entries in grub.cfg when scanning /boot

Finding and updating UUIDs when imaging

  • When running from a recover disk the command blkid will list all of the system UUID's
   /dev/sdc1: LABEL="/scratch" UUID="3b3ed01c-e3ba-41b8-834c-7552746e9220" TYPE="ext3" 
   /dev/sdb2: LABEL="/home" UUID="e2395ad4-3201-4fd6-97bf-b473cf1381a2" TYPE="ext3" 
   /dev/sda5: LABEL="/" UUID="78c310b2-4e85-431c-8a5d-d768d01c1b99" TYPE="ext3" 
   /dev/sda6: LABEL="/fsys1" UUID="6b376205-7d64-48cc-8983-b3a2a881c919" TYPE="ext3" 
   /dev/sda7: LABEL="/var" UUID="ab8ec5f6-997c-4afd-ae49-e0072ff2b8d9" TYPE="ext3" 
   /dev/sda8: LABEL="/tmp" UUID="c6fe3594-4538-45b4-bd21-88b032cc4e40" TYPE="ext3" 
   /dev/sdb1: TYPE="swap" UUID="77d765b5-2358-4935-abaa-a2785c8dbf45"

Updating Grub 2 config files

Update 5 Dec 2012
  1. ) make any changes to /etc/default/grub
  2. ) grub-mkconfig -o /boot/grub/grub.cfg
  3. ) update-grub
    • Note we run grub-mkconfig because it is not always invoked from grub-update

Checking Grub

  • grub-install --recheck /dev/sdX where X is the boot device a or b or c ...

Grub2 repair

Updated 2 April 2013
  • Please note that with dual boot windows 7 and Ubuntu we are now using the WIndows boot manager. Therefore we have to install Grub2 in the Ubuntu boot partition - NOT in the MBR!!!!
  • Note: For stand alone system I suggest purging and reinstalling Grub as the best overall solution. This does not take much time and grantees the results - works mainly due to the fact that there are potentially many files in /boot/grub that can keep persistent data around that impact the repair process

Using Live CD

We assume that /dev/sda5 is the root partition in this example
  1. ) Boot Ubuntu 9.10 install CD and choose try without installing (ex. Live Mode)
  2. ) open a terminal window (look under accessories)
  3. ) sudo bash (become root)
  4. ) fdisk -l (find your linux partition and drive)
  5. ) mount /dev/sda5 /mnt
  6. ) grub-install --root-directory=/mnt /dev/sda
  7. ) umount /mnt

RIP CD,PXE or USB to fix a"> Using RIP CD,PXE or USB to fix and Ubuntu system with GRUB2

Easy way - using ubunt-scripts on ASIMOV

Update 5 Dec 2012
  • Boot updated RIP - suggest Graphical Mode version 13.7 or higher
  • Optionally update ubuntu-scripts
    • rsync cscf-adm@asimov:/coregroup1/images/ubuntu-scripts . - get latest updates
  • cd /ubuntu-scripts

  • In the next steps please ignore any /dev/pty related errors in the next steps - harmless
  1. ) BOOT RIP
  2. ) dhcpcd (start network - make sure you are on a DHCP network that will give the system an address)
    • ping www.yahoo.com (Test network)
  3. ) fdisk -l (discover your drives)
  4. ) blkid (lists partitions and UUID and partition type)
  5. ) Say our partition is /dev/sda1
  6. ) ./mntpart /dev/sda1
  7. ) ./grub-fix
    • This purges and reinstalls GRUB.
    • Why? Because /boot/grub can hold several files that keep persistent data that might not (and often does not) get fixed using normal grub tools
    • Notes: this script makes most of the changes listed in the Grub Menu Entries Section Below - no hidden menus , save last menu choice, text console, etc

RIP CD,PXE"> OLD MANUAL WAY Using RIP CD,PXE or USB to fix and Ubuntu system with GRUB2

  1. ) BOOT RIP
  2. ) dhcpcd (start network - make sure you are on a DHCP network that will give the system an address)
    • ping www.yahoo.com (Test network)
  3. ) fdisk -l (discover your drives)
  4. ) blkid (lists partitions and UUID and partition type)
  5. ) Say our partition is /dev/sda1
  6. ) ls -l /dev/sda (get the major/minor numbers of /dev/sda and its partitions)
          ls -l /dev/sda*
          brw-rw---- 1 root disk 8, 0 2011-09-14 11:09 /dev/sda
          brw-rw---- 1 root disk 8, 1 2011-09-06 09:05 /dev/sda1
  7. ) Note that the major number is 8 and the minor numbers are 0 and 1 1 is the root partition as reported by blkid
  8. ) mount /dev/sda1 /mnt/sda1 ( mount the root partition - RIP automatically creates mount points)
  9. ) Create the device nodes in the target portion if they do not exist - grub needs these to work
    1. ) cd /mnt/sda1/dev
    2. ) mknod sda b 8 0
    3. ) mknod sda1 b 8 1
  10. ) chroot /mnt/sda1
  11. ) mount proc /proc -t proc
  12. ) *mount sysfs /sys -t sysfs
  13. ) mount devpts /dev/pts -t devpts
  14. ) Remove/Purge and Reinstall GRUB2 - we will use dpkg to list grub components
    1. ) dpkg -l | grep grub
               ii  grub           0.97-29ubuntu60    GRand Unified Bootloader (Legacy version)
               ii  grub-common    1.98-1ubuntu12     GRand Unified Bootloader, version 2 (common files)
               ii  grub-pc        1.98-1ubuntu7      GRand Unified Bootloader, version 2 (PC/BIOS version)
    2. ) apt-get remove --purge grub grub-common grub-pc
    3. ) rm -rf /boot/grub
    4. ) rm -f /etc/mtab - we only want /etc/fstab
    5. ) apt-get install grub2
      • If prompted regarding the grub configuration file you can pick "install the package maintainer's version" if you want to start clean - recommended
      • See section Grub Boot Time options
      • Optionally you can now remove the /dev/sda entries you created You are DONE

Important Menu Entries and their function

Grub Boot Time options

Update 5 Dec 2012
  • Config File: /etc/grub/default should be /etc/default/grub ???
    • After making changes use the command grub-mkconfig -o /boot/grub/grub.cfg

  • Add remember last menu:
    • GRUB_DEFAULT=saved
  • Make the Menu NOT hidden so you can choose the menu items you have in GRUB
    • *NOtes: Hold down SHIFT to display hidden boot options as an alternative to this option
  • Make default boot in N seconds
  • Make boot startup happen in TEXT mode (not graphics mode)
    • GRUB_TERMINAL=console
  • Modify Default Linux Command Line options GRUB_CMDLINE_LINUX - if desired
  • Example /etc/default/grub config file
       # If you change this file, run 'update-grub' afterwards to update
       # /boot/grub/grub.cfg.
       # For full documentation of the options in this file, see:
       #   info -f grub -n 'Simple configuration'
       GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
       GRUB_CMDLINE_LINUX_DEFAULT="max_loop=255 "
       # Uncomment to enable BadRAM filtering, modify to suit your needs
       # This works with Linux (no patch required) and with any kernel that obtains
       # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
       # Uncomment to disable graphical terminal (grub-pc only)
       # The resolution used on graphical terminal
       # note that you can use only modes which your graphic card supports via VBE
       # you can see them in real GRUB with the command `vbeinfo'
       # Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
       # Uncomment to disable generation of recovery mode menu entries
       # Uncomment to get a beep at grub start
       #GRUB_INIT_TUNE="480 440 1"

Recreating */boot/grub/grub.cfg

Update 5 Dec 2012
  • update-grub to regenerate the /boot/grub/grub.cfg file
  • or grub-mkconfig -o /boot/grub/grub.cfg

9.10 and 10.04 grub update problems

  • Just read the previous section if these command do not work
    • grub-mkconfig -o /boot/grub/grub.cfg
    • update-grub

Ubuntu 10.04 and later

Update 5 Dec 2012
  • grub.cfg replaces menu.lst
  • /etc/grub.d/ contain scripts that interpret files under /boot that automatically create boot entries in grub.cfg
  • Run grub-mkconfig -o /boot/grub/grub.cfg AFTER make any changes
    • Note: u*update-grub* may not always correctly update grub.cfg so we use grub-mkconfig instead

/etc/grub.d/ scripts

Update 5 Dec 2012
  • Don't edit anything except 40_custom
    • 00_header loads settings from /etc/default/grub (timeout, defaults, etc)
    • 05_debian_theme loads background colors and themes
    • 10_linux loads menu entries for Ubuntu 10.04
    • 20_memtest86+ loads memtest
    • 30_os-prober loads menu entries for any operating systems it finds
    • 40_custom this is the script to edit for additional menu options


Update 5 Dec 2012
  • Example:
       #!/bin/sh -e
       echo "This string will display when update-grub runs"
       #indicates start of boot entry
       #sets the name of the boot entry
       menuentry "Custom Windows Option" {
       #sets the hard drive the system will boot from
       #NOTE: partition notation now starts with 1 instead of 0
       set root=(hd0,1)
       #more boot options go here, this one is for Windows
       chainloader (hd0,1)+1
       #This one is for Linux
       #linux vmlinuz
       #initrd initrd.img
  • Alternatively, you can just put the custom entries into 40_custom. * Run grub-mkconfig -o /boot/grub/grub.cfg

GRUB 2 Windows 7 conflict - solution

Update 5 Dec 2012
Edit | Attach | Watch | Print version | History: r20 < r19 < r18 < r17 < r16 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r20 - 2016-04-05 - MikeGore
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback