LVM – Setup and configure Logical Volumes in RHEL 6/Centos 6 – Part 3

Welcome to Part 3 of this series of 4 articles detailing how to setup and configure multiple filesystems running on LVM partitions. Each article will cover a specific topic, per the below:

Part 1 – Setup and configure Physical Volumes
Part 2 – Setup and configure Volume Groups
Part 3 – Setup and configure Logical Volumes
Part 4 – Setup and configure Filesystems

In Part 3 we are going to create the logical volumes within our data volume group. The logical groups to be created are:

music (10GB)
video (5GB)
pictures (5GB)

So to proceed, run the lvcreate command per the below:

lvcreate --name music --size 10G data

The output will be:

[root@lnx-svr-01 ~]# lvcreate --name music --size 10G data
  Logical volume "music" created

Perform the same commands in order to create the video and pictures logical volumes:

lvcreate --name video --size 5G data
lvcreate --name pictures --size 5G data

Please note that there was insufficient space on the data volume group to fit the picture logical volume:

[root@lnx-svr-01 ~]# lvcreate --name pictures --size 5G data
  Volume group "data" has insufficient free space (1274 extents): 1280 required.
[root@lnx-svr-01 ~]#

But as you can see from the above it confirms that there are only 1274 extents available. So we can run lvcreate with the -l option:

[root@lnx-svr-01 ~]# lvcreate --name pictures -l 1274 data
  Logical volume "pictures" created
[root@lnx-svr-01 ~]#

Here I have stated that I want the pictures volume group to be laid down on exactly 1274 extents. Alternatively, I could have run the following command to achieve the same result:

lvcreate -l 100%FREE -n pictures data

The above command will simple use all remaining space for the logical volume creation.

Now run lvdisplay to view all logical volumes:

[root@lnx-svr-01 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/data/music
  LV Name                music
  VG Name                data
  LV UUID                Vpq1Tk-j7wj-6WTi-37bZ-3KQx-AJRA-fUuELr
  LV Write Access        read/write
  LV Creation host, time lnx-svr-01.vsysad.local, 2015-06-11 13:03:20 +0100
  LV Status              available
  # open                 1
  LV Size                10.00 GiB
  Current LE             2560
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/data/pictures
  LV Name                pictures
  VG Name                data
  LV UUID                TzB4Gd-ZjYo-4YBD-mRVb-zFek-7j91-pIjzQo
  LV Write Access        read/write
  LV Creation host, time lnx-svr-01.vsysad.local, 2015-06-11 13:17:30 +0100
  LV Status              available
  # open                 1
  LV Size                4.98 GiB
  Current LE             1274
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3

  --- Logical volume ---
  LV Path                /dev/data/video
  LV Name                video
  VG Name                data
  LV UUID                YPv1jQ-sneY-ee20-aSq3-J3qQ-zivI-WeJkSN
  LV Write Access        read/write
  LV Creation host, time lnx-svr-01.vsysad.local, 2015-06-11 13:35:43 +0100
  LV Status              available
  # open                 1
  LV Size                5.00 GiB
  Current LE             1280
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:4

  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                tYZOe0-bhSb-G0fL-7RWK-Vzwq-BG8H-AZyZL9
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-05-30 19:17:03 +0100
  LV Status              available
  # open                 1
  LV Size                17.51 GiB
  Current LE             4482
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_swap
  LV Name                lv_swap
  VG Name                VolGroup
  LV UUID                QWeze3-c0cy-dwui-6BkI-LDkc-VSun-7W7yuK
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-05-30 19:17:25 +0100
  LV Status              available
  # open                 1
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[root@lnx-svr-01 ~]#

The logical volumes we created; music, video and pictures are visible. We can run lvscan to view a more concise listing of logical volumes:

[root@lnx-svr-01 ~]# lvscan
  ACTIVE            '/dev/data/music' [10.00 GiB] inherit
  ACTIVE            '/dev/data/pictures' [4.98 GiB] inherit
  ACTIVE            '/dev/data/video' [5.00 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_root' [17.51 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_swap' [2.00 GiB] inherit
[root@lnx-svr-01 ~]#

To rename a logical volume run the lvrename command:

lvrename data video movies

The output would be:

[root@lnx-svr-01 ~]# lvrename data video movies
Renamed "video" to "movies" in volume group "data"
[root@lnx-svr-01 ~]#

To delete a logical volume run the lvremove command:

lvremove /dev/data/video

The result would be:

[root@lnx-svr-01 ~]# lvremove /dev/data/video
Do you really want to remove active logical volume video? [y/n]: y
Logical volume "video" successfully removed
[root@lnx-svr-01 ~]#

The lvrename and lvremove examples were for your reference only, there is no need to run them.

This is then end of Part 3. Please go to Part 4, to setup and configure Filesystems.

References:
How to Create LVM Partition in RHEL 6 / CentoOS
Linux Basics – LVM (Logical Volume Manager) Tutorial
How to Install LVM on Linux and Disk Operations
A Beginner’s Guide To LVM
How To Create LVM Using vgcreate, lvcreate, and lvextend lvm2 Commands

LVM – Setup and configure Volume Groups in RHEL 6/Centos 6 – Part 2

Welcome to Part 2 of this series of 4 articles detailing how to setup and configure multiple filesystems running on LVM partitions. Each article will cover a specific topic, per the below:

Part 1 – Setup and configure Physical Volumes
Part 2 – Setup and configure Volume Groups
Part 3 – Setup and configure Logical Volumes
Part 4 – Setup and configure Filesystems

In Part 2 we will cover Volume Group Management and will create a volume group called data and add /dev/sdb1/dev/sdd1 to it by running the following command:

vgcreate data /dev/sdb1 /dev/sdc1 /dev/sdd1

The result of which is:

[root@lnx-svr-01 ~]# vgcreate data /dev/sdb1 /dev/sdc1 /dev/sdd1
  Volume group "data" successfully created
[root@lnx-svr-01 ~]#

To display information about our volume groups we run vgdisplay:

[root@lnx-svr-01 ~]# vgdisplay
  --- Volume group ---
  VG Name               data
  System ID
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               19.98 GiB
  PE Size               4.00 MiB
  Total PE              5114
  Alloc PE / Size       0 / 0
  Free  PE / Size       5114 / 19.98 GiB
  VG UUID               6eGhBN-LhH2-loZy-Vv04-adpB-NTiY-FToZMP

  --- Volume group ---
  VG Name               VolGroup
  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               19.51 GiB
  PE Size               4.00 MiB
  Total PE              4994
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               4Con9G-f33H-UBae-36Z0-dhOE-K2y4-0HFDty

[root@lnx-svr-01 ~]#

As you can see from the above, we have two volume groups; data and VolGroup. The VolGroup volume group was created during the install of the operating system, so was already present before we created the data volume group in the previous step.

You can run vgscan to scan the system and display volume groups also:

[root@lnx-svr-01 ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "data" using metadata type lvm2
  Found volume group "VolGroup" using metadata type lvm2
[root@lnx-svr-01 ~]#

Please note that to rename the data volume group simply run the vgrename command:

[root@lnx-svr-01 ~]# vgrename data store
  Volume group "data" successfully renamed to "store"
[root@lnx-svr-01 ~]#

The above command renames the data volume group to store.

Please also note that to delete the volume group run vgremove:

[root@lnx-svr-01 ~]# vgremove data
  Volume group "data" successfully removed
[root@lnx-svr-01 ~]#

There is no need to run these two commands (vgrename and vgremove), they are for your reference only.

This is then end of Part 2. Please go to Part 3, to setup and configure Logical Volumes.

References:
How to Create LVM Partition in RHEL 6 / CentoOS
Linux Basics – LVM (Logical Volume Manager) Tutorial
How to Install LVM on Linux and Disk Operations
A Beginner’s Guide To LVM
How To Create LVM Using vgcreate, lvcreate, and lvextend lvm2 Commands