I'm having difficult time installing grub in LVM LV container for a VM. This is the partition table:

# parted /dev/mgtvg/linux2os print
Model: Linux device-mapper (linear) (dm)
Disk /dev/dm-7: 129GB  
Sector size (logical/physical): 512B/512B
Partition Table: msdos 

Number  Start   End     Size    Type      File system  Flags
 1      1049kB  6469MB  6468MB  primary   ext3         boot
 2      6469MB  11.8GB  5369MB  primary   xfs
 3      11.8GB  17.2GB  5369MB  primary   xfs
 4      17.2GB  129GB   112GB   extended               lba
 5      17.2GB  22.6GB  5369MB  logical   xfs

Partition one contains the root file system (there is no /boot). Attempting to install grub:

# grub --device-map=/dev/null

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> device (hd0) /dev/mgtvg/linux2os
device (hd0) /dev/mgtvg/linux2os
grub> root (hd0,0)
root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83
grub> setup

Error 1: Unrecognized device string

This is the grub.conf file from the LV containing the VM:

serial --unit=1 --speeed=19200
terminal --timeout=8 console serial
title CentOS (2.6.32-279.22.1.el6.x86_64)
        root (hd0,0)   
        kernel /vmlinuz-2.6.32-279.22.1.el6.x86_64 ro root=/dev/sda1
        initrd /initramfs-2.6.32-279.22.1.el6.x86_64.img
title CentOS (2.6.32-279.el6.x86_64)
        root (hd0,0)   
        kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=/dev/sda1
        initrd /initramfs-2.6.32-279.el6.x86_64.img

What else do I need?


You want to reference the LV by it's name and not the physical partition that it's on.

Things are structured as follows. I have 3 things:

  • A physical volume (PV)
  • A volume group (VG)
  • A logical volume (LV)

On my laptop I have the following:

$ pvs
  PV         VG         Fmt  Attr PSize   PFree
  /dev/sda6  vg_grinchy lvm2 a-   304.22g    0 

NOTE: PV = /dev/sda6, VG = vg_grinchy

$ lvs
  LV      VG         Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv_home vg_grinchy -wi-ao 248.53g                                      
  lv_root vg_grinchy -wi-ao  50.00g                                      
  lv_swap vg_grinchy -wi-ao   5.69g          

NOTE: So my VG (vg_grinchy) contains 3 LVs (lv_home, lv_root, and lv_swap).

You can confirm this with the vgs command:

$ vgs
  VG         #PV #LV #SN Attr   VSize   VFree
  vg_grinchy   1   3   0 wz--n- 304.22g    0 

NOTE: See it says we have #LV = 3, and #PV = 1.

Now if we use the command lvdisplay, we can see the full names of our LVs:

$ lvdisplay |grep "LV Name"
  LV Name                /dev/vg_grinchy/lv_root
  LV Name                /dev/vg_grinchy/lv_home
  LV Name                /dev/vg_grinchy/lv_swap

These are the names that you should be using to specify which LV to mount in your grub.cfg file.


Below is one of my stanzas from my grub.cfg file.

title Fedora (
    root (hd0,4)
    kernel /vmlinuz- ro root=/dev/mapper/vg_grinchy-lv_root rd_LVM_LV=vg_grinchy/lv_root rd_LVM_LV=vg_grinchy/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=l
atarcyrheb-sun16 KEYTABLE=us rhgb quiet
    initrd /initramfs-

Sure enough you can see that my kernel is getting passed the following:

|improve this answer|||||
  • True if you're using LVM inside the VM. In this case, the LV in the Physical host is used as a container for the VM which partitions it without using LVM itself (it sees a raw device which happens to be a LV on the physical host). In other words, it's not LVM on top of LVM. – vamfoom May 8 '13 at 5:11
  • Are you saying that the host of the VMs has a LVM and the guest VMs have their .img files sitting in that LVM? Can you better explain this setup? – slm May 8 '13 at 5:18
  • Right, except that the guest LVM doesn't use a .img file -- it uses the LV created for it. The LV is created on the Physical host and passed on as raw device to the VM. Inside the VM, raw partitions are created instead of using LVM again. The VM doesn't see any LVM information -- it just sees a physical disk with raw partitions. – vamfoom May 8 '13 at 18:20
  • OK, thank you, now I understand what you're trying to do. – slm May 8 '13 at 18:27

You might be missing the device files for those partitions. In other words:

kpartx -a -v /dev/mgtvg/linux2os

This should create something like:



After that, you might be able to do

grub-install /dev/mapper/mgtvg-linux2os

This will in turn resolve (hd0,0) or (hd0,msdos1) into /dev/mapper/mgtvg-linux2os1, and then things might actually work.

Note that I would also do all this within a chroot. The chroot /dev has to have the VM-relevant device nodes from the parent machine, as well as /proc. That way you'll be sure not to mess with the parent's grub.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.