GRUB2 and Xen Kernels

    Yesterday I wrote a small reviewer of the new GRUB 2 bootloader. And one unpleasant thing caught my attention. After all, if nothing works, you do not pay attention to it. So, I decided to try Xen-based virtualization. She demanded to install a modified kernel. Of course, the developers have not yet thought about such subtleties, so the freshly added menu item did not work. Obviously, we have two options. We need either a script that will correctly find the kernel and correctly compose the menu item, or we will have to make a menu item with pens in /boot/grub/grub.cfg.
    Naturally, I did not really understand what the correct menu item should look like, so I went to Google. He prompted me a note “xen with grub2 on debian etch”on a blog of a simple Australian guy named Daniel Mateos. The article helped me and everything would be fine if Daniel had not demolished his blog :) More precisely, he was tired of Wordpress, and, hand in hand somewhere in the wrong direction, he created a new site on django. That's why I decided to write what was discussed in his article here. For greater safety.

    GRUB2 liked the Australian admins support for GPT / EFI partitions, with which you can use disks larger than 2TB (they needed 5TB). Like any person who google on the topic of documentation on GRUB2, the guys were very upset. She is not. Therefore, they hoped that the following would benefit you.

    0. Cook GRUB

    Open and edit /etc/kernel-img.conf, bringing it to this form: All lines are intuitive. The config determines how the system will behave when installing a new kernel from a deb package. More details in man kernel-img.conf Further actions: Decryption line by line: 1. We mount the necessary section in the corresponding directory. This is completely optional. 2. Install, in fact, GRUB 2. It is strange if you do not already have it. 3. We write the bootloader in the boot sector of the hard drive. It can take some time. 4. Install the kernel. After that, GRUB will add it to the menu itself. The kernel is ordinary, not Xen-ovsky, so there should be no problems.
    do_symlinks = yes
    relative_links = yes
    do_bootloader = no
    do_bootfloppy = no
    do_initrd = yes
    link_in_boot = no
    postinst_hook = update-grub
    postrm_hook = update-grub

    # mount /dev/sda1 /boot
    # apt-get install grub-pc
    # grub-install /dev/sda
    # apt-get install linux-image-2.6.18-5-amd64

    1. Installing Xen Elements

    # apt-get install xen-hypervisor-3.2-1-amd64
    # apt-get install xen-docs-3.2 xen-utils-3.2-1 xen-tools
    # apt-get install libc6-xen
    # apt-get install linux-image-2.6.18-5-xen-amd64
    # apt-get install xen-linux-system-2.6.18-5-xen-amd64
    # apt-get install xen-linux-system-2.6.18-5-xen-vserver-amd64

    I note that the author installs a specific kernel version (2.6.18-5) for a specific architecture (amd64). No need to stupidly copy these commands. Adjust them according to your system and preferences.

    2.1. Manually adding a record to a menu

    Let me remind you right away: this is not the right way to edit the menu. According to the rules, we must write a script that would compose similar entries for Xen automatically. But if your time is more valuable than the reliability of the system, you can do so. Everything will work until the next bootloader update.
    Add a similar entry to grub.cfg at the end: Now, after rebooting, you should be in the dom0 kernel, running inside the Xen hypervisor.

    menuentry “Xen 3.2″ {
    multiboot (hd0,1)/xen-3.2-1-amd64.gz dom0_mem=256M
    module (hd0,1)/vmlinuz-2.6.18-5-xen-amd64 root=/dev/sda2 ro
    module (hd0,1)/initrd.img-2.6.18-5-xen-amd64

    2.2 Script for the correct solution to the problem

    This script is provided in a post comment by a man named Roger Smith. Of course, it needs to be improved, but the foundation is laid and from here you can understand the logic of the script. Necessary actions: 1. Create a file for the script 2. Set access rights to it: 3. Add the above script to /etc/grub.d/10_xen That's all. Good luck

    set -e

    kernels=`ls /boot/vmlinuz-*-xen-*|sed s/”.*vmlinuz-”//` 2>/dev/null
    initrds=`ls /boot/vmlinuz-*-xen-*|sed s/”.*initrd.img-”//` 2>/dev/null
    xenimgs=`ls /boot/xen-*|sed s/”.*xen-”//|sed s/”.gz”//` 2>/dev/null
    for i in $xenimgs; do
    for j in $kernels; do
    echo “Found xen kernel and image: $j –> $i” >&2
    echo “$initrds” | grep $j > /dev/null 2>&1
    if [ $? -eq 0 ]; then
    MODULE=”module ${GRUB_DRIVE_BOOT}/initrd.img-$j

    cat << EOF
    menuentry “Xen ${i} kernel $j” {
    multiboot ${GRUB_DRIVE_BOOT}/xen-$i.gz dom0_mem=256M
    module ${GRUB_DRIVE_BOOT}/vmlinuz-$j root=/dev/sda2 ro console=tty0
    echo “”

    #touch /etc/grub.d/10_xen

    #chmod 755 /etc/grub.d/10_xen

    Also popular now: