Page 1 of 1

Grub2 - the switch

Posted: 03 Aug 2012, 15:36
by viking60
Well I have only just gotten used to Grub-legacy when it apparently is time to switch to Grub2. To avoid becoming a conservative grumpy Linux user I decided to replace my good ol' Grub with Grub2 on one of my Arch boxes. I thought I should share my nervous breakdowns with you guys:

So this is a long lived Arch 64bit installation that has behaved well on a Toshiba laptop. It looks like this when I boot into the LTS kernel:

Code: Select all

[berserk@viking60-server ~]$ inxi -Fz
System:    Host: viking60-server Kernel: 3.0.38-1-lts x86_64 (64 bit) Desktop: N/A Distro: Arch Linux
Machine:   System: TOSHIBA product: 2011-06-04-22-48-17.082-VirtualBox-17084.log version: Bilder
           Mobo: Dropbox model: Maler version: Musikk Bios: NetBeansProjects version: Offentlig date: Videoklipp
CPU:       Dual core Intel Pentium Dual CPU T2310 (-MCP-) cache: 1024 KB flags: (lm nx sse sse2 sse3 ssse3)
           Clock Speeds: 1: 1463.105 MHz 2: 1463.105 MHz
Graphics:  Card: Intel Mobile GM965/GL960 Integrated Graphics Controller (primary)
           X.Org: 1.7.7 driver: intel Resolution: 1920x1200@50.0hz
           GLX Renderer: GeForce GTX 275/PCI/SSE2 GLX Version: 1.4 (2.1.2 NVIDIA 195.36.24)
Audio:     Card: Intel 82801H (ICH8 Family) HD Audio Controller driver: HDA Intel Sound: ALSA ver: 1.0.24
Network:   Card-1: Realtek RTL8101E/RTL8102E PCI Express Fast Ethernet controller driver: r8169
           IF: eth0 state: up speed: 100 Mbps duplex: full mac: <filter>
           Card-2: Atheros AR242x / AR542x Wireless Network Adapter (PCI-Express) driver: ath5k
           IF: wlan0 state: down mac: <filter>
Drives:    HDD Total Size: 160.0GB (40.9% used) 1: id: /dev/sda model: Hitachi_HTS54161 size: 160.0GB
Partition: ID: / size: 17G used: 9.1G (57%) fs: ext4 ID: /home size: 130G used: 52G (43%) fs: ext4
           ID: /boot size: 99M used: 55M (59%) fs: ext2 ID: swap-1 size: 0.27GB used: 0.00GB (0%) fs: swap
Sensors:   None detected - is lm-sensors installed and configured?
Info:      Processes: 159 Uptime: 4:19 Memory: 743.1/2001.9MB Client: Shell inxi: 1.8.14


So it is pretty much a matter of "simply" replacing Grub with Grub2. in my BIOS system.
Since I am very nervous at this point I chicken out and make a backup of my old grub stuff

Code: Select all

sudo mv /boot/grub /boot/grub-legacy

This is also handy for checking out what settings you had in the old menu.lst when you set up Grub2 later....

I also need to backup my current MBR which contains the boot code and the partition table

Code: Select all

dd if=/dev/sdX of=/path/to/backup/mbr_backup bs=512 count=1

Arch is also telling me:
Only 446 bytes of the MBR contain boot code, the next 64 contain the partition table. If you do not want to overwrite your partition table when restoring, it is strongly advised to backup only the MBR boot code:

So monkey see and monkey do:

Code: Select all

dd if=/dev/sdX of=/path/to/backup/bootcode_backup bs=446 count=1

This should be enough to save my bacon if I FUBAR :pray:

So here we go; time to replace the good old Grub (legacy) with the new Grub(2):
In Arch it is done like this:

Code: Select all

pacman -S grub-bios

So now the old grub is gone - probably not a good time to boot.....
Since I want to Install to 440-byte MBR boot code region
I setup grub-bios in the 440-byte Master Boot Record boot code region, populate the /boot/grub directory, generate the /boot/grub/i386-pc/core.img file, and embed it in the 31 KiB (minimum size - varies depending on partition alignment) post-MBR gap (MBR disks) or in BIOS Boot Partition (GPT disks):

Code: Select all

# modprobe dm-mod
# grub-install --target=i386-pc --recheck --debug /dev/sda
# mkdir -p /boot/grub/locale
# cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo


Yes I only copied that code from the Arch site and the stuff monkey see and monkey do style.
That last command gave me an error message though ("not a directory"??) so by now I am sweating a lot. And no matter how often I repeat it the error stays so I feel I have no choice but moving on.Please Arch don't let me down now we are so close to the finish line..

Generating GRUB2 BIOS Config file to finish:

Code: Select all

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


/etc/grub.d/10_linux is set to automatically add menu items for Arch linux that work out of the box, to any generated configuration. Other operating systems may need to be added manually to /etc/grub.d/40_custom or /boot/grub/custom.cfg

Time to reboot then :pray:

Re: Grub2 - the switch

Posted: 03 Aug 2012, 17:23
by viking60
:dance: Hey it worked!
Now the file that you will be editing the most is /etc/default/grub and every time you make changes you have to da a:

Code: Select all

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

That will generate the new grub.cfg for you. ( I do not know if this is Arch specific).

I see that Grub2 adds a lot of flexibility so I uncommented this line in /etc/default/grub:

Code: Select all

GRUB_THEME="/boot/grub/themes/starfield/theme.txt"

To have a sexy theme.
Then I put this background in /boot/themes/start/starfield and edited theme.txt to replace the default one.
Really nice!