LVM and RAID

GRUB has support for LVM and RAID since version 1.95. Multiple volume groups don't work with GRUB 1.95 however. This bug has been fixed in 1.96.

Also, (as of 1.96+20080724) GRUB can only boot from RAID which uses a Version 0.90 metadata superblock (i.e. one created with the --metadata=0.90 option to mdadm). To check your superblock version, do "mdadm -Q --detail /dev/mdX"

modules

The modules required to make LVM and RAID work are 'lvm' and 'raid', respectively.

grub.cfg

To enable LVM support, place the following in your grub.cfg file:

    insmod lvm

Similarly, RAID support can be enabled by placing the following in your grub.cfg file:

    insmod raid

You will then be able to get the RAID and/or LVM volumes listed in the grub command line, typing 'ls'.

RAID

For RAID arrays, the same name is used as the Linux devicename. E.g. if the array is /dev/md2 under Linux, its GRUB name is (md2). The number is taken from the superblock. If it happens that there are two different arrays with the same number in their superblocks the first free number is used.

LVM

LVM volumes are named (volumegroup-volumename). This is the same format as the name of the devices in /dev/mapper.

core.img

If your boot partition (the one containing grub data) is part of an LVM, the module must be part of your core.img rather than being loaded at grub.conf processing time. In order to create a core.img with lvm support, perform the following:

    grub-mkimage --output=/boot/grub/core.img ext2 _chain part_msdos part_gpt biosdisk lvm

The core.img is usually installed outside of logical volumes so that it's physical location doesn't change on it's own.

For IBM/MS-DOS partitions this means that there should be ample space between the MBR and the start of the first partition so that the core.img can be written there.

When using GPT there isn't any free space available between the MBR and the first partition since this area is used by the GPT. When you want to store the core.img on a GPT labeled device, you need to create a BIOS Boot Partition, which GRUB will detect and use.

pc-style partitions

If your Physical Volumes are PC-style partitions, you must put the pc module before the lvm module in core.img.

/boot on RAID or LVM

Installing GRUB while /boot is on RAID and/or LVM should be straightforward. Grub-setup will detect that and specify the GRUB root device/prefix accordingly, so GRUB will be able to find the files in /boot. If you have a RAID array you can specify the RAID device as destination device. Grub-setup will look at the members of the RAID array and install on the MBR of each disk.

Note: package grub-pc in Debian Lenny (version 1.96+20080724) does not work on LVM over RAID, so you need to build grub from SVN, or get version 1.97~beta3-1 or older from testing (http://packages.debian.org/squeeze/amd64/grub-pc).

Example grub.cfg for LVM

Below is a sample grub.cfg using LVM. Linux is installed under MainGroup-linuxLV where MainGroup is the VolumeGroup und linuxLV is the logical volume. Notice that vmlinuz (the linux kernel) and initrd.img are lying in the logical volume and can be accessed by symlinks.

set timeout=20
set default=0
menuentry "Linux on LVM" {
        insmod lvm
        set root=(MainGroup-linuxLV)
        linux /vmlinuz root=/dev/mapper/MainGroup-linuxLV
        initrd /initrd.img
} 

Example grub.cfg for RAID

This is an example of grub.cfg when the /boot filesystem is on a RAID device.

insmod raid
set root=(md0)
search --fs-uuid --set 155c8fdb-607f-45a4-bd6d-0dd89f21eac2

menuentry "Linux" {
        insmod raid
        set root=(md0)
        search --fs-uuid --set 155c8fdb-607f-45a4-bd6d-0dd89f21eac2
        linux    /vmlinuz-2.6.31 root=LABEL=root ro
        initrd   /initrd.img-2.6.31
} 


GrubWiki: LVMandRAID (last edited 2009-12-27 11:44:24 by NickAndrew)