2012. március 16., péntek

Debian Linux can boot an LVM root partition

I installed Debian Squeeze on my Dell laptop and partitioned the disk to be fully managed by LVM. Including the root (/) partition and I got GRUB set up the MBR as the primary boot loader. After the successful installation, GRUB can load the root filesystem with an LVM partition! In other words, it can boot it without any extra tricks (i.e.: /boot filesystem separate partition, etc.) contrary to Ege Turgay, a Linux sysadmin from Turkey, who claimed that Linux cannot boot an LVM partition unless /boot is on a separate partition not being part of LVM. All the files / partitions are on LVM and Debian Linux Squeeze is able to boot the OS seamlessly. Here are the setup below.

root@debian:/boot/grub# cat /etc/mtab
/dev/mapper/debian-root / ext4 rw,errors=remount-ro 0 0
tmpfs /lib/init/rw tmpfs rw,nosuid,mode=0755 0 0
proc /proc proc rw,noexec,nosuid,nodev 0 0
sysfs /sys sysfs rw,noexec,nosuid,nodev 0 0
udev /dev tmpfs rw,mode=0755 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
devpts /dev/pts devpts rw,noexec,nosuid,gid=5,mode=620 0 0
/dev/mapper/debian-var /var ext4 rw 0 0
fusectl /sys/fs/fuse/connections fusectl rw 0 0


Above you can see that the root partition is on /dev/mapper/debian-root on LVM and there is no separate /boot partition. Another partition, /var is on /dev/mapper/debian-var on LVM as well (but that does not make any difference to the point) and no other tricks or glitches. Below I am going to show you my grub.cfg which contains an important line that makes it possible. 


root@debian:/boot/grub# cat grub.cfg |grep -C3 lvm
(...)

menuentry 'Debian GNU/Linux, with Linux 2.6.XX-X' --class debian --class gnu-linux --class gnu --class os {
insmod lvm
insmod part_msdos
insmod ext2
set root='(debian-root)'
--
initrd /boot/initrd.img-2.6.XX-X
}
(...) 

Pay attention to the red line above. When GRUB is loaded from the MBR, it loads an lvm module so that it can handle LVM partitions without issues. This is so simple! :-) And it's not even the latest, most up-to-date Linux version or distro, but it is a rather old version, the stable distro from Debian, with a relatively obsolete kernel. See the root partition below that is indeed an LVM.

root@debian:/boot/grub# uname -a
Linux debian 2.6.32-5-686-bigmem #1 SMP Mon Jan 16 16:42:05 UTC 2012 i686 GNU/Linux
root@debian:/boot/grub# grub-install -v
grub-install (GRUB) 1.98+20100804-14+squeeze1
root@debian:/boot/grub# lvdisplay /dev/debian/root

--- Logical volume ---
  LV Name                /dev/debian/root
  VG Name                debian
  LV UUID                yYjrfl-keey-KNrH-tbC8-R7B3-Luwi-OKMAMH
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                186.26 GiB
  Current LE             47683
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0

root@debian:/boot/grub#

Nincsenek megjegyzések: