[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with grub2 on lvm

From: Simon Hobson
Subject: Re: problem with grub2 on lvm
Date: Thu, 4 Oct 2012 21:24:09 +0100

Ingo Becker wrote:

i am trying to create a bootable vm using grub2.

vm ? So this is for a virtual machine.

Here are the steps i tried:

1. creating a logical volume using lvcreate
2. creating a partition-table with one ext partition inside the logical volume: #parted -s /dev/${VGNAME}/${LVNAME} unit GB mklabel msdos mkpart primary ext2 0 ${LVSIZE}
4. kpartx -a /dev/${VGNAME}/${LVNAME}

Personally I just create a filesystem in the lv, I don't partition it. Apart from a few minor issues*, it's a lot easier to manage.

My question is, whats the right way to install grub2 to the lvm device? Or is there a way to install grub2 to a logical volume without a partition-table (/dev/vg/debianvm)? Do i have to chroot to the system to install grub or is there a way to install it from the host?

It depends, a *LOT*, on what your virtualisation system is and how you are using it. I'm only familiar with Xen and Debian, so here's how I manage it. Bear in mind it's a while since I last set any of this up, and I'm probably not using the same setup as you are. To "fiddle" with the guest I just mount it's device, eg "mount /dev/vg/debianvm /mnt" - you can now mess around with fstab, network, etc. I tend to create new machines by just copying a base install I cooked up ages ago - far quicker than doing it from scratch. Unmount when done.

But before unmounting, I copy the kernel (vmlinuz) and initrd to the host, and boot using these files.

Once the VM is running, it's then a lot easier to set stuff up. grub-update should create all the files - but I grub-install on anything as I'll use pygrub (if it works !).

A quick search suggests that you can install the grub stage 0 in a partition - it only needs one disk sector I believe, and then it loads the rest using a sector list embedded in that first sector of code. Once that's loaded, it can read the filesystem to get the second stage etc.

So if you are doing full virtualisation, rather than para in Xen, then you should be able to install grub in the lv and have it boot the system.

* Main one is remembering that your filesystem is on the raw device rather than a partition within it - eg with Xen that would be xvda rather than xvda1.

Simon Hobson

Visit for books by acclaimed
author Gladys Hobson. Novels - poetry - short stories - ideal as
Christmas stocking fillers. Some available as e-books.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]