Sunday, April 09, 2006

Put portage stuff on LVM

Recently I installed LVM2 on /dev/hda3.
First use fdisk to change partition type for /dev/hda3 to 8e (Linux LVM)(turns out this is unnecessary when using LVM 2, but still a good thing for disk management).
Recompile kernel:

Device Drivers --->
Multi-device support (RAID and LVM) --->
[*] Multiple devices driver support (RAID and LVM)
< > RAID support
<*> Device mapper support
< > Crypt target support

If "Device mapper support" is compiled as a module, add the module "dm-mod" to /etc/modules.autoload.d/kernel-2.6.
Install the lvm2 package:
# emerge lvm2

Edit /etc/lvm/lvm.conf, find the line:
 filter = [ "a/.*/" ]

Replace it with the following one to scan /dev/hda and /dev/hdb and reject anything else:
 filter = [ "a|/dev/hd[ab]|", "r/.*/" ]

Then reboot. Now prepare the partition:
# pvcreate /dev/hda3

This creates a volume group descriptor at the start of the /dev/hda3 partition.
Create a volume group named "vg":
# vgcreate vg /dev/hda3

Create the logical volumes (just like creating partitions with fdisk):
# lvcreate -L3G -nportage  vg
# lvcreate -L3G -nccache vg
# vgdisplay vg | grep Free
Free PE / Size 667 / 2.61 GB
# lvcreate -l 667 vg -n tmp (let "tmp" take up all the rest)

Now you should see portage, ccache and tmp in /dev/vg/
Create filesystems on the logical volumes:
# mkreiserfs /dev/vg/portage
# mkreiserfs /dev/vg/ccache
# mkreiserfs /dev/vg/tmp

Move the stuff in /usr/portage, /var/tmp/ccache and /var/tmp/portage to another place and mount the logical volumes, then move the stuff back:
# mv /usr/portage/* /root/portage
# mv /var/tmp/ccache/* /root/ccache
# mv /var/tmp/portage/* /root/tmp
# mount /dev/vg/portage /usr/portage
# mount /dev/vg/tmp /var/tmp/portage
# mount /dev/vg/ccache /var/tmp/ccache
# mv /root/portage/* /usr/portage
# mv /root/ccache/* /var/tmp/ccache
# mv /root/tmp/* /var/tmp/portage

Add the following lines to /etc/fstab:
# Logical volumes
/dev/vg/portage /usr/portage reiserfs noatime 0 0
/dev/vg/ccache /var/tmp/ccache reiserfs noatime 0 0
/dev/vg/tmp /var/tmp/portage reiserfs noatime 0 0

Then if you restart your machine, all partitions will be automatically mounted.

Here comes the nice things about LVM, shrink logical volume "portage":
# umount /usr/portage/
# resize_reiserfs -s-1500M /dev/vg/portage (First, resize the filesystem)
# lvreduce -L-1500M /dev/vg/portage (resize the logical volume)
# mount /usr/portage

To extend a logical volume, we do it in a slightly different order:
# lvextend -L+1G /dev/vg/portage
# resize_reiserfs -f /dev/vg/portage (no need to umount nor specify size this time)

To add another physical partition to the volume group "vg":
# pvcreate /dev/hda9
# vgextend vg /dev/hda9

then you should be able to create more logical volumes.

Other useful commands:
# umount /dev/vg/tmp 
# lvremove /dev/vg/tmp (remove a logical volume)
# vgreduce vg /dev/hda9 (remove a physical volume from a group)
# vgchange -a n vg (deactivate a volume group)
# vgremove vg (remove a volume group)


P.S. I'm now thinking about the following scheme for dealing with portage stuff:
1) put /usr/portage on a reiserfs LV, perhaps 300MB is enough.

2) put sources in a directory other than /usr/portage/distfiles, probably /var/distfiles (may be on an independent ext3 LV).

3) put /var/tmp (which includes /var/tmp/ccache and /var/tmp/portage) on an ext2 LV, maybe 5G?

3 Comments:

Blogger Palatis said...

since you're on linux so DONT REBOOT SO OFTEN.
lvm2 applies just ON-THE-FLY!

and you don't need to comment out the 2 lines in 50-udev anyway.

7:00 PM  
Blogger Hauser said...

You're right the whole thing works even those 2 lines in 50-udev are not commented out.
But when I was preparing the partitions I had to do that and reboot, otherwise "# pvcreate /dev/hda3" wouldn't work (can't remember the error message).

3:46 PM  
Blogger Hauser said...

Now I remember, I actually couldn't create logical volumes at the time, and there's no vg in /dev (even if the group has successfully been created). I did a little search, someone says editing the 50-udev file and restarting the machine may solve the problem, so I did and it worked. Now after thinking about it I realize that it has nothing to do with 50-udev, I couldn't create logical volumes because the dev mapper driver had not been activated yet! After recompiling the kernel, I should reboot, simple as that!

5:13 PM  

Post a Comment

<< Home