22. 11. 2012

GRUB2 installation walkthrough with Xen, RAID, LVM and Windows

This is little/quick how-to install GRUB2. Whole article is focused on this configuration:

  • root filesystem over RAID and LVM (need initramfs)
  • Xen hypervisor
  • UEFI booting (and GPT) due to 3 TB hard drives
  • x86_64 machine
  • "dualboot" Gentoo Linux and Windows 8

At this moment you should know some basics about the GRUB2 and differences from GRUB Legacy. Probably you read some howtos and you're confused as myself.

Step 1 - installing Windows

You should skip this step if you're interested just in GNU/Linux.
  1. If you want a UEFI booting, boot your setup media (DVD) in the UEFI mode. For UEFI installations you must boot in this mode. We'll talk about this later in so-called "chicken-egg problem".
  2. Create a new partition (i.e. a half of whole drive), let some space for your linux. In case of Windows 8, setup will create 4 partitions on your drive. In my case I had prepared GPT drive with gdisk and existing mdraid partition at the end with working system from previous 2 TB drives.
  3. Continue installing Windows.

Step 2 - installing GNU/Linux and GRUB2

  1. Install your linux as usual. In my case I just chrooted from USB to my working system.
  2. Unmask GRUB2 and efibootmgr in /etc/portage/package.keywords (or package.accept_keywords):
  3. Set desired platform(s) in your make.conf, for me it's:
  4. Install GRUB2:
    # emerge -avj grub
  5. You should consider using sys-boot/os-prober too.
  6. At this moment you should have accessible efivars (/sys/firmware/efi/vars/), this is little bit chicken-egg problem, because you must boot in UEFI mode to work with your UEFI firmware. In my case I've made USB boot with GRUB2 EFI binary (just command line without menu) by this command:
    # grub2-install --target=x86_64-efi --root-directory=/mnt/usb --removable --modules="part_gpt raid lvm"
    ... and then manually booted my system (set root ..., linux ..., initrd ..., boot), finally checked efivars by running efibootmgr. All done.
  7. Prepare mountpoint to the EFI partition (created by Windows setup - in my case it's sda2), don't forget to update /etc/fstab:
    # mkdir -p /boot/efi
    # mount /dev/sda2 /boot/efi

    In case your haven't Windows installation, create new partition with type EF00 and format it with vfat (FAT32).
  8. Install GRUB2, this step will automatically create EFI record, you don't need to make it manually (probably you had to do this in previous versions). Directory efi-directory is EFI partition and boot-directory where is stored configuration (grub.cfg), GRUB2 EFI binary (grubx64.efi) and whole application (menu, themes, etc.):
    # grub2-install --target=x86_64-efi --efi-directory=/boot/efi/ --boot-directory=/boot/efi/EFI/ --bootloader-id=GRUB2 --no-floppy --recheck

Step 3 - configuring GRUB2

  1. As you know, GRUB2 offers semi-automatic script generation by running:
    grub2-mkconfig -o /boot/efi/EFI/GRUB2/grub.cfg
  2. Check your /etc/default/grub and set your kernel parameters as I described here.
  3. Make sure you have correctly named kernel binaries, as you can read here.
  4. Re-run grub2-mkconfig ...
  5. If you prefer your own entries, copy these generated from grub.cfg to /etc/grub.d/40_custom, customize them and remove execution bit from 10/20/30* files. Then re-run grub2-mkconfig ...
  6. For my Windows 8 menuentry, I've used this commands:
    root # grub2-probe --target=hints_string /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi
    root # grub2-probe --target=fs_uuid /boot/efi/EFI/Microsoft/Boot/bootmgfw.efi

    ... and add results to the menuentry:

    menuentry "Windows 8" {
    insmod part_gpt
    insmod fat
    insmod search_fs_uuid
    insmod chain
    search --fs-uuid --no-floppy --set=root
    chainloader /EFI/Microsoft/Boot/bootmgfw.efi

  7. Because my computer always boots to Windows, at last I've deleted Windows EFI records and leave just GRUB2 record:
    # efibootmgr -b xxxx -B

Good luck!

PS: Sorry for poor styling, I'll make it better or move whole blog to another service, 'cause Blogger sucks! But at this moment I need to go to sleep, so maybe later. Later later...