Navigation

      Tweaking Ubuntu‎ > ‎

      An easy way for a dedicated Grub 2 partition

      When GRUB 2 is in its own dedicated partition it is 'operating system independant', so we can add or remove one or two operating systems without the inconvenience of losing the boot of the remaining operating systems.
      Those of us who are multi-booting with more that two operating systems in their computer like to be able to set their own user friendly names for their operating systems.
      It's okay to edit the grub.cfg directly when GRUB 2 isn't part of an operating system, making it easier to do what we like with GRUB and have fun with it and learn more GRUB commands and tricks.


      1. Choose an existing partition or create a new one and format it with a file system, you will need at least about 60 MiB of space in the partition for grub 2 files, but a little more room than that might be advisable.
      2. Format the partition with a file system and optionally give the file system a FILE SYSTEM LABEL.
      3. Mount the partition by clicking on its icon in the 'Places' menu.
      4. Run a grub-install command similar to the one shown below, 
        sudo grub-install --root-directory=/media/grub2 /dev/sda
      Where: '/media/grub2' is the mount point for the file system I want to have GRUB files created in
      Where:  I want to make a new /boot/grub directory and fill it with GRUB files.
      Where: '/dev/sda' is the hard disk in which I want to write the stage1 code to MBR in

      That command creates a new /boot and /boot/grub/ directory if one doesn't already exist, and creates or refreshes GRUB files in /boot/grub, all except for grub.cfg.
      If you don't make a grub.cfg then  there will be no GRUB Menu and your computer will boot to a GRUB Command Line Interface,  see GRUB2 How To Boot From CLI Mode

      If you want a GRUB Menu you need to make a grub.cfg file and copy it to /boot/grub.
      You can make your own grub.cfg file and customize it in any way you like.
      The proper way to do it would be to use the grub-mkconfig command, and alter the file path to make it point to the 'Dedicated'  /boot/grub/'. See How to Update the GRUB Menu .
      Another way would be to make your own grub.cfg, if you need an example to help you get started, look here, grub.cfg - Grub Wiki.
      Or, copy and paste this one, grub.cfg, to a blank text file, name it grub.cfg, edit it to your needs and paste it in your Dedicated /boot/grub.
      Later, you can also make and add other files such as background images.

      I had trouble getting my 'Dedicated GRUB 2' to display any background image at first.
      I was getting 'error: No video mode activated', after trying the background_image command in CLI Mode.
      I needed make a fonts folder in my 'Dedicated GRUB 2 Partition and copy the fonts from /usr/share/grub/unicode.pff and /usr/share/grub/ascii.pff into it. Then I had to correct the fonts path in my grub.cfg header area,
      ### BEGIN /etc/grub.d/00_header ###
      set default=0
      set timeout=5
      set root=(hd0,2)
      if font (hd0,2)/fonts/unicode.pff ; then
        set gfxmode=640x480
        insmod gfxterm
        insmod vbe
        terminal gfxterm
      fi
      ### END /etc/grub.d/00_header ###

      After that I was able to display my splashimage in my 'Dedicated GRUB 2 Partition'.

      After this it´s neccesairy to install grub in the partition of your linux OS. Use this method for doing that (where sda5 should be replaced with the device name of your /boot partition:


      sudo grub-install /dev/sda5
      Where: /dev/sda5 is the disk you wish to install GRUB to, (boot.img to first hard disk MBR), otherwise use '/dev/sdb' for second hard disk or '/dev/sdc' for third hard disk.

      Normally, most people will want to install GRUB to MBR in the first hard disk if Ubuntu is installed in a so-called 'internal' disk inside a computer. By an 'internal' disk I mean a disk that is more or less 'permanently' connected to the motherboard by IDE ribbon cables or SATA cables.
      If your computer has more than one hard disk and you're not sure which hard disk's MBR you want to install GRUB2 to, it might be best to install GRUB to all of your disks, just to make sure.

      If you have Ubuntu installed in a so-called 'removable' disk, such as a USB 'external' drive, or any disk that you intend to remove from the computer, you should probably install GRUB to the MBR of the same disk you have Ubuntu installed in only, meaning your USB external drive.

      If you want to install GRUB2 to the boot sector of a partition for some strange reason, you may use something like /dev/sda1 or /dev/sda2 for writing GRUB's boot.img to a partition boot sector. The practice of installing GRUB2 to partition boot sectors is not encouraged. It reduces GRUB's reliability and it could be dangerous to other operating systems if users use the grub-install command carelessly or ill-informed and write GRUB to the wrong boot sector.

      You need to have the operating system booted first, before you can use the command.
      If the operating system you're trying to fix won't boot you need to chroot into it from another operating system such as a Live CD operating system before you can run grub-install. In that situation it might be easier to use grub-setup instead, please refer to How To Re-install GRUB from Live CD - with grub-setup.

      The grub-install command doesn't run grub-mkconfig (or update-grub), so the user still needs to run one of those commands if a new grub.cfg is wanted. See grub -mkconfig  - make a new grub.cfg file.


      Examples of the grub.cfg file in the dedicated grub partition:

      #
      # 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,msdos5)'
      search --no-floppy --fs-uuid --set e25d5b4e-d3df-47ec-be92-2f79d417d9f2
      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,msdos5)'
      search --no-floppy --fs-uuid --set e25d5b4e-d3df-47ec-be92-2f79d417d9f2
      set locale_dir=($root)/boot/grub/locale
      set lang=nl
      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 ###
      insmod ext2
      set root=(hd0,7)
      search --no-floppy --fs-uuid --set 8385-8482
      insmod tga
      if background_image /boot/grub/background/earthrise-tux-windows.tga ; then
        set color_normal=white/black
        set color_highlight=white/light-gray
      else
        set menu_color_normal=white/black
        set menu_color_highlight=white/light-gray
      fi
      ### END /etc/grub.d/05_debian_theme ###


      ### BEGIN /etc/grub.d/10_linux ###

      menuentry "Linux Mint configfile" {
          configfile (hd0,9)/boot/grub/grub.cfg
      }
      menuentry "Linux Ubuntu configfile" {
          configfile (hd0,5)/boot/grub/grub.cfg
      }


      ### END /etc/grub.d/10_linux ###

      ### BEGIN /etc/grub.d/20_linux_xen ###
      ### END /etc/grub.d/20_linux_xen ###


      ### BEGIN /etc/grub.d/30_os-prober ###
      ### END /etc/grub.d/30_os-prober ###

      ### BEGIN /etc/grub.d/40_custom ###
      # This file provides an easy way to add custom menu entries.  Simply type the
      # menu entries you want to add after this comment.  Be careful not to change
      # the 'exec tail' line above.

      menuentry "Microsoft Windows XP Professional NL(on /dev/sda1)" {
          insmod part_msdos
          insmod ntfs
          set root='(hd0,msdos1)'
          search --no-floppy --fs-uuid --set 067a6eea242a2681
          drivemap -s (hd0) ${root}
          chainloader +1
      }
      ### END /etc/grub.d/40_custom ###

      ### BEGIN /etc/grub.d/20_memtest86+ ###
      menuentry "Memory test (memtest86+)" {
          insmod part_msdos
          insmod ext2
          set root='(hd0,msdos5)'
          search --no-floppy --fs-uuid --set e25d5b4e-d3df-47ec-be92-2f79d417d9f2
          linux16    /boot/memtest86+.bin
      }
      menuentry "Memory test (memtest86+, serial console 115200)" {
          insmod part_msdos
          insmod ext2
          set root='(hd0,msdos5)'
          search --no-floppy --fs-uuid --set e25d5b4e-d3df-47ec-be92-2f79d417d9f2
          linux16    /boot/memtest86+.bin console=ttyS0,115200n8
      }
      ### END /etc/grub.d/20_memtest86+ ###
       


      Example of the grub.cfg file on the OS partition:

      #
      # 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 video_bochs
        insmod video_cirrus
      }

      insmod part_msdos
      insmod ext2
      set root='(/dev/sda,msdos5)'
      search --no-floppy --fs-uuid --set=root e25d5b4e-d3df-47ec-be92-2f79d417d9f2
      if loadfont /usr/share/grub/unicode.pf2 ; then
        set gfxmode=auto
        load_video
        insmod gfxterm
      fi
      terminal_output gfxterm
      insmod part_msdos
      insmod ext2
      set root='(/dev/sda,msdos5)'
      search --no-floppy --fs-uuid --set=root e25d5b4e-d3df-47ec-be92-2f79d417d9f2
      set locale_dir=($root)/boot/grub/locale
      set lang=nl_NL
      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
      if background_color 44,0,30; then
        clear
      fi
      ### END /etc/grub.d/05_debian_theme ###

      ### BEGIN /etc/grub.d/10_linux ###
      if [ ${recordfail} != 1 ]; then
        if [ -e ${prefix}/gfxblacklist.txt ]; then
          if hwmatch ${prefix}/gfxblacklist.txt 3; then
            if [ ${match} = 0 ]; then
              set linux_gfx_mode=keep
            else
              set linux_gfx_mode=text
            fi
          else
            set linux_gfx_mode=text
          fi
        else
          set linux_gfx_mode=keep
        fi
      else
        set linux_gfx_mode=text
      fi
      export linux_gfx_mode
      if [ "$linux_gfx_mode" != "text" ]; then load_video; fi
      menuentry 'Ubuntu, met Linux 2.6.38-10-generic' --class ubuntu --class gnu-linux --class gnu --class os {
          recordfail
          set gfxpayload=$linux_gfx_mode
          insmod part_msdos
          insmod ext2
          set root='(/dev/sda,msdos5)'
          search --no-floppy --fs-uuid --set=root e25d5b4e-d3df-47ec-be92-2f79d417d9f2
          linux    /boot/vmlinuz-2.6.38-10-generic root=UUID=e25d5b4e-d3df-47ec-be92-2f79d417d9f2 ro   quiet splash vt.handoff=7
          initrd    /boot/initrd.img-2.6.38-10-generic
      }
      menuentry 'Ubuntu, met Linux 2.6.38-10-generic (herstelmodus)' --class ubuntu --class gnu-linux --class gnu --class os {
          recordfail
          set gfxpayload=$linux_gfx_mode
          insmod part_msdos
          insmod ext2
          set root='(/dev/sda,msdos5)'
          search --no-floppy --fs-uuid --set=root e25d5b4e-d3df-47ec-be92-2f79d417d9f2
          echo    'Loading Linux 2.6.38-10-generic ...'
          linux    /boot/vmlinuz-2.6.38-10-generic root=UUID=e25d5b4e-d3df-47ec-be92-2f79d417d9f2 ro single
          echo    'Loading initial ramdisk ...'
          initrd    /boot/initrd.img-2.6.38-10-generic
      }
      submenu "Previous Linux versions" {
      menuentry 'Ubuntu, met Linux 2.6.35-30-generic' --class ubuntu --class gnu-linux --class gnu --class os {
          recordfail
          set gfxpayload=$linux_gfx_mode
          insmod part_msdos
          insmod ext2
          set root='(/dev/sda,msdos5)'
          search --no-floppy --fs-uuid --set=root e25d5b4e-d3df-47ec-be92-2f79d417d9f2
          linux    /boot/vmlinuz-2.6.35-30-generic root=UUID=e25d5b4e-d3df-47ec-be92-2f79d417d9f2 ro   quiet splash vt.handoff=7
          initrd    /boot/initrd.img-2.6.35-30-generic
      }
      menuentry 'Ubuntu, met Linux 2.6.35-30-generic (herstelmodus)' --class ubuntu --class gnu-linux --class gnu --class os {
          recordfail
          set gfxpayload=$linux_gfx_mode
          insmod part_msdos
          insmod ext2
          set root='(/dev/sda,msdos5)'
          search --no-floppy --fs-uuid --set=root e25d5b4e-d3df-47ec-be92-2f79d417d9f2
          echo    'Loading Linux 2.6.35-30-generic ...'
          linux    /boot/vmlinuz-2.6.35-30-generic root=UUID=e25d5b4e-d3df-47ec-be92-2f79d417d9f2 ro single
          echo    'Loading initial ramdisk ...'
          initrd    /boot/initrd.img-2.6.35-30-generic
      }
      }
      ### END /etc/grub.d/10_linux ###

      ### BEGIN /etc/grub.d/20_memtest86+ ###
      menuentry "Memory test (memtest86+)" {
          insmod part_msdos
          insmod ext2
          set root='(/dev/sda,msdos5)'
          search --no-floppy --fs-uuid --set=root e25d5b4e-d3df-47ec-be92-2f79d417d9f2
          linux16    /boot/memtest86+.bin
      }
      menuentry "Memory test (memtest86+, serial console 115200)" {
          insmod part_msdos
          insmod ext2
          set root='(/dev/sda,msdos5)'
          search --no-floppy --fs-uuid --set=root e25d5b4e-d3df-47ec-be92-2f79d417d9f2
          linux16    /boot/memtest86+.bin console=ttyS0,115200n8
      }
      ### END /etc/grub.d/20_memtest86+ ###


      Comments