Creating a Physical
Volume
To create a new physical volume from free hard drive space
or a hard drive partition, use the pvcreate command:
pvcreate <disk>
Replace <disk> with the device name of the hard drive:
pvcreate /dev/sda
or the partition name:
pvcreate /dev/sda1
The <disk> specified can also be a meta device or
loopback device, but using an entire hard disk or partition is more common.
After creating a physical volume, you can either add it to an existing volume
group or create a new volume group with the physical volume.
Creating and
Modifying Volume Groups
A volume group can be created from one or more physical
volumes. To scan the system for all physical volumes, use the pvscan command as
root. It displays all PVs on the system. If the PV is part of a VG, it will
display the name of the VG next to it.
To create a VG, execute the vgcreate command as root, where
<vgname> is a unique name for the volume group and <pvlist> is one
or more physical volumes to use, each separated by a space:
vgcreate <vgname> <pvlist>
For example, to create a VG with the name DatabaseVG from
the first and second SCSI hard drives:
vgcreate DatabaseVG /dev/sda /dev/sdb
If a volume group already exists but needs to be expanded,
use the vgextend command to add additional physical volumes to it:
vgextend <vgname> <pvlist>
To remove a physical volume from a volume group:
vgreduce <vgname> <pvlist>
Use caution when reducing a volume group because any logical
volume using the PVs are removed from the VG and can no longer be accessed.
Creating and
Modifying Logical Volumes
Now that the physical volumes are formed into volume groups,
the volume groups can be divided into logical volumes, and the logical volumes
can be formatted with a filesystem and assigned mount points.
Use the lvcreate command to create a logical volume. Each LV
must have a unique name. If one is not specified with the -n <name>
option, a name will be assigned to it. To create a logical volume from the
volume group <vgname> of a certain size, specify the size unit after the
value of the size such as 300G for 300 gigabytes:
lvcreate -n <lvname> --size <size>
<vgname>
Each physical volume consists of physical extents, which are
4 megabytes in size by default. When the size is given in gigabytes, this size
must be converted to physical extents, meaning that some amount of disk space
may not be used. So, the number of physical extents to use when creating the
logical volume can be given with the –l <numpe> option:
lvcreate -n <lvname> -l <numpe> <vgname>
To determine the number of physical extents in a logical
volume group, issue the following command as root:
vgdisplay <vgname>
The Total PE line shows the number of physical extents for
the volume group. The output should look similar, which shows a total of 1189
physical extents. Look for the Free PE / Size line to determine whether any
free PEs are available to allocate to a new logical volume. shows 220 free
physical extents.
Example vgdisplay Output
--- Volume group
---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 37.16 GB
PE Size 32.00 MB
Total PE 1189
Alloc PE / Size 969 / 30.28 GB
Free PE / Size 220 / 6.88 GB
VG UUID N60y5U-2sM2-uxHY-M1op-Q1v3-uVV2-Zkahza
By default, logical volumes are created linearly over the
physical volumes. However, they can be striped over multiple PVs:
lvcreate -i<stripes> -I<stripesize> -l
<numpe> -n <lvname> <vgname> <pvlist>
The -i<stripes> option sets the number of stripes, or
physical volumes to use. The -I<stripesize> is the stripe size, which
must be 2^n, where n is an integer from 2 to 9. Provide the number of PEs to
use with the -l <numpe> option or give the size of the LV with the --size
<size> option. The -n <lvname> option specifies the LV name, and
<vgname> represents the name of the VG to use. Optionally, list the PVs
to use, <pvlist>, at the end of the command separated by spaces. The
number of PVs listed should be equal to the number of stripes.
After creating the logical volume, you must create a
filesystem on it. To create an ext3 filesystem, execute the following as root:
mke2fs -j /dev/<vgname>/<lvname>
If the LV is to be used as swap, execute the following as root
instead:
mkswap /dev/<vgname>/<lvname>
Next, still as the root user, create an empty directory as
its mount point with the mkdir command, and use the mount command to mount the
filesystem:
mount /dev/<vgname>/<lvname> /mount/point
If it mounts properly, the last step is to add it to
/etc/fstab so it is mounted automatically at boot time. As root, add a line
similar to the following, replacing with the appropriate values:
/dev/<vgname>/<lvname> /mount/point ext3
defaults 1 2
To extend a logical volume, expand the volume group if
necessary, and then use the lvextend command. Either specify the final size of
the logical volume:
lvextend --size <size>
/dev/<vgname>/<lvname>
or specify how much to expand the logical volume:
lvextend --size +<addsize> /dev/<vgname>/<lvname>
Just like physical volumes are composed of 4KB physical
extents, logical volumes consist of logical extents, which also have a default
size of 4KB. Instead of specifying the size or amount of space to add in
gigabytes, it is also possible to use the -l <numle> to provide the final
number of logical extents or -l +<numle> to expand the logical volume by
a certain number of logical extents.
After extending the logical volume, the filesystem on it
must be expanded as well. If it is an ext3 filesystem (default filesystem for
Red Hat Enterprise Linux), it can be expanded while it is still mountedTo do
so, execute the following as root:
resize2fs /dev/<vgname>/<lvname>
The filesystem is expanded to fill the entire logical volume
unless a size is listed after the logical volume device name (be sure to list
the size unit such as G for gigabyte after the size):
resize2fs /dev/<vgname>/<lvname> <size>
To remove a logical volume from a volume group, first
unmount it with the umount command:
umount /dev/<vgname>/<lvname>
and then use the lvremove command:
lvremove /dev/<vgname>/<lvname>
To view the existing logical volumes along with information
about them such as what VG they are a member of, the number of logical extents,
and their size in gigabytes, execute the lvdisplay command as root as shown in.
Example lvdisplay
Output
--- Logical volume
---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID tugMFo-PESp-3INs-nrGF-K0Wh-s3U0-l9FsTc
LV Write Access read/write
LV Status available
# open 1
LV Size 12.94 GB
Current LE 414
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0
--- Logical volume
---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID fdKfYP-wIP9-M4Da-eoV3-pP99-w8Vb-0yhgZb
LV Write Access read/write
0 comments:
Post a Comment