Adding a New Disk to a CentOS 6 Volume Group and Logical Volume

PreviousTable of ContentsNext
Adding a New Disk Drive to a CentOS 6 SystemAdding and Managing CentOS 6 Swap Space


You are reading a sample chapter from the CentOS 6 Essentials Essentials book.

Purchase a copy of the fully updated CentOS 8 edition in eBook ($24.99) or Print ($36.99) format

CentOS 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 260 pages. Learn more...

Buy Print Preview Book


In the previous chapter we looked at adding a new disk drive to a CentOS 6 system, 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 Logical Volume 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 a CentOS 6 based server. Without LVM this file system would be created with a certain size when the operating system 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 would be 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 still be nearly full. The only option would be to move files onto the new file system. With LVM, the new disk (or part thereof) can be assigned to the logical volume containing the root file system thereby dynamically 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 a CentOS 6 system.

An Overview of Logical Volume Management (LVM)

LVM provides a flexible and high level approach to managing disk space. Instead of each disk drive 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 space assigned 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.

LVM consists 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 a file 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 physical volumes and assign them to the volume group and logical volume.

Getting Information about Logical Volumes

As an example of using LVM with CentOS 6 we will work through an example of adding space to the / file system of a standard CentOS 6 installation. Anticipating the need for flexibility in the sizing of the root partition, CentOS 6 sets up the / file system as a logical volume (called lv_root) within a volume group called vg_name where name corresponds to the hostname of the CentOS 6 system. Before making any changes to the LVM setup, however, it is important to first gather information.

Running the mount command on will typically show output similar to the following:

/dev/mapper/vg_centos6-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sr0 on /media/CentOS_6.2_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=500,gid=500,iocharset=utf8,mode=0400,dmode=0500)

Information about the volume group can be obtained using the /usr/sbin/vgdisplay command:

 
# vgdisplay
  --- Volume group ---
  VG Name               vg_centos6
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  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               31.51 GiB
  PE Size               4.00 MiB
  Total PE              8066
  Alloc PE / Size       8066 / 31.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               zQAp7U-seRJ-TyVe-Ws9Z-qYuB-oYS1-BsHX6H

As we can see the in the above example, vg_centos6 has a physical extend size of 4.00MB and has a total of 31.51GB available for allocation to logical volumes. Currently 8066 physical extents are allocated equaling the total 31.51GB capacity. If we want to increase the space allocated to any logical volumes in vg_centos6 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 Management menu option. This tool is not installed by default, so if the menu option is not available the tool may be installed from a terminal window by entering the following commands:

su –
yum install system-config-lvm 

Once installed and running, the tool will appear as illustrated in the following figure:


[[Image:|The CentOS 6 LVM tool]]


Information about logical volumes in a volume group may similarly be obtained using the lvdisplay command:

# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg_centos6/lv_root
  VG Name                vg_centos6
  LV UUID                lj3Kp4-mqIk-Oi3Q-b1wq-0VtG-cfd3-0uAWZE
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                29.54 GiB
  Current LE             7562
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/vg_centos6/lv_swap
  VG Name                vg_centos6
  LV UUID                RKcjwn-660p-qzqc-pP3u-lCiY-23pC-O282tl
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.97 GiB
  Current LE             504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

As shown in the above example 29.54GB of the space in volume group vg_centos6 is allocated to logical volume lv_root (for the / file system) and 1.97GB to lv_swap (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/sda2
  VG Name               vg_centos6
  PV Size               31.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              8066
  Free PE               0
  Allocated PE          8066
  PV UUID               iTtzWo-HG3r-Agm6-wWHh-yyxv-rL2E-usEfKf

Clearly the space controlled by logical volume vg_centos6 is provided via a physical volume located on /dev/sda2.

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 a CentOS 6 Volume Group from the Command Line

Just as with the previous steps to gather information about the current Logical Volume Management configuration of a CentOS 6 system, changing this configuration can be performed both from the command line and from within the graphical volume management tool. In this chapter we will focus on the use of command line tools.

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 new disk 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
  Physical volume "/dev/sdb" successfully created

With the physical volume created we now need to add it to the volume group (in this case vg_centos6) using the vgextend command:

# vgextend vg_CentOS6 /dev/sdb
  Volume group "vg_CentOS6" successfully extended

The new physical volume has now been added to the volume group and is ready to be allocated to a logical volume. To do this we run the lvextend tool providing the size by which we wish to extend the volume. In this case we want to extend the size of lv_root by 30 GB. Note that we need to provide the path to the logical volume which can be obtained from the lvdisplay command (in this case /dev/vg_centos6/lv_root):

# lvextend -L+30G /dev/vg_centos6/lv_root
  Extending logical volume lv_root to 59.54 GiB
  Logical volume lv_root successfully resized

The last step in the process is to resize the file system residing on the logical volume so that it uses the additional space. Since we are assuming a default CentOS 6 installation here this can be achieved using the resize2fs command:

# resize2fs /dev/vg_centos6/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_centos6/lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 4
Performing an on-line resize of /dev/vg_centos6/lv_root to 15607808 (4k) blocks.

The filesystem on /dev/vg_centos6/lv_root is now 15607808 blocks long. Once the resize completes the file system will have been extended to use the additional space provided by the new disk drive. All this has been achieved without moving a single file or even having to restart the server. As far as any users on the system are concerned nothing has changed (except, of course, that there is now more disk space).


You are reading a sample chapter from the CentOS 6 Essentials Essentials book.

Purchase a copy of the fully updated CentOS 8 edition in eBook ($24.99) or Print ($36.99) format

CentOS 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 260 pages. Learn more...

Buy Print Preview Book



PreviousTable of ContentsNext
Adding a New Disk Drive to a CentOS 6 SystemAdding and Managing CentOS 6 Swap Space