Packetwatch.net

LVM disk management commands in Red Hat Enterprise Linux



Last modified: Feb. 27, 2012

Contents
1 - Summary
2 - General information
3 - Physical volumes
4 - Volume groups
5 - Logical volumes
6 - Add space to a volume group


1 - Summary

This guide will show some LVM disk management commands in Red Hat Enterprise
Linux. LVM stands for logical volume manager. A logical volume provides storage
virtualization meaning that it allows you to create a logical storage volume
using multiple physical disks. This has been tested in Red Hat Enterprise Linux
5.


2 - General information

Find out what version of LVM is installed.
# rpm -qa | grep -i lvm
lvm2-2.02.84-6.el5_7.2
system-config-lvm-1.1.5-9.el5

Find out what hard disks the computer has and information about them.
# sudo /sbin/fdisk -l | grep Disk
Password: 
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
# sudo /sbin/hdparm -I /dev/sda | head -n 7 | tail -n 4
Password: 
ATA device, with non-removable media
        Model Number:       Hitachi HUA721010KLA330                 
        Serial Number:      GTF000PBGGTADF
        Firmware Revision:  GKAOA9N1
# sudo /sbin/hdparm -I /dev/sdb | head -n 7 | tail -n 4
Password: 
ATA device, with non-removable media
        Model Number:       Hitachi HUA721010KLA330                 
        Serial Number:      GTF000PBGGJSMF
        Firmware Revision:  GKAOA9N1

Display the local file system disk space usage.
# df -hl
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              93G   15G   75G  17% /
/dev/mapper/VolGroup00-LogVol00
                      1.7T  400G  1.2T  25% /data
tmpfs                 2.0G     0  2.0G   0% /dev/shm


3 - Physical volumes

Scan all disks for physical volumes.
# sudo /sbin/pvscan
Password: 
  PV /dev/sda3   VG VolGroup00   lvm2 [831.50 GB / 0    free]
  PV /dev/sdb1   VG VolGroup00   lvm2 [931.50 GB / 0    free]
  Total: 2 [1.72 TB] / in use: 2 [1.72 TB] / in no VG: 0 [0   ]

Display attributes of physical volumes.
# sudo /usr/sbin/pvdisplay /dev/sda3
Password: 
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               VolGroup00
  PV Size               831.51 GB / not usable 12.53 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              26608
  Free PE               0
  Allocated PE          26608
  PV UUID               wALAIn-1MfU-W1Zc-O70G-0194-2QS5-ddU4tT
# sudo /usr/sbin/pvdisplay /dev/sdb1
Password: 
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               VolGroup00
  PV Size               931.51 GB / not usable 11.19 MB
  Allocatable           yes (but full)
  PE Size (KByte)       32768
  Total PE              29808
  Free PE               0
  Allocated PE          29808
  PV UUID               45HeHE-EJ0d-AK6A-KWWI-CUgL-4WAx-uXMWZn


4 - Volume groups

Scan all disks for volume groups.
# sudo /sbin/vgscan 
Password: 
  Reading all physical volumes.  This may take a while...
  Found volume group "VolGroup00" using metadata type lvm2

Display attributes of volume groups.
# sudo /usr/sbin/vgdisplay VolGroup00
Password: 
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               1.72 TB
  PE Size               32.00 MB
  Total PE              56416
  Alloc PE / Size       56416 / 1.72 TB
  Free  PE / Size       0 / 0   
  VG UUID               qTyO9u-1keX-a8b0-uAUa-VspH-tysg-Cte41M


5 - Logical volumes

Scan all disks for logical volumes.
# sudo /usr/sbin/lvscan
Password: 
  ACTIVE            '/dev/VolGroup00/LogVol00' [1.72 TB] inherit

Display attributes of logical volume
# sudo /usr/sbin/lvdisplay /dev/VolGroup00/LogVol00
Password: 
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                gNvKds-MZIH-ldaO-ghBA-Zk2S-8bUx-Cl9I7x
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.72 TB
  Current LE             56416
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0


6 - Add space to a volume group

We will go through an example of adding more space space to a volume group by
adding a new disk. The first step is create a physical volume.
# sudo /usr/sbin/pvcreate /dev/sdc
Password:
  Physical volume "/dev/sdc" successfully created

Next, we want to list the volume groups.
# sudo /sbin/vgscan
Password:
  Reading all physical volumes.  This may take a while...
  Found volume group "VolGroup00" using metadata type lvm2

With the physical volume create, we now need to add it to the volume group.
# sudo /usr/sbin/vgextend VolGroup00 /dev/sdc
Password:
  Volume group "VolGroup00" successfully extended

The new physical volume has been added to the volume group and is ready to be
allocated to a logical volume. Display attributes of the new physical volume.
# sudo /usr/sbin/pvdisplay /dev/sdc
Password:
  --- Physical volume --
  PV Name               /dev/sdc
  VG Name               VolGroup00
  PV Size               1.82 TB / not usable 17.09 MB
  Allocatable           yes
  PE Size (KByte)       32768
  Total PE              59616
  Free PE               59616
  Allocated PE          0
  PV UUID               akTQlv-EM8d-hrYp-t31W-FfbR-Kkds-y5yYXT

Find the name of the logical volume.
# df -hl
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              97G  6.9G   85G   8% /
/dev/mapper/VolGroup00-LogVol00
                      1.7T  1.5T  168G  90% /data
tmpfs                 7.9G     0  7.9G   0% /dev/shm

Next, we extend the size of the logical volume.
# sudo /usr/sbin/lvextend -l+59616 /dev/mapper/VolGroup00-LogVol00
Password:
  Rounding up size to full physical extent 1.82 TB
  Extending logical volume LogVol00 to 3.52 TB
  Logical volume LogVol00 successfully resized

The last step in the process is to resize the file system on the logical volume
so it uses the additional space.
# sudo /sbin/resize2fs /dev/mapper/VolGroup00-LogVol00
Password:
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/VolGroup00-LogVol00 is mounted on /data; on-line resizing required
Performing an on-line resize of /dev/mapper/VolGroup00-LogVol00 to 943841280 (4k) blocks.
The filesystem on /dev/mapper/VolGroup00-LogVol00 is now 943841280 blocks long.

Finally, do a check to verify that the file system on the logical volume was
resized.
# df -hl
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              97G  7.0G   85G   8% /
/dev/mapper/VolGroup00-LogVol00
                      3.5T  1.5T  1.9T  44% /data
tmpfs                 7.9G     0  7.9G   0% /dev/shm


Last modified: Thu Jan 1 00:00:00 1970 UTC
Packetwatch Research 2002-2024.