Using Linux Logical Volume Management and RAID on top of ordinary devices offers powerful administrative as well as performance benefits. One thing I find myself looking up once a year or so (when storage is filling up) is some brief step-by-step snipplets for LVM2.
RAID setups allow combining multiple, inexpensive disks to a combined storage. This is usually used to increase the storage size for database applications or other content required to be processed in it's entity or to protect against disk failures by redundantly storing the information and/or parity information on multiple disks.
To create a software RAID under Linux with the new-style mdadm utilities with 4 disks and RAID5 the command simply is:
or a more lightweight (SOHO :-) setup with just 2 disks for a RAID1 mirror setup:
On initial creation the array will be sychronizing and the progress can be monitor, for example via /etc/proc:
Logical Volume Management allows to break thru the static, and often limitting historic partitioning of disks. Be it the PC map with 4 primary + n logical parition, the Sun or Apple partition maps, or others. LVM allows to flexible size, add and resize logical volumes. Thefore the LVM is given the control over multiple block storages and later used to flexible allocate chunks. Depending on the actual filesystem used on the logical volumes, most modern ones can be even resized, often grown, some even shrinked (more details on that below).
To initialize a disk or partition for use by LVM pvcreate must be used. Each of those physical volumes can be a disk partition, whole disk, meta device, or loopback file. In this example we want to use the previously created RAID device:
Next, the logical volume group has to be initialized with vgcreate:
And finally the logical volume group can be devided (sliced) into the individual volumes as required with lvcreate:
The resulting device nodes can be used, usually by creating and mounting a filesystem as usually:
Of course additional volumes can be added:
To enlarge (extend, grow) an existing lvm both, the logical volume as well as the underlying filesystem have to be resize. On the LVM side the commands to archive this are lvextend and lvreduce plus the filesystem specific tool like resize2fs or resize_reiserfs. To extend the just created "www" volume, formated with ext3 by 1GB the command sequence would be:
Note that unless you have a "online ext2/3 resize patched kernel" you need to unmount the often used ext2/3 filesystem. Some filesystems, such as jfs, reiserfs and xfs can be resized while mounted (online).
René Rebe studied computer science and digital media science at the University of Applied Sciences of Berlin, Germany. He is the founder of the T2 Linux SDE (System Development Environment), and contributer to various projects in the open source landscape for more than 10 years, now. He also founded the Berlin-based software company ExactCODE GmbH. A company dedicated to exact software solutions that just work, everyday.