861
<sect2 id="lvm" status="review">
862
<title>Logical Volume Manager (LVM)</title>
865
Logical Volume Manger, or <emphasis>LVM</emphasis>, allows administrators to create <emphasis>logical</emphasis> volumes out of
866
one or multiple physical hard disks. LVM volumes can be created on both software RAID partitions and standard partitions
867
residing on a single disk. Volumes can also be extended, giving greater flexibility to systems as requirements change.
870
<sect3 id="lvm-overview" status="review">
871
<title>Overview</title>
874
A side effect of LVM's power and flexibility is a greater degree of complication. Before diving into the LVM installation process,
875
it is best to get familiar with some terms.
881
<emphasis>Volume Group (VG):</emphasis> contains one or several Logical Volumes (LV).
886
<emphasis>Logical Volume (LV):</emphasis> is similar to a partition in a non-LVM system. Multiple Physical Volumes (PV)
887
can make up one LV, on top of which resides the actual EXT3, XFS, JFS, etc filesystem.
892
<emphasis>Physical Volume (PV):</emphasis> physical hard disk or software RAID partition. The Volume Group can be extended
899
<sect3 id="lvm-installation" status="review">
900
<title>Installation</title>
903
As an example this section covers installing Ubuntu Server Edition with <filename role="directory">/srv</filename> mounted
904
on a LVM volume. During the initial install only one Physical Volume (PV) will be part of the Volume Group (VG). Another
905
PV will be added after install to demonstrate how a VG can be extended.
909
There are several installation options for LVM, <emphasis>"Guided - use the entire disk and setup LVM"</emphasis>,
910
<emphasis>"Guided - use entire and setup encrypted LVM"</emphasis>, or <emphasis>Manually</emphasis> setup the partitions
911
and configure LVM. At this time the only way to configure a system with both LVM and standard partitions, during installation,
912
is to use the Manual approach.
919
Follow the installation steps until you get to the <emphasis>Partition disks</emphasis> step, then:
926
At the <emphasis>"Partition Disks</emphasis> screen choose <emphasis>"Manual"</emphasis>.
933
Select the hard disk and on the next screen choose "yes" to <emphasis>"Create a new empty partition table on this device"</emphasis>.
940
Next, create standard <emphasis>/boot</emphasis>, <emphasis>swap</emphasis>, and <emphasis>/</emphasis> partitions with whichever
941
filesystem you prefer.
948
For the LVM <emphasis>/srv</emphasis>, create a new <emphasis>Logical</emphasis> partition. Then change <emphasis>"Use as"</emphasis>
949
to <emphasis>"physical volume for LVM"</emphasis> then <emphasis>"Done setting up the partition"</emphasis>.
956
Now select <emphasis>"Configure the Logical Volume Manager"</emphasis> at the top, and choose <emphasis>"Yes"</emphasis> to write
964
For the <emphasis>"LVM configuration action"</emphasis> on the next screen, choose <emphasis>"Create volume group"</emphasis>. Enter
965
a name for the VG such as <emphasis>vg01</emphasis>, or something more descriptive. After entering a name, select the partition
966
configured for LVM, and choose <emphasis>"Continue"</emphasis>.
973
Back at the <emphasis>"LVM configuration action"</emphasis> screen, select <emphasis>"Create logical volume"</emphasis>. Select
974
the newly created Logical Volume, and enter a name for the new LV, for example <emphasis>srv</emphasis> since that is the intended
975
mount point. Then choose a size, which may be the full partition because it can always be extended later. Choose
976
<emphasis>"Finish"</emphasis> and you should be back at the main <emphasis>"Partition Disks"</emphasis> screen.
983
Now add a filesystem to the new LVM. Select the partition under <emphasis>"LVM VG vg01, LV srv"</emphasis>, or whatever name
984
you have chosen, the choose <emphasis>Use as</emphasis>. Setup a file system as normal selecting <emphasis>/srv</emphasis> as
985
the mount point. Once done, select <emphasis>"Done setting up the partition"</emphasis>.
992
Finally, select <emphasis>"Finish partitioning and write changes to disk"</emphasis>. Then confirm the changes and continue
993
with the rest of the installation.
1000
There are some useful utilities to view information about LVM:
1004
<listitem><para><emphasis>vgdisplay:</emphasis> shows information about Volume Groups.</para></listitem>
1005
<listitem><para><emphasis>lvdisplay:</emphasis> has information about Logical Volumes.</para></listitem>
1006
<listitem><para><emphasis>pvdisplay:</emphasis> similarly displays information about Physical Volumes.</para></listitem>
1010
<sect3 id="lvm-extending" status="review">
1011
<title>Extending Volume Groups</title>
1014
Continuing the <emphasis>/srv</emphasis> as an LVM volume example, this section covers adding a second Physical Volume (PV) to
1015
<filename role="directory">/srv</filename> and expanding the filesystem. This example assumes a second hard disk has been added
1016
to the system and will be added to the <emphasis>vg01</emphasis> volume group.
1023
First, create a partition on the new disk using the <application>fdisk</application> utility. For example,
1024
from a terminal enter:
1028
<command>sudo fdisk /dev/sdb</command>
1029
<computeroutput>Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
1030
Building a new DOS disklabel with disk identifier 0x7b741e03.
1031
Changes will remain in memory only, until you decide to write them.
1032
After that, of course, the previous content won't be recoverable.
1034
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
1036
Command (m for help): <userinput>n</userinput>
1039
p primary partition (1-4)
1040
<userinput>p</userinput>
1041
Partition number (1-4): <userinput>1</userinput>
1042
First cylinder (1-391, default 1):
1043
Using default value 1
1044
Last cylinder, +cylinders or +size{K,M,G} (1-391, default 391):
1045
Using default value 391
1046
Command (m for help): <userinput>w</userinput>
1047
The partition table has been altered!
1049
Calling ioctl() to re-read partition table.
1050
Syncing disks.</computeroutput>
1054
The above output creates a single partition covering the entire disk. Your output will vary depending on your hard disk.
1058
A quick <application>fdisk</application> reference:
1062
<listitem><para><emphasis>n:</emphasis> creates a new partition.</para></listitem>
1063
<listitem><para><emphasis>p:</emphasis> prints the partition table.</para></listitem>
1064
<listitem><para><emphasis>w:</emphasis> writes the changes to disk, and exits fdisk.</para></listitem>
1065
<listitem><para><emphasis>q:</emphasis> quits fdisk without writing the changes to disk.</para></listitem>
1070
Adjust <filename>/dev/sdb</filename> according to your system. Also, the <application>cfdisk</application>,
1071
menu driven, partition utility can be used instead of <application>fdisk</application>.
1079
Next, create a Physical Volume (PV) on the new partition:
1083
<command>sudo pvcreate /dev/sdb1</command>
1090
Now extend the Volume Group (VG):
1094
<command>sudo vgextend vg01 /dev/sdb1</command>
1101
The Logical Volume (LV) can now be extended:
1105
<command>sudo lvextend /dev/vg01/srv -L3221M</command>
1109
The <emphasis>-L</emphasis> option allows the LV to be extended using Meg, Gig, Tera, etc bytes. Just be sure the
1110
hard disk has enough space for the value you choose. The <application>fdisk</application> <emphasis>q</emphasis>
1111
option will display the exact size of a drive.
1118
Finally, resize the filesystem:
1122
<command>sudo resize2fs /dev/vg01/srv</command>
1126
The above command is for an <application>EXT3</application> or <application>EXT4</application> filesystem. If you are
1127
using another filesystem there may be other resize utilities available.
1134
You should now see the expanded space in <filename>/srv</filename>: <command>df -h</command>.
1138
<sect3 id="lvm-resources" status="review">
1139
<title>Resources</title>
1144
See the <ulink url="http://tldp.org/HOWTO/LVM-HOWTO/index.html">LVM HOWTO</ulink> for more information.
1149
Another good article is
1150
<ulink url="http://www.linuxdevcenter.com/pub/a/linux/2006/04/27/managing-disk-space-with-lvm.html">Managing Disk Space with LVM</ulink>
1151
on O'Reilly's linuxdevcenter.com site.
1156
For more information on <application>fdisk</application> see the
1157
<ulink url="http://manpages.ubuntu.com/manpages/jaunty/en/man8/fdisk.8.html">fdisk man page</ulink>.