Let me state up front that it will be an automatic deduction of 10 geek
points for anyone who asks me why.

Some day I might find a good boot loader with lvm2 support built in but,
for now, I will be using grub with a small boot partition not part of
lvm2. Everything else (root, swap, etc.) will all be in lvm2.

The basic steps are to

1) Configure your system with a small boot partition at the front and
add the rest of your disk space into lvm2. There is plenty of details
out there for setting up lvm2 so I will not go into it here.

2) Create logical partitions for root (/), and for swap and for anything
else you feel like having logical partitions for.

3) Install your system onto the lvm2 logical volumes.

4) Compile your kernel (suspend2 sources to use hibernate) with dm-mod
(either in kernel or as a module) and with ramdisk and initial ramdisk
support. The ram disk can't be compiled as a module.

5) Create your initial ram disk with the script provided in this how to.

6) Setup grub (that's what I use, if you use lilo it will work, but you
won't find the directions here) pointing to your kernel with parameters
lvm2root and lvm2resume2 pointing to your lvm2 root logical volume and
your lvm2 swap logical volume respectively

7) Enjoy the coolness of a fully lvm2 system with all that flexibility
and software suspend.

CONFIGURING THE DISK

I make my boot partition 50Megs. That gives me room for about 20 kernels
before I need to start cleaning things up. You can make yours any size
your want, just put it at the front of the disk and give it a partition
type of 83.

I made the rest of the disk (partition 2) with a type of 8e. That is
certainly not the only way to do it, but it works and makes pretty good
sense. There is no reason you can't add a second disk with 1 (or more)
partitions of type 8e and use them as part of this setup.

CREATING LOGICAL VOLUMES

With LVM2 you can use a different strategy than you might be used
to. Instead of building your partitions big enough for anything you
might throw at them, you want to build your logical volumes so that they
are pretty close to full. Leave enough room for day to day operations
but since you can grow the space any time you need to, don't lock it
into a partition until you really need it.

For example, 4G for slash on my laptop is good and snug. If you
separated out /usr/portage into another logical partition, I could make
that even smaller. Your swap partition can me made nice and small (just
enough room to run the larger programs you normally run) maybe less than
your current memory size. If you want to run something big that will
actually use a lot of swap, just create a second swap volume and add it
in on the fly.

INSTALLING YOUR SYSTEM

The install goes just the way it would on a normal system. Once you
chroot into your logical volumes, you won't be able to tell the
difference. Just be sure to install the lvm2 package.

COMPILING YOUR KERNEL

I would suggest using the suspend2-sources. While you can use the
vanilla-sources and patch it yourself, that loses it's charm after
about the second kernel upgrade.

The only things you need to have above and beyond what you need for
your system and for setting up the software suspend2 stuff is the
device mapper and initial ram disk. You can find the device mapper in
drivers->multi device and you can either compile it in the kernel or
add it as a module. You can find the ram disk support in devices->block
devices and you must compile it in the kernel. You also need to select
initial ram disk support.

Compile and install your kernel in the normal fashion.

CREATING THE INITIAL RAMDISK

This is the tricky part. Your initial ramdisk will need to activate
lvm2, initialize software suspend2 functionality and switch to the lvm2
root filesystem. For software suspend2 to work, it has to do all that
without using a read/write filesystem on your ramdisk.

I started with the lvm2create_initrd script that comes the lvm2 sources
and added Gentoo specific changes (such as using the full featured
statically compiled busybox in Gentoo called bb) and then added in
changes to deal with not mounting the ramdisk read/write.

This script will calculate the size of ramdisk needed to hold the
required utilities (currently /sbin/lvm and /bin/bb) as well as any
additional modules and then it creates the ramdisk and copies everything
needed into it.

The script also builds an /sbin/init script for the ramdisk that will
deal with activating lvm2 and setting up software suspend2.

Creating the ramdisk got a little tricky because busybox on Gentoo
compiles in so many of the applets that I ran out of inoes when linking
in all of the command names. The script now specified the number of
indoes needed as 500 and that seems to cover the current needs.

Creating a /sbin/init script that meets the requirements of lvm2 and
software suspend2 was also tricky. In order for software suspend2
to be willing to resume from a suspend, no device backed filesystem
can be mounted rw before the resume. The ram disk is a device backed
filesystem. In order to activate lvm2, the device mapper has to be
loaded and device files need to be created matching the current device
major and minor numbers. Those files can't be created in the /dev in the
ramdisk or you break the read/write rule. The solution turned out to be
mounting a tmpfs filesystem over /dev (tmpfs has no device associated
with it) and re-creating dev there and then building the rest of what is
needed.

Due to the dynamic nature of the device mapper's major and minor
numbers, there is no way for the kernel to deal with the normal
parameters of root= and resume2= while booting. For this reason,
the /sbin/init script will look for the parameters lvm2root= and
lvm2resume2= and use them to define the root and resume partitions after
lvm2 is activated.

To activate software suspend2, you need to provide a value for
resume2 in /proc/suspend2/resume2 and then create the file
/proc/suspend2/do_resume. This will not make any sense to the kernel
until after lvm2 is activated.

EDIT: As of 1.94-r3 of the hibernate scrips, I have had to put the line

EDIT: Added support for tuxonice (thanks to Heinzi)

EDIT: 3/19/08 Increased number of indoes in mke2fs command.

EDIT: 4/18/08 Re-worked script to use cpio based initrd instead of ramdisk.

# Read command line arguments.
#
# Device-Mapper dynamically allocates all device numbers. This means
# it is possible that the root volume specified to LILO or Grub may
# have a different number when the initrd runs than when the system
# was last running. In order to make sure the correct volume is
# mounted as root, the init script must determine what the desired
# root volume name is by getting the LVM2 root volume name from
# the kernel command line. In order for this to work correctly,
# "lvm2root=/dev/Volume_Group_Name/Root_Volume_Name" needs to be passed
# to the kernel command line (where Root_Volume_Name is replaced by your
# actual root volume's name. The same problem exists for resume2 and is
# fixed by passing "lvm2resume2=..."

# tack on stuff for modules if we declared any and the files exist
if [ -n "$MODULES" ]; then
if [ -f "/etc/modprobe.conf" ]; then
INITRDFILES="$INITRDFILES /etc/modprobe.conf"
fi
if [ -f "/lib/modules/modprobe.conf" ]; then
INITRDFILES="$INITRDFILES /lib/modules/modprobe.conf"
fi

This should create the file initrd-lvm2-2.6.17-suspend2-r2.gz in your
/boot directory (be sure it is mounted first).

SETTING UP GRUB

You will need to provide a few non standard options to the kernel by
appending them on the kernel command line in grub. You will also need
to change the standard root= to be root=/dev/ram0, while I believe that
should be the default when using a initial ramdisk, I have had much
better luck when specifying it explicitly on the command line. Also, it
won't hurt to add ro to be sure your ramdisk is mounted read only.

The first non standard option to add is lvm2root. Have this point to
your root partition in lvm2 for example, mine is

Code:

lvm2root=/dev/vg00/root

The second non standard option is lvm2resume2. This should point to your
swap partition in lvm2.

You can also add lvm2rescue to drop into a shell after activating lvm2
so that you can do any system maintenance or repair before finishing the
boot.

So, there, I exit the shell and my box boot as usual, but I notice, I got :

Quote:

umount: /initrd not found

To fix it, I taked many ways.
In a first time, I add pivot_root with the -e option. I also use $BINUTILS variable to add it. But this doesn't resolv anything.
After that, I verfiy if pivot_root was on my initrd and it is. There is a symlink to busybox bin. So, I turn my attention to busybox and I try to emerge it with static use flag. And like you can imagine, if I've always this issue : this doesn't change anything.

The original version worked however. I don't actually see where the error should be, so could you
please verify if it also exists on your machine? If there is a mistake please correct it, since I built my machine
on your script. It is verry nice, but I need it after kernel updates for the system to come up with the new kernel (and ramdisk!)

# Read command line arguments.
#
# Device-Mapper dynamically allocates all device numbers. This means
# it is possible that the root volume specified to LILO or Grub may
# have a different number when the initrd runs than when the system
# was last running. In order to make sure the correct volume is
# mounted as root, the init script must determine what the desired
# root volume name is by getting the LVM2 root volume name from
# the kernel command line. In order for this to work correctly,
# "lvm2root=/dev/Volume_Group_Name/Root_Volume_Name" needs to be passed
# to the kernel command line (where Root_Volume_Name is replaced by your
# actual root volume's name. The same problem exists for resume2 and is
# fixed by passing "lvm2resume2=..."

# tack on stuff for modules if we declared any and the files exist
if [ -n "$MODULES" ]; then
if [ -f "/etc/modprobe.conf" ]; then
INITRDFILES="$INITRDFILES /etc/modprobe.conf"
fi
if [ -f "/lib/modules/modprobe.conf" ]; then
INITRDFILES="$INITRDFILES /lib/modules/modprobe.conf"
fi
fi

Don't forget to set root=/dev/ram0 in kernel parameters
Don't forget to set lvm2root=/dev/VG/LV in kernel parameters, where LV is your root volume
If you use lilo try adding/modifying an entry similar to this one in lilo.conf:

And adding with --mknodes because Gentoo LVM2 guide mentions that if the installation has been interrupted, as is in my case many times, that need to be added using LiveCD. So I put it on the scripe as well.

/rootvol is part of the initrd image. If it is not there, your image might be bad. This brings me to your ramdisk size, I find the 4096 suspect. Mine is 5152. The script that creates the ramdisk tells you what size to use. What did it say?

# Uncomment this if you want to disable automatic size detection
#INITRDSIZE=4096

And in my kernel was set to that number as well I thought I should've uncommented it. But if the size is greatet than 4096 what about the kernel? Should I change the kernel and put more? And what multiple should I use?

Well now I am not sure what to follow next, whether uncomment that line first and re-run the scrip or change the kernel value to something higher.

The script will spit out a suggested command line that you can modify the way you want. I don't change the size in the kernel config since I won't know the size until after I copy in what I need and that might change from time to time.

Raffi thank very much for your support I will try this right now and see the results. This is an excellent script I wish instalation on LVM2 would be mainstream instead of a dark practice. Also I have a proposal to add this into Gentoo's LVM2 guide and put in the wiki, with your permision if you agree of course. Perhaps give directions on how to set up the script for laptops and a section for desktops. The Gentoo LVM2 installation has a resources section where they provide an appaling and pathetic link on how to set up root on LVM. It just doesn't make any sense, while Gentoo's guide explicitly talks about LVM2 which now is at version LVM2-2.02.10, the outdated link, "Date: Fri, 20 Oct 2000 23:41:44 +0200" is using LVM 0.7 . To make matters worst it only talks about setting lilo and the freaking guy doesn't even run Gentoo!!!

Quote:

I was using a SuSE 6.4 install

WTF??!!

What do you think about proposing this to the people in charge of LVM2 guide?

This solve everything and I was able to boot without an issue. Now this left me scratching my head over the reason why the script didn't give you this problem and why it did for me. Although I am not a coder I peered inside your script in order to see if I could relate something to that failed message. These are the parts where I found rootvol and I did not see "mkdir rootvol" anywhere.

I did pass several combinations of options in the kernel including "noapic", because googling had a solution doing this, however it stops all the after kernel boot with that message!!!

Are there general rules for re-compiling the system/world/kernel in order to create the initrd image?

Googling actually didn't yield any meaningful results for this that applies to Gentoo.

Thanks

[EDIT] I just wanted to make sure that it doesn't matter whether lvm2 and busybox aren't compiled with the STATICALLY. You said before that busybox automatically creates a static version of itself.

[EDIT 2] By the way something really weird happened, when I used LiveCD and mounted / I went to check /proc directory and it was completely empty!!! As far as I know that there's been always stuff on /proc directory. I am truly perplexed as to what might've cause this!!!