Upload
kannanor
View
220
Download
0
Embed Size (px)
Citation preview
8/2/2019 Adding a New Disk to an RHEL 5 Volume Group and Logical Volume
1/8
Adding a New Disk to an RHEL 5 Volume
Group and Logical Volume
In the previous chapter we looked at adding a new disk drive to a Red Hat Enterprise Linux 5system, creating a partition and file system and then mounting that file system so that the disk
can be accessed. An alternative to creating fixed partitions and file systems is to use LogicalVolume Management (LVM) to create logical disks made of space from one or more physical
disks or partitions. The advantage of using LVM is that space can be added to or removed from
logical volumes as needed without the need to spread data over multiple file systems.
Let us take, for example, the root (/) file system of an RHEL 5 server. Without LVM this file
system would be created with a certain size when the operating is installed. If a new disk drive is
installed there is no way to allocate any of that space to the / file system. The only option wouldbe to create new file systems on the new disk and mount them at particular mount points. In this
scenario you would have plenty of space on the new file system but the / file system would stillbe nearly full. The only option would be to move files onto the new file system. With LVM, thenew disk (or part thereof) can be assigned to the logical volume containing the root file system
thereby extending the space available.
In this chapter we will look at the steps necessary to add new disk space to both a volume group
and a logical volume for the purpose of adding additional space to the root file system of an
RHEL 5 system.
Contents
[hide]
1 An Overview of Logical VolumeManagement (LVM)
o 1.1 Volume Group (VG)o 1.2 Physical Volume (PV)o 1.3 Logical Volume (LV)o 1.4 Physical Extent (PE)o 1.5 Logical Extent (LE)
2 Getting Information about LogicalVolumes
3 Adding Additional Space to an RHELVolume Group from the CommandLine
http://toggletoc%28%29/http://toggletoc%28%29/http://toggletoc%28%29/http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#An_Overview_of_Logical_Volume_Management_.28LVM.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#An_Overview_of_Logical_Volume_Management_.28LVM.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#An_Overview_of_Logical_Volume_Management_.28LVM.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#An_Overview_of_Logical_Volume_Management_.28LVM.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#An_Overview_of_Logical_Volume_Management_.28LVM.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Volume_Group_.28VG.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Volume_Group_.28VG.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Physical_Volume_.28PV.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Physical_Volume_.28PV.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Logical_Volume_.28LV.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Logical_Volume_.28LV.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Physical_Extent_.28PE.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Physical_Extent_.28PE.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Logical_Extent_.28LE.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Logical_Extent_.28LE.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Getting_Information_about_Logical_Volumeshttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Getting_Information_about_Logical_Volumeshttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Getting_Information_about_Logical_Volumeshttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Getting_Information_about_Logical_Volumeshttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Getting_Information_about_Logical_Volumeshttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Adding_Additional_Space_to_an_RHEL_Volume_Group_from_the_Command_Linehttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Adding_Additional_Space_to_an_RHEL_Volume_Group_from_the_Command_Linehttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Adding_Additional_Space_to_an_RHEL_Volume_Group_from_the_Command_Linehttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Adding_Additional_Space_to_an_RHEL_Volume_Group_from_the_Command_Linehttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Adding_Additional_Space_to_an_RHEL_Volume_Group_from_the_Command_Linehttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Adding_Additional_Space_to_an_RHEL_Volume_Group_from_the_Command_Linehttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Adding_Additional_Space_to_an_RHEL_Volume_Group_from_the_Command_Linehttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Adding_Additional_Space_to_an_RHEL_Volume_Group_from_the_Command_Linehttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Adding_Additional_Space_to_an_RHEL_Volume_Group_from_the_Command_Linehttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Getting_Information_about_Logical_Volumeshttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Getting_Information_about_Logical_Volumeshttp://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Logical_Extent_.28LE.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Physical_Extent_.28PE.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Logical_Volume_.28LV.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Physical_Volume_.28PV.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#Volume_Group_.28VG.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#An_Overview_of_Logical_Volume_Management_.28LVM.29http://www.techotopia.com/index.php/Adding_a_New_Disk_to_an_RHEL_5_Volume_Group_and_Logical_Volume#An_Overview_of_Logical_Volume_Management_.28LVM.29http://toggletoc%28%29/8/2/2019 Adding a New Disk to an RHEL 5 Volume Group and Logical Volume
2/8
An Overview of Logical Volume Management (LVM)
LVM provides a flexible and high level approach to managing disk space. Instead of each diskdrive being split into partitions of fixed sizes onto which fixed size file systems are created,
LVM provides a way to group together disk space into logical volumes which can be easily
resized and moved. In addition LVM allows administrators to carefully control disk spaceassigned to different groups of users by allocating distinct volume groups or logical volumes to
those users. When the space initially allocated to the volume is exhausted the administrator can
simply add more space without having to move the user files to a different file system. LVMconsists of the following components:
Volume Group (VG)
The Volume Group is the high level container which holds one or more logical volumes and
physical volumes.
Physical Volume (PV)
A physical volume represents a storage device such as a disk drive or other storage media.
Logical Volume (LV)
A logical volume is the equivalent to a disk partition and, as with a disk partition, can contain afile system.
Physical Extent (PE)
Each physical volume (PV) is divided into equal size blocks known as physical extents.
Logical Extent (LE)
Each logical volume (LV) is divided into equal size blocks called logical extents.
Let's suppose we are creating a new volume group called VolGroup001. This volume group
needs physical disk space in order to function so we allocate three disk partitions /dev/sda1,/dev/sdb1 and /dev/sdb2. These become physical volumes in VolGroup001. We would then
create a logical volume called LogVol001 within the volume group made up of the three physical
volumes. If we run out of space in LogVol001 we simply add more disk partitions as physicalvolumes and assign them to the volume group and logical volume.
Getting Information about Logical Volumes
As an example of using LVM with RHEL we will work through an example of adding space to
the / filesystem of a standard RHEL installation. Anticipating the need for flexibility in the sizing
of the root partition, RHEL sets up the / file system as a logical volume (called LogVol00) within
8/2/2019 Adding a New Disk to an RHEL 5 Volume Group and Logical Volume
3/8
a volume group named VolGroup00. Before making any changes to the LVM setup it is
important to gather information.
Running the mount command on an RHEL system will typically show output similar to the
following:
# mount/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)/dev/sda1 on /boot type ext3 (rw)tmpfs on /dev/shm type tmpfs (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)nfsd on /proc/fs/nfsd type nfsd (rw)
Information about the volume group can be obtained using the /usr/sbin/vgdisplay command:
--- Volume group ---VG Name VolGroup00System IDFormat lvm2Metadata Areas 1Metadata Sequence No 3VG Access read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 1Act PV 1VG Size 31.88 GBPE Size 32.00 MBTotal PE 1020Alloc PE / Size 1020 / 31.88 GBFree PE / Size 0 / 0VG UUID HA8FrD-w14T-5a31-Shn3-ZTAE-9PJH-kFrfF8
As we can see the in the above example, VolGroup00 has a physical extend size of 32MB andhas a total of 31.88GB available for allocation to logical volumes. Currently there are no free
physical extents so if we want to increase the space allocated to any logical volumes in
VolGroup00 we will need to add one or more physical volumes.
The same information can be viewed graphically using the Logical Volume Manager tool,
accessed by selecting the System -> Administration -> Logical Volume Managementmenu
option. If the menu option is not available the tool may installed from a terminal window byentering the following commands:
su yum install system-config-lvm
8/2/2019 Adding a New Disk to an RHEL 5 Volume Group and Logical Volume
4/8
Once installed and running, the tool will appear as follows:
Information about logical volumes in a volume group may similarly be obtained using the
lvdisplay command:
# lvdisplay--- Logical volume ---LV Name /dev/VolGroup00/LogVol00VG Name VolGroup00LV UUID 8enNJV-bWkm-Zlf3-rLno-YZvY-awdj-YqFborLV Write Access read/writeLV Status available# open 1LV Size 29.91 GBCurrent LE 957Segments 1Allocation inherit
Read ahead sectors auto- currently set to 256Block device 253:0
--- Logical volume ---LV Name /dev/VolGroup00/LogVol01VG Name VolGroup00LV UUID AM1D10-cu8L-KdRk-lWXN-ZLwz-tQow-iv87eSLV Write Access read/writeLV Status available
http://www.techotopia.com/index.php/Image:Rhel_lvm.jpg8/2/2019 Adding a New Disk to an RHEL 5 Volume Group and Logical Volume
5/8
# open 1LV Size 1.97 GBCurrent LE 63Segments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:1
As shown in the above example 29.91GB of the space in volume group VolGroup00 is allocated
to logical volume LogVol00 (for the / file system) and 1.97GB to LogVol01 (for swap space).
Now that we know what space is being used it is often helpful to understand which devices are
providing the space (in other words which devices are being used as physical volumes). To
obtain this information we need to run the pvdisplay command:
# pvdisplay--- Physical volume ---
PV Name /dev/sda2VG Name VolGroup00PV Size 31.90 GB / not usable 23.41 MBAllocatable yes (but full)PE Size (KByte) 32768Total PE 1020Free PE 0Allocated PE 1020PV UUID IDAxKn-Xejs-Q07y-qKOA-T4tz-gCSD-GZjXbK
Clearly the space controlled by logical volume VolGroup00 is provided via a physical volumelocated on /dev/sda2. Selecting the Physical View from the graphical tool results in the following
representation of the same information:
8/2/2019 Adding a New Disk to an RHEL 5 Volume Group and Logical Volume
6/8
Now that we know a little more about our LVM configuration we can embark on the process of
adding space to the volume group and the logical volume contained within.
Adding Additional Space to an RHEL Volume Group fromthe Command Line
Just as with the previous steps to gather information about the current Logical Volume
Management configuration of a RHEL system, changing this configuration can be performedboth from the command line and from within the graphical volume management tool. In this
section we will focus on the use of command line tools since this gives a better understanding of
the underlying changes that are being made, and avoids reliance on graphical tools that may notalways be available.
In the remainder of this chapter we will assume that a new disk has been added to the system and
that it is being seen by the operating system as /dev/sdb. We shall also assume that this is a newdisk that does not contain any existing partitions. If existing partitions are present they should be
backed up and then the partitions deleted from the disk using the fdisk utility.
The first step is to convert this disk into a physical volume. This is achieved using the pvcreate
command:
# pvcreate /dev/sdb
http://www.techotopia.com/index.php/Image:Rhel_lvm_physical_volume.jpg8/2/2019 Adding a New Disk to an RHEL 5 Volume Group and Logical Volume
7/8
Physical volume "/dev/sdb" successfully created
With the physical volume created we now need to add it to the volume group (in this caseVolGroup00) using the vgextend command:
vgextend VolGroup00 /dev/sdb
Volume group "VolGroup00" successfully extended
The new physical volume has now been added to the volume group and is ready to be allocatedto a logical volume. To do this we run the lvextend tool providing the size by which we wish to
extend the volume. To find out the space available on the new physical volumes, we turn againto the pvdisplay command:
# pvdisplay /dev/sdb--- Physical volume ---PV Name /dev/sdbVG Name VolGroup00PV Size 32.00 GB / not usable 32.00 MB
Allocatable yesPE Size (KByte) 32768Total PE 1023Free PE 1023Allocated PE 0PV UUID WuW0eO-uezo-JSGF-CUHQ-bxRR-qDBl-jdpdTj
The above output indicate that the new physical volume on /dev/sdb is 32GB in size. In this case
we want to extend the size of LogVol00 the full 32GB, though since there are only 1023 physical
extents available (1024 would be required for the full 32GB) we will instead allocate 31GB.Note that we need to provide the path to the logical volume which can be obtained from the
lvdisplay command (in this case /dev/VolGroup00/LogVol00):
# lvextend -L+31G /dev/VolGroup00/LogVol00Extending logical volume LogVol00 to 60.91 GBLogical volume LogVol00 successfully resized
The last step in the process is to resize the file system residing on the logical volume so that ituses the additional space. Since we are assuming a default RHEL installation here this can beachieved using the resize2fs command:
# resize2fs /dev/VolGroup00/LogVol00resize2fs 1.39 (29-May-2006)Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing
requiredPerforming an on-line resize of /dev/VolGroup00/LogVol00 to 15966208 (4k)blocks.The filesystem on /dev/VolGroup00/LogVol00 is now 15966208 blocks long.
Once the resize completes the file system will have been extended to use the additional spaceprovided by the new disk drive. All this has been achieved without moving a single file or even
having to reboot the system. As far as any users on the system are concerned nothing has
8/2/2019 Adding a New Disk to an RHEL 5 Volume Group and Logical Volume
8/8
changed (except that there is now more disk space). The new space can be verified using the df
command. For example:
# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol00
60G 2.7G 54G 5% //dev/sda1 99M 19M 75M 21% /boottmpfs 502M 0 502M 0% /dev/shm
As we can see from the above output, our root (/) partition is now 60GB in size as a result ofadding 31GB of disk space from a new disk drive to the logical volume.