Go to the first, previous, next, last section, table of contents.


7. LVM and RAID

7.1 Logical Volume Manager and Redundant Arrays of Inexpensive Disks

LVM (Logical Volume Manager) is an alternative system to partitioning. It allows logical volumes (i.e. "virtual partitions") to be spread over many physical volumes (i.e. hard disks and/or partitions). LVM is supported on Linux version 2.4, and later.

RAID (Redundant Array of Inexpensive Disks) is a system for using many disks and/or partitions together, as a "virtual partition". There are a few different modes of utilising software RAID, that are essentially:

Software RAID is supported on Linux version 2.0, and later.

Hardware RAID is supported normally by Parted - so you need not read this section if you are using hardware RAID (as opposed to software RAID).

LVM, software RAID and partitions are often used simultaneously, but they can all be used independently. LVM and software RAID are often composed of partitions, rather than raw hard disks.

GNU Parted does not support LVM and software RAID in full, but it is still useful when used in combination with their respective tools. Parted is useful for these tasks:

7.2 Creating RAID or LVM partitions

To create a RAID or LVM partition, you must:

  1. Create a partition with the mkpart command.
  2. Set the LVM or RAID flag on the partition.

For example:

(parted) mkpart primary ext2 0 4000
(parted) set 1 lvm on

Note: the LVM or RAID partition will not be ready for use yet. You still need to run mkraid(8) for RAID, or use the LVM tools to initialise the physical volume, and create logical groups, etc.

7.3 Manipulating a File System on a RAID or LVM volume

Parted can manipulate RAID and LVM logical volumes, even though it does not understand RAID or LVM. It utilises Linux's support for RAID and LVM. Therefore, you can only use these methods if your Linux kernel supports RAID and/or LVM.

To manipulate a file system on a RAID or LVM logical volume (or, a raw partition, for that matter), you can start parted by selecting the logical volume (partition) device. For example:

# parted /dev/md0

For the rest of this chapter, "virtual device" will refer to the device Parted is editting (in our example cases, `/dev/md0').

7.3.1 Creating a File System on an LVM or RAID Virtual Device

To create a file system on an LVM volume, use the following steps:

  1. Create a loop disk label. This is a fake disk label, that tells Parted to treat the virtual device as a single file system. With this fake disk label, there is either zero or one partition.
    (parted) mklabel loop
    
  2. Create the file system, by using Parted's mkpartfs command. You should make the start of the file system 0. The partition can end anywhere inside the virtual device. You can find out the size of the virtual device with the print command. For example:
    (parted) print
    Disk geometry for /dev/md0: 0.000-47.065 megabytes
    Disk label type: loop
    Minor    Start       End     Filesystem  Flags
    (parted) mkpartfs primary ext2 0 47.065
    (parted) print
    Disk geometry for /dev/md0: 0.000-47.065 megabytes
    Disk label type: loop
    Minor    Start       End     Filesystem  Flags
    1          0.000     47.065  ext2
    

7.3.2 Resizing a File System on an LVM or RAID Virtual Device

You usually resize the file system at the same times as you resize your virtual device. If you are growing the file system and virtual device, you should grow the device first (with the RAID or LVM tools), and then grow the file system. If you are shrinking the file system and virtual device, you should shrink the file system first, and then the virtual device afterwards.

To resize the file system in Parted, use the resize command. For example:

(parted) select /dev/md0
(parted) resize 1 0 20

7.3.3 Copying a File System from an LVM or RAID Virtual Device to a Partition

To copy a filesystem from an LVM or RAID virtual device, just use the cp command. For example:

(parted) select /dev/hda (parted) cp /dev/md0 1 3

7.3.4 Copying a File System to an LVM or RAID Virtual Device

To copy a file system from an LVM or RAID virtual device, use the following recipe:

  1. Create the loop disk label on the virtual device. For example:
    (parted) select /dev/md0
    (parted) mklabel loop
    
  2. Create a file system on the virtual device, with the mkpartfs command. For example:
    (parted) mkpartfs primary ext2 0 47.065
    
  3. Copy the partition with the cp command:
    (parted) select /dev/hda
    (parted) cp /dev/md0 3 1
    


Go to the first, previous, next, last section, table of contents.