Wednesday, April 11, 2012

Acer Aspire 5755G - 09 - Grub2

I'm using Grub2 because it support some nice ways to theme it.
The setup of it is slightly confusing though and I never got around with the auto configuration stuff of it.
I'm going to explain in this post how you can set it up with your own config files which is also a little bit more gentooish.

The Installation:

Grub2 is still masked by keyword **, it needs to be unmasked.
First we need the /etc/portage folder: mkdir -p /etc/portage Then we need to decide which version we want, the latest release snapshot or the live gits.
For gits: echo "sys-boot/grub **" > /etc/portage/package.keywords For the latest release snapshot: echo "=sys-boot/grub-2* **" > /etc/portage/package.keywords I'm using gits without any troubles.

Now we are able to emerge it. emerge grub:2

The Configuration:

We need to disable all autoconfig scripts in /etc/grub.d. cd /etc/grub.d chmod -x 10_linux chmod -x 20_linux_xen chmod -x 30_os-prober

Now the custom configuration for our dualboot system.
Open 40_custom with nano: nano 40_custom

Linux Part:
menuentry 'Navi 3.0.26' { load_video set gfxpayload=keep insmod gzio insmod part_msdos linux (hd0,msdos5)/vmlinuz-3.0.26-tuxonice rootfstype=btrfs root=/dev/sda7 ro rootflags=subvol=root quiet }

It's the name which should be displayed in grub2, choose whichever you want.

set gfxplayload:
A built in framebuffer. Set it either to keep or auto.

insmod gzio:
Loads the gzip module to unpack the kernel image.

insmod part_msdos:
Load the msdos partition table module.

Loads the kernel with several parameters.
Let's have a look at it step by step:

That's your boot partition where your kernel is located. Grub2 starts to count hdds at 0 and partitions at 1. So (hd0,msdos5) is the first hdd and the fifth msdos partition.

That's the kernel which should be loaded when you choose to boot this menu entry. So (hd0,msdos5)/vmlinuz-3.0.26-tuxonice boots the kernel vmlinuz-3.0.26-tuxonice from the first hdd and fifth partition.

The choosen filesystem for root. It has to match the actual filesystem of your root partition. It's set to btrfs in my case.

This option has to be set to the hdd and partition where your root is located. My grub2 loads /dev/sda7 as root.

Mount the root readonly during boot time. It will be later remounted with rw flags through fstab.

This is only needed for btrfs. It indicates which subvolume contains the root. Set it to the name of your root subvolume which you've created in your btrfs pool.

Prevents spamming tons of debug output during boot time. Unset this option if your system doesn't boot and you'll see some nice error messages.

Windows Part:
menuentry 'The Devils Instrument' { insmod part_msdos insmod chain chainloader (hd0,msdos2)+1 }

Again the name which should be displayed.

indmod part_msdos:
And the partition table type.

insmod chain:
Since Windows comes with an own bootloader on the second partition, we need to chainload it and need the chain module.

The actual chainloader. It loads the Windows bootloader from (hd0,msdos2), the first hdd and second partition.
The addon +1 indicates on which partition Windows is installed. It's on the third partition in my case, so I need to count up one partition.
If the Windows bootloader would be on the second partition but Windows itself on the fifth, then it would look like this: chainloader (hd0,msdos2)+3

This was all we need for now, we will later alter it a little bit for splash support and fancy things but that will be covered in a later chapter.

Hit ctrl+o to save the config, then ctrl+x to leave the editor.

Create config and write Grub2 into mbr:

Now we're going to create the config. Make sure that /boot is mounted and /etc/grub.d/40_custom executeable. mkdir -p /boot/grub2 chmod +x /etc/grub.d/40_custom grub2-mkconfig -o /boot/grub2/grub.cfg It might show some warnings about /sys not loaded or not readable, but you can ignore them.

Check the created config file in /boot/grub2. It sometimes happens that it isn't created at all.
It should look like this, it's only important for now, that the custom part is added to it: navi lia # cat /boot/grub2/grub.cfg # # DO NOT EDIT THIS FILE # # It is automatically generated by grub2-mkconfig using templates # from /etc/grub.d and settings from /etc/default/grub # ### BEGIN /etc/grub.d/00_header ### if [ -s $prefix/grubenv ]; then load_env fi set default="0" if [ x"${feature_menuentry_id}" = xy ]; then menuentry_id_option="--id" else menuentry_id_option="" fi export menuentry_id_option 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 load_video { if [ x$feature_all_video_module = xy ]; then insmod all_video else insmod efi_gop insmod efi_uga insmod ieee1275_fb insmod vbe insmod vga insmod video_bochs insmod video_cirrus fi } if [ x$feature_default_font_path = xy ] ; then font=unicode else insmod part_msdos insmod btrfs set root='hd0,msdos7' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos7 --hint-efi=hd0,msdos7 --hint-baremetal=ahci0,msdos7 79ae43bc-38b5-494b-9f07-0f3190096236 else search --no-floppy --fs-uuid --set=root 79ae43bc-38b5-494b-9f07-0f3190096236 fi font="/root/usr/share/grub/unicode.pf2" fi if loadfont $font ; then set gfxmode=1366x768 load_video insmod gfxterm set locale_dir=$prefix/locale set lang= insmod gettext fi terminal_input gfxterm terminal_output gfxterm insmod part_msdos insmod ext2 set root='hd0,msdos5' if [ x$feature_platform_search_hint = xy ]; then search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5 b1008699-03ad-4d72-8213-ec028739292a else search --no-floppy --fs-uuid --set=root b1008699-03ad-4d72-8213-ec028739292a fi insmod gfxmenu loadfont ($root)/grub2/themes/remix/bauhaus.pf2 loadfont ($root)/grub2/themes/remix/dejavu.pf2 insmod png set theme=($root)/grub2/themes/remix/theme.txt export theme if sleep --interruptible 0 ; then set timeout=10 fi ### END /etc/grub.d/00_header ### ### 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. ### BEGIN navi main ### menuentry 'Navi 3.0.26' { load_video set gfxpayload=keep insmod gzio insmod part_msdos linux (hd0,msdos5)/vmlinuz-3.0.26-tuxonicenavi rootfstype=btrfs root=UUID=79ae43bc-38b5-494b-9f07-0f3190096236 ro rootflags=subvol=root quiet splash initrd /initramfs-3.0.26-tuxonicenavi.img } menuentry 'The Devils Instrument' { insmod part_msdos insmod chain chainloader (hd0,msdos2)+1 } ### END /etc/grub.d/40_custom ###

And the final step, the install: grub2-install --no-floppy /dev/sda

We are almost ready to reboot, just some minor steps are ahead of us: Internet configuration, fstab and root password.

No comments:

Post a Comment