Linux: Boot from LVM

From Luky-Wiki
Jump to: navigation, search

Yes, it is possible to boot Linux directly from LVM without legacy /boot partition. If you don't need fancy graphic for GRUB then configuration is really simple. Here are mandatory prerequisites:

  • only GRUB version 1.9*, 2.00 and newer support booting from LVM
  • there should be enough "space" before first partition on disk
  • during installation correct modules should be selected (or simply all)

First partition should start at 2048 sector otherwise there is not enough free space for GRUB2. If your boot device looks like this one:

# fdisk -l /dev/sda

Disk /dev/sda: 640.1 GB, 640135028736 bytes, 1250263728 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc3b3f0e3

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048  1250263727   625130840   8e  Linux LVM

then continue with next steps. If first partition occupy part of first 2048 sectors, then you should shift (move) it first.

Configuration of GRUB2 (without graphics) looks similar to configuration of legacy GRUB. Here is my configuration as example:

# grub.cfg for phoebe

set default="0"
set timeout="3"

insmod part_msdos
insmod lvm
insmod ext2

set root=lvm/vg_phoebe-lv_boot

menuentry "Gentoo GNU/Linux" {
        linux /vmlinuz root=/dev/vg_phoebe/lv_root rootfstype=ext4 nodetect dolvm quiet net.ifnames=0
        initrd /initramfs

menuentry "Memory test (memtest86+)" {
        linux16 /memtest86plus/memtest.bin


Most important part is insmod. This will instruct GRUB to load proper modules which are essential for kernel load from logical volume (ext2 module cover also ext3 and ext4).

Note: "set root" statement changed between version 1.99 and 2.00. Correct syntax is following:

  • 1.99 -> set root="(vg_phoebe-lv_boot)"
  • 2.00 -> set root=lvm/vg_phoebe-lv_boot

As last step is important to store GRUB2 in boot area of disk. If you don't care that all modules are installed (as me also) then invoke:

# grub-install /dev/sda
Installation finished. No error reported.

It should finish with no errors (of course) and installation can take longer than similar task for legacy GRUB. If you want only specific modules installed then use --install-modules option for grub-install