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