GNU/Linux booting from a logical volume

In this tutorial, I'll give you a couple of tips on how to organize your data in order to be more flexible and allow for more kernels, distributions and all that stuff.
My first tip, would be regarding the boot partition, it should be a LV. Create a new LV, name it boot and a size of about 100MB. Next, mount it as /boot and install GRUB2. In case it gives you an error message saying there is not enough space to embed the image, you'll need to free up some space at the start of the hdd so that there are some MB of unpartitioned space there (I think 20MB - 25MB should be enough, though I'm not really sure).
Let's say that you named it lvboot and the VG it resides within is vg0. Edit the grub.cfg on it, so that the root is vg0-lvboot. Eg:

set root=(vg0-lvboot)

Also, I good thing to have is a different directory hierarchy on /boot. In case you're interested, here's mine:

boot

  • [dir] grub (all of grub2's files)
  • [dir] kernels
    • [dir] 2.6.26
      • vmlinuz-2.6.26
      • initrd.img-2.6.26
      • System.map-2.6.26
      • config-2.6.26
      • [link] vmlinuz -> vmlinuz-2.6.26
      • [link] initrd.img -> initrd.img-2.6.26
      • [link] System.map -> System.map-2.6.26
      • [link] config -> config-2.6.26
    • [dir] 2.6.24-19-generic
      • (same scheme as above)
    • … (other directories with kernels)
    • [link to dir] defkern -> 2.6.26
  • [link] vmlinuz -> kernels/defkern/vmlinuz
  • [link] initrd.img -> kernels/defkern/initrd.img
  • [link] System.map -> kernels/defkern/System.map
  • [link] config -> kernels/defkern/config
  • [dir] modules
    • [dir] 2.6.26 (directory with all the modules for the 2.6.26 kernel)
    • [dir] 2.6.24-19-generic (the same for kernel version 2.6.24-19-generic)
    • … (the rest of the kernels)
  • [dir] src
    • [dir] 2.6.26 (directory with 2.6.26 kernel's sources)
    • [dir] 2.6.24-19-generic (the same for the 2.6.24-19-generic one)
    • … (the rest of the kernels)

Yes, I know, it is a little big, but notice the flexibility: I can have as many kernels as I want, each residing in it's own directory. Also each file that the kernel consists of has a symlink to it (vmlinuz, initrd.img, config). They will help me when booting from a specific kernel, because instead of adding the line linux /kernel/2.6.26/vmlinuz-2.6.26, I simply add linux /kernel/2.6.26/vmlnuz. This comes to further use when using the defkern symlink. As you've might of guessed, it points to the default kernel, so the line then becomes /kernel/defkern/vmlinuz. Now notice that I don't have any version information on my grub.cfg. I simply use defkern to point to any kernel I desire. Thus easying the work when changing from one default kernel to another.

Also notice that I have both my modules and my sources on /boot. This is because we want every kernel to run every distribution on our system. If we didn't had the modules and sources on a partition accessible from every where, we would had to recompile each kernel for each distribution in order to install the modules in /lib. With this approach, a simple symlink or binded mount will solve the problem. Note that you may want to edit the build and source symlinks in /boot/modules

NOTE: having modules in /boot doesn't work. I'll need to find a fix. In any case you can use the other directories, just don't add all of you modules on the boot partition. This is because the sistem will first try to load all of the modules, then mount the boot partition.
NOTE2: the above hasn't been confirmed
NOTE3: editing the initrd may work

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License