Migrating from Grub-legacy to Grub2(non UEFI)[Archlinux]

Archlinux Logo©

Today I’ve read news on Archlinux that Grub legacy is no longer supported and they recommend to upgrade to Grub2. Although it is not necessary and your favorite grub legacy will still serve you. But for those who always want latest piece of a software program and find it difficult to upgrade here are some quick step..

  1.  This tutorial is only intended for non EFI systems. Please follow the ArchWiki for more information.
  2. This tutorial is written form a average user’s point of view. Use your common sense before doing any thing other than what is mentioned here.
  3. Always keep a backup of your important data and a rescue disk ready in case something goes wrong.

First backup Grub-legacy files :

# cp -r /boot/grub /boot/grub-legacy

Install “grub-bios” package :

# pacman -S grub-bios
* Installing this package will replace the “grub-legacy” package. So before installing the above mentioned package, check your /var/cache/pacman/pkg/  directory for “grub-0.x.y.pkg.tar.xz” package. And if you are paranoid backup this package somewhere else to restore it later if something goes wrong.

Also load the device-mapper kernel module so that grub-probe can detect disks and partitions :

# modprobe dm_mod 
* The ArchWiki recommends installing to 440-byte_MBR_boot_code_region but we will generate core.img first and boot from that just to be safe.

Here are the steps :

If your /boot is on another partition, first make sure it is mounted.(It should be mounted unless you are using some weird setup.)

# grub-install --directory=/usr/lib/grub/i386-pc --target=i386-pc --grub-setup=/bin/true --boot-directory=/boot --recheck --debug /dev/sda

where /dev/sda is the destination of the installation.

# mkdir -p /boot/grub/locale

# cp /usr/share/locale/en@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo

Generate the Grub2 config file :

# grub-mkconfig -o /boot/grub/grub.cfg

Now go to your /boot/grub directory, there should be a file called menu.lst.pacnew. Rename it to menu.lst and append the following entry

title Grub2 Chainload
root (hd0,5)
kernel /boot/grub/i386-pc/core.img
* Remember to change the “root (hd0,5)” with your root partition. In my case it was root (hd0,5). Just look in the Archlinux entry in your file for your root partition number.

Now reboot and select the “Grub2 Chainload” option at booting screen. The Grub2 should work now.

After that if you are satisfied and want to install Grub2 and replace Grub-legacy do:

# grub-install --directory=/usr/lib/grub/i386-pc --target=i386-pc --boot-directory=/boot --recheck --debug /dev/sda

# mkdir -p /boot/grub/locale

# cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo

# grub-mkconfig -o /boot/grub/grub.cfg

Update: (22/07/2012) : After doing some more research and reading the ArchWiki again and again I found out that to successfully install Grub2 on 440-byte_MBR_boot_code_region (and that is what Arch devs recommend and support) you must need at least 2Mib of space before your first partition. If you dual boot with Microsoft Windows it is more likely that you do not have 1-2 Mb of post MBR space.

In that case either remove Windows (if you dont need it) and convert from MBR to GPT (see below) or install Grub2 to partition or partition-less disk but be warned this is know to cause some trouble and system breakage, but that is the only option if you need Grub2.

A note from author: Seriously I dont think anyone should do all this hassle just to install a piece of bootloader that does nothing but just boots your system.  I mean Grub-legacy is already on your system and working fine, what else you want it to do besides booting your system. But for some of you guys who still want to install Grub2 for some reason, here are the steps:

Converting from MBR to GPT:

First install a package called “gptfdisk” .

#pacman -S gptfdisk

now open MBR using “cgdisk”.

#cgdisk /dev/sda

press “w” at the prompt and exit. Watch out for any error and fix them before writing any change to disk because you may risk losing data.

Now create a 2 MiB partition using cgdisk and set the partition type to “EF02”.

After that it is just a matter of running.

# grub-install --directory=/usr/lib/grub/i386-pc --target=i386-pc --boot-directory=/boot --recheck --debug /dev/sda

# mkdir -p /boot/grub/locale

# cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo

# grub-mkconfig -o /boot/grub/grub.cfg

If you have any trouble or if I miss something or any suggestion, comment below and let me know.

For “cgdisk” walkthrough see here (cgdisk walkthrough)
For GPT information see here (rodsbooks)
For more information on Grub2 see here (dedoimedo)
See ArchWiki here (ArchWiki)


About Gaurav Trivedi

Gaurav Trivedi is a Gnu/Linux user, geek and technology enthusiast. He loves to play FPS games and traveling.
This entry was posted in Archlinux and tagged , , , , , , , , . Bookmark the permalink.

One Response to Migrating from Grub-legacy to Grub2(non UEFI)[Archlinux]

  1. Swagbucks says:

    Great post. Eager to read more by you soon!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s