LVM

http://www.thegeekstuff.com/2010/08/how-to-create-lvm/

  1. Determine resources that we be used for LVM. Typically, these are standard partitions but can also be Linux software RAID volumes. In LVM terminology, these resources are called 'physical volumes'.
  2. Initialize these 'physical volumes' so that they can be recognized by LVM. This involve setting up correct partition type, and running pvcreate command.
  3. Create a volume group. You can think of a 'volume group' as a pool of storage that consist of one or more physical volumes. While LVM is running, we can add physical volumes to the volume group or even remove them. However, we can't mount or create filesystems on a volume group directly. Instead, we can tell LVM to create one or more 'logical volumes' using our volume group storage pool. Creating an LVM logical volume is easy, and once it's created, we can go ahead and put filesystem on it, mount it, and start using it to store our files. To create a logical volume, we use the lvcreate command, specifying the name of our new volume, the size we'd like the volume to be, and the volume group that we'd like this particular logical volume to be part of. The LVM system will then allocate storage from the volume group we specify and create our new volume, which is now ready for use. Once created, we can put an ext2 or reiserfs filesystem on it, mount it, and use it as we like.

Behind the scenes, LVM system allocates storage in equal-sized chunks, called extents. We can specify the particular extent size to use at volume group creation time. The size of an extent defaults to 4Mb, which is perfect for most uses. One of the beauties of LVM is that the physical storage locations of the extents used for one of our logical volume (in other words, what disk they're stored on) can be dynamically changed while our logical volume is mounted and in use! The LVM system ensures that our logical volumes continue to operate while allowing the administrator to physically change where everything is stored.

Of course, since everything is created out of equally-sized extents, it's really easy to allocate some additional extents for an already-existing logical volume — in other words, dynamically grow the volume.

Once the logical volume has been expanded, you can then expand your ext2 or reiserfs filesystem to take advantage of this new space. If you use program such as resize_reiserfs, this filesystem expansion can also happen while the volume is mounted and being used.

The only time you need to shutdown your system is when you need to add new physical disks. Once new disks have been added, you can add these new physical volumes to your volume group(s) to create a fresh supply of extents.

  1. Install new hard drive
  2. Use cfdisk to partition the drive, and set the partition type to 8E (the official LVM partition type).
  3. Reboot to force a reread of my partition table.
  4. Initialize the new partition as a physical volume
  5. Create a volume group using this physical volume
  6. Allocate some of the extents on the volume group

Initialize the new partition as physical volume:

pvcreate /dev/hda5

pvcreate set up a special "accounting" area on /dev/hda5, called the VGDA ("volume group descriptor area"). LVM uses this area to keep track of how the physical extents are allocated, among other things.

Create a volume group called main:

vgcreate main /dev/hda5

The vgcreate command did a couple of things. In addition to creating the "main" volume group, it also set up /dev/hda5 to use 4 MB extents, the default extent size. This means that any logical volumes I create from this volume group can be expanded and shrunk in 4 MB increments.

Due to kernel limitations, the extent size determines the maximum size that a logical volume can be. As you can see from the above output, a 4 MB extent size imposes a logical volume size limitation of 256 Gigabytes, which is an easily attainable logical volume size if you're adding several high-capacity drives to your volume group. If your volumes could end up being greater than 256 GB apiece, I recommend specifying a larger extent size at vgcreate time. Extents can range anywhere from 8 KB to 512 MB, and must always be a multiple of two. By increasing the extent size above 4 MB, the maximum physical volume size will be scaled accordingly, up to a maximum of 1 Petabyte (although the current real-world size limit is 2 Terabytes on x86 systems). For example, if I wanted to create a volume group with 32 Megabyte extents, I'd type:

vgcreate -s 32M main /dev/hda5

32 MB is a good extent size, since a 32 MB granuarity is still manageable and pushes the maximum logical volume size to 2 Terabytes to boot. Once your volume group is created, you can view its information by typing "vgdisplay"

Create an 8G logical volume called lv_home:

lvcreate -L8G -nlv_home main

Create a filesystem on the logical volume:

mkreiserfs /dev/main/lv_home

Mount the logical volume:

mkdir /mnt/newhome
mount /dev/main/lv_home /mnt/newhome
init 1
cp -avx /home/* /mnt/newhome
cd /
mv home home.old
mkdir home
umount /mnt/newhome
mount /dev/main/lv_home /home

Add

/dev/main/lv_home   /home            reiserfs     defaults      2 2

to /etc/fstab so that it included a new /home entry (so that my new /home partition would be available every time the machine started up).

Modify the "checkroot" startup script so that the following commands would run immediately after my root partition was remounted read/write:

/sbin/vgscan
/sbin/vgchange -a y

Modify my filesystem unmounting script that gets run on shutdown, so that the following command would run immediately after all filesystems were unmounted:

/sbin/vgchange -a n

Add additional capacity to the "lv_home" logical volume:

lvextend -L+2G /dev/main/lv_home

Use the resize_reiserfs utility to expand the filesystem so that it would use this additional capacity:

resize_reiserfs -f /dev/main/lv_home

http://www.ibm.com/developerworks/library/l-lvm2.html
What about RAID, hot swap?
What about performance?

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