Growth and Reallocation
Suppose that over the next year, the storage system fills up and needs to be expanded. Initially, you can begin allocating the unallocated space. For instance, to increase the amount of space available for shared files from 10GB to 15GB, run a command such as:
# lvextend -L15G /dev/datavg/sharelv # resize_reiserfs /dev/datavg/sharelv
But over time, all the unallocated disk space will be used. One solution is to replace the four 250G drives with larger 800G ones.
In the case where you use RAID 1, migration is straightforward. Use
mdadm to mark one drive of each of the RAID 1 mirrors as failed, and then remove them:
# mdadm --manage /dev/md0 --fail /dev/sda1 # mdadm --manage /dev/md0 --remove /dev/sda1 # mdadm --manage /dev/md0 --fail /dev/sdc1 # mdadm --manage /dev/md0 --remove /dev/sdc1
Pull out the sda and sdc hard drives and replace them with two of the new 800G drives. Split each 800G drive into a 250G partition and a 550G partition using
fdisk, and add the partitions back to md0 and md1:
# fdisk /dev/sda # fdisk /dev/sdc # mdadm --manage /dev/md0 --add /dev/sda1 # mdadm --manage /dev/md1 --add /dev/sdc1
Repeat the above process with sdd and sdb to move them to the other two new drives, then create a third and fourth RAID device, md2 and md3, using the new space:
# mdadm --create /dev/md2 -a -l 1 -n 2 /dev/sda2 /dev/sdd2 # mdadm --create /dev/md3 -a -l 1 -n 2 /dev/sdb2 /dev/sdc2
Finally, add these to LVM:
# pvcreate /dev/md2 /dev/md3 # vgextend datavg /dev/md2 /dev/md3
The file server now has 1.6TB of fully redundant storage.
LVM and Desktops
So far, we've talked only about LVM and RAID for secondary disk space via a standalone file server, but what if you want to use LVM to manage the space on a regular desktop system? It can work, but there are some considerations to take into account.
First, the installation and upgrade procedures for some Linux distributions don't handle RAID or LVM, which may present complications. Many of today's distros do support it, and even provide tools to assist in creating and managing them, so check this first.
Second, having the root filesystem on LVM can complicate recovery of damaged file systems. Because boot loaders don't support LVM yet, you must also have a non-LVM /boot partition (though it can be on a RAID 1 device).
Third, you need some spare unallocated disk space for the new LVM partition. If you don't have this, use
parted to shrink your existing root partition, as described in the LVM HOWTO.
For this example, assume you have your swap space and /boot partitions already set up outside of LVM on their own partitions. You can focus on moving your root filesystem onto a new LVM partition in the partition /dev/hda4. Check that the filesystem type on hda4 is LVM (type 8e).
Initialize LVM and create a new physical volume:
# vgscan # pvcreate /dev/hda4 # vgcreate rootvg /dev/hda4
Now create a 5G logical volume, formatted into an xfs file system:
# lvcreate rootvg ---name rootlv -size 5G # mkfs.xfs /dev/rootvg/rootlv
Copy the files from the existing root file system to the new LVM one:
# mkdir /mnt/new_root # mount /dev/rootvg/rootlv /mnt/new_root # cp -ax /. /mnt/new_root/
Next, modify /etc/fstab to mount / on /dev/rootvg/root instead of /dev/hda3.
The trickiest part is to rebuild your
initrd to include LVM support. This tends to be distro-specific, but look for
initrd image must have the LVM modules loaded or the root filesystem will not be available. To be safe, leave your original
initrd image alone and make a new one named, for example, /boot/initrd-lvm.img.
Finally, update your bootloader. Add a new section for your new root filesystem, duplicating your original boot stanza. In the new copy, change the
root from /dev/hda3 to /dev/rootvg/rootlv, and change your
initrd to the newly built one. If you use lilo, be sure to run
lilo once you've made the changes. For example, with grub, if you have:
title=Linux root (hd0,0) kernel /vmlinuz root=/dev/hda3 ro single initrd /initrd.img
add a new section such as:
title=LinuxLVM root (hd0,0) kernel /vmlinuz root=/dev/rootvg/root ro single initrd /initrd-lvm.img
LVM is only one of many enterprise technologies in the Linux kernel that has become available for regular users. LVM provides a great deal of flexibility with disk space, and combined with RAID 1, NFS, and a good backup strategy, you can build a bulletproof, easily managed way to store, share, and preserve any quantity of files.
Bryce Harrington is a Senior Performance Engineer at the Open Source Development Labs in Beaverton, Oregon.
Kees Cook is the senior network administrator at OSDL.
Return to the Linux DevCenter.