Partitioning RAID / LVM on RAID

From Linux Raid Wiki
Revision as of 11:38, 4 April 2011 by Viridian Development Corporation (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Back to Related tools

Partitioning RAID / LVM on RAID

RAID devices can be partitioned, like ordinary disks can. This can be a real benefit on systems where one wants to run, for example, two disks in a RAID-1, but divide the system onto multiple different filesystems:

FIXME : This is the 'non-partitioned' approach:

 # df -h
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/md2              3.8G  640M  3.0G  18% /
 /dev/md1               97M   11M   81M  12% /boot
 /dev/md5              3.8G  1.1G  2.5G  30% /usr
 /dev/md6              9.6G  8.5G  722M  93% /var/www
 /dev/md7              3.8G  951M  2.7G  26% /var/lib
 /dev/md8              3.8G   38M  3.6G   1% /var/spool
 /dev/md9              1.9G  231M  1.5G  13% /tmp
 /dev/md10             8.7G  329M  7.9G   4% /var/www/html

Partitions on a RAID device

A RAID device can only be partitioned if it was created with an --auto option given to the mdadm tool. This option is not well documented, but here is a working example that would result in a partitionable device made of two disks -- sda and sdb:

 mdadm --create --auto=mdp --verbose /dev/md_d0 --level=mirror --raid-devices=2 /dev/sda /dev/sdb

Issuing this command will result in a /dev/md_d0 device that can be partitioned with fdisk or parted. The partitions will be available as /dev/md_d0p1, /dev/md_d0p2 etc.


An alternative solution to the partitioning problem is LVM, Logical Volume Management. LVM has been in the stable Linux kernel series for a long time now - LVM2 in the 2.6 kernel series is a further improvement over the older LVM support from the 2.4 kernel series. While LVM has traditionally scared some people away because of its complexity, it really is something that an administrator could and should consider if he wishes to use more than a few filesystems on a server.

We will not attempt to describe LVM setup in this HOWTO, as there already is a fine HOWTO for exactly this purpose. A small example of a RAID + LVM setup will be presented though. Consider the df output below, of such a system:

 # df -h
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/md0              942M  419M  475M  47% /
 /dev/vg0/backup        40G  1.3M   39G   1% /backup
 /dev/vg0/amdata       496M  237M  233M  51% /var/lib/amanda
 /dev/vg0/mirror        62G   56G  2.9G  96% /mnt/mirror
 /dev/vg0/webroot       97M  6.5M   85M   8% /var/www
 /dev/vg0/local        2.0G  458M  1.4G  24% /usr/local
 /dev/vg0/netswap      3.0G  2.1G 1019M  67% /mnt/netswap

"What's the difference" you might ask... Well, this system has only two RAID-1 devices - one for the root filesystem, and one that cannot be seen on the df output - this is because /dev/md1 is used as a "physical volume" for LVM. What this means is, that /dev/md1 acts as "backing store" for all "volumes" in the "volume group" named vg0. All this "volume" terminology is explained in the LVM HOWTO - if you do not completely understand the above, there is no need to worry - the details are not particularly important right now (you will need to read the LVM HOWTO anyway if you want to set up LVM). What matters is the benefits that this setup has over the many-md-devices setup:

  • No need to reboot just to add a new filesystem (this would otherwise be required, as the kernel cannot re-read the partition table from the disk that holds the root filesystem, and re-partitioning would be required in order to create the new RAID device to hold the new filesystem)
  • Resizing of filesystems: LVM supports hot-resizing of volumes (with RAID devices resizing is difficult and time consuming - but if you run LVM on top of RAID, all you need in order to resize a filesystem is to resize the volume, not the underlying RAID device). With a filesystem such as XFS, you can even resize the filesystem without un-mounting it first (!). Ext3 Hot-resizing is also supported (growing only).
  • Adding new disks: Need more storage? Easy! Simply insert two new disks in your system, create a RAID-1 on top of them, make your new /dev/md2 device a physical volume and add it to your volume group. That's it! You now have more free space in your volume group for either growing your existing logical volumes, or for adding new ones.
  • Ability to take LVM snapshots to enable consistent backup operations.

All in all - for servers with many filesystems, LVM (and LVM2) is definitely a fairly simple solution which should be considered for use on top of Software RAID. Read on in the LVM HOWTO if you want to learn more about LVM.

Back to Related tools
Personal tools