In this post we will see how to create LVM partitions. LVM is one of the most important objectives of both RHCSA and RHCE. Also it is the most important and useful tool for Linux system administrators as it provides facility of extending and reducing partitions online.
LVM covers following topics.
- Creating Physical Volumes
- Creating Volume Group.
- Creating Logical Volumes.
- Rename Volume Group.
- Rename Logical Volume.
- Extending Logical Volume Online.
- Extending Logical Volume Online.
- Reducing Volume Group.
- Deleting Logical Volume.
- Deleting Volume Group
- Deleting Physical Volume.
In the previous post I mentioned that the Physical Volume can be a partition or a whole disk. To see current partitions and disks use fdisk –l. In this example I will use the whole disk to create a Physical Volume.
1. First select the disk from which you have to create the Physical Volume. In this example I am using the second and third disk (sdb and sdc) to create two PV.
2. Use fdisk to create partition on the required hard disc and create a partition of whole disk as shown below.
Note. It is not required to change the partition type to 8e (Linux LVM), this is just for the refrence.
4. Now use pvcreate command to create the Physical Volume. Ex pvcreate /dev/sdb1, I have created one more PV with disc sdc, and use pvdisplay/pvscan command to view Physical volume.
Ex: vgcreate <VG_NAME> /dev/sdb1 /dev/sdc. And use vgscan/vgdisplay command to view the VG.
In the above image we can see that there is 3.99GB/1022 PE free space we will create two LVs of 1 GB each.
6. From the above volume group we can create logical volumes as we like, in this example I will create 2 logical volumes each of size 1 GB.
lvcreate –L 1G –n lvdata MYVG0
-L is for size
-n is for lvname.
MYVG01 is VG name from which we have to create the LV.
The above command will create a LV of size 1GB. We can see the created logical volume by lvscan/lvdisplay command.
In this example we will create LV using physical extents. In vgdisplay command we can see that Physical Extent size is 4Mb therefore to create LV of size 1Gb we need 256 Physical Extents (PE).
lvcreate –l 256 –n lvdata1 MYVG01
Here –l is for number of PE.
7. Now to use these LVs first we have to create file system (format) of these LVs using mkfs.ext4 command.
- mkfs.ext4 /dev/MYVG01/lvdata
- mkfs.ext4 /dev/MYVG01/lvdata1
In the next post we will see how to rename Volume Groups and Logical Volumes. If you have any questions and queries please post comments.
No comments:
Post a Comment