LVM Documentation
Logical Volume Manager
LV, or Logical Volume, is a virtual storage unit created and managed by a Logical Volume Manager (LVM). Unlike traditional disk partitions that have fixed sizes, logical
volumes are more flexible and can be resized or moved across different physical storage devices without significant disruption.
Key Characteristics of Logical Volumes (LVs):
• Flexibility:
• Virtualization:
• Part of a Volume Group (VG):
• File System Compatibility:
This Document Covers:
1. Creating Partitions on sdb
2. Creating Physical Volume
3. Creating Volume Group
4. Creating Logical Volume
5. Make LVM File System
6. How To Increase Volume Group
7. How To Increase Logical Volume Size
8. Removing LVM
9. Remove Linux Group
10. Remove Physical Volumes
11. Remove Physical Partitions
12. Creating Partitions on Different Disks
13. Mount Directory On LVM
14. Creating New Partition And Increase LVM
15. Extend Volume Group
16. Extend Logical Volume
17. Reducing LVM Size
18. Use LVM As NFS Storage
VM Storage Disks:
• List Storage: There are two storage disks on this VM listed as sda and sdb. I will use sdb storage to create LVM
1
LVM Documentation
• Main Configuration File of VSFTPD: As it shows that, sdb storage disk has no disk partitions
Creating Partitions on sdb:
• Disk Partition : Use fdisk command to create disk partition.
I. n: new partition
II. p: Primary partition
III. 1: Partition number
IV. +2G: partition will be created of 2 GB size.
V. t: change partition type
VI. L: To view codes
VII. 8e: To change partition type from “Linux” to “Linux-LVM”
VIII. w: save changes
2
LVM Documentation
• Inform Kernel: This command will tell all the changes you have made to the kernel:
Creating Physical Volume:
• List Physical Volume: As we have created disk partitions, so or next step will be creating physical volumes. From following command yo can list all the physical
volumes in your VM.
• Create A Physical Volume In sdb1: Here, we are going to create a physical volume in sdb1 and also list it to view
Creating Volume Group:
• List Volume Group: vgdisplay is the command to list all the volume group.
• Create Volume Group: Following you can create and list volume group
3
LVM Documentation
Creating Logical Volume:
• List Logical Volume: lvdisplay is the command to list all the logical volumes.
• Create LVM: You can create LVM by following command. As you have created volume group LinuxVG, so you cannot exceed LVM size by 2GB.
4
LVM Documentation
• Check LVM File Type: You can check LVM type by entering following command. Since we have just created LVM, so it will not have any file system as showing
you below.
• Make LVM File System: You can make a file system on your LVM by following command.
• Mount LVM: You can mount a LVM on a directory by following command
• Data In testdir: For the clarification of concepts here, I have created 100 files named test{1..100} in testdir. Since we mount /testdir directory with
/dev/sdb1/LinuxVG/LinuxLV so data will actually store on /dev/sdb1 directory which is a physical volume in disk sdb
How To Increase Volume Group:
5
LVM Documentation
• Concept: If you want to increase your LVM and think about first bottleneck issue of volume group. You will need to increase your volume group. A name “group”
specifies that you can add multiple volumes to your logical volume.
I. Creating storage partition in sdb like in our case
II. Creating physical volume
III. Assign physical volume to that volume volume group.
In our case, we have already created the partition sdb2 on sdb in “Creating Partitions on sdb” step. So, here we create the physical volume in this partition like follows:
• Extend Volume Group: By following command you can easily extend your volume group. vgdisplay command shows you the extended size of this volume
group LinuxVG
How To Increase Logical Volume Size:
• Concept: Since you have increased the size of your logical volume in previous step. So, you can now be able to increase your logical volume size as well. Please
note that you can create multiple logical volume in your volume group. Here following you can see that we have a LV which size is 1.46GB right now.
• Extend Logical Volume Size: By following command, you can increase your logical volume size.
6
LVM Documentation
Going Back:
• Removing LVM: As you know that first of aall we have added a physical storage, created partition, physical volume, volume group and then created the LVM.
Now we have to remove it for our practice purpose. So, you have to follow the steps in just opposite order. So, in first order just unmount the LVM.
• Remove Linux Group: Now you need to remove the linux group.
• Remove Physical Volumes: Now, you can remove physical volumes that you made previously for your LVM. Since, we have created two volumes like sdb1 and
sb2. Now we can remove them using following command:
7
LVM Documentation
• Remove Physical Partitions: As you removed your physical volumes that you created on physical partitions. After that, you can remove physical partitions one
by one. Press w and Enter to save the changes. Then enter partprobe to reflect the changes:
Creating Partitions on Different Disks:
• Partitions: Since we have added (sdb) for scsi and (sdc) for sata drives on our VM and now trying to make partitions on it. For sdb and sdc respectively:
8
LVM Documentation
Creating Physical Volumes on Different Disks:
• Physical Volume: Since we have created sdb1 partition on (sdb) for scsi and sdc1 partition on (sdc) for sata drives on our VM and now trying to make their
physical volume respectively:
9
LVM Documentation
Creating Volume Group:
• Volume Group: Now you can create volume group on these two partitions that were created on two different types of disks:
Creating Logical Volume:
• Logical Volume: Now you can create logical volume on previously created volume group:
• Assign File System To LVM: Newly created LVM has no file system. So you can assign it a file system by following command:
• Mount Directory On LVM: You can mount a directory on LVM by following command:
10
LVM Documentation
• Extent Logical Volume: You can extend logical volume as well. By vgdisplay, you can check free space and extend LVM accordingly:
Creating New Partition And Increase LVM:
• Add New Partition on Disk SDB: You can create new partition as following way:
11
LVM Documentation
Create Physical Volume: You can now create physical volume by following command:
Extend Volume Group: Now you can extend VG by following way:
Extend Logical Volume: Now you can extend LV by following way:
Reducing LVM Size:
• Concept: Since LVM size is 7GB. We can also reduce it. But before reduce, please unmount any directory which is already mounted on this LVM for safety
purpose:
• Check File System: Check file system before reducing the LVM. Non-contiguous shows that there is no error in your file system:
• Size Reduction: You can reduce your LVM size by following command:
12
LVM Documentation
• Mount Directory Again And Verify Content: After resizing, you can mount the directory again and check your content safe:
Use LVM As NFS Storage:
• Concept: You can mount a directory on LVM storage and then share it to different clients VMs as a NFS host. Just create an directory on your NFS Server like
/mnt/nfs_share/0_55:
• Create Content In That Directory: You can create content in this directory like:
• Mount This Directory On LVM: You can create content in this directory like:
• Change The Ownership Of That Directory On Server End: You need to change the ownership of that directory to nobody.:
13
LVM Documentation
• Change Directory Permissions: As other clients needs to read and write on this specific directory so please change its permissions as follows:
• Edit /etc/exports: Please open up the exports file and made changes like follows and save the file:
• Export The Share: You can export the share by following command By NFS Server-side:
• Allow Firewall: If you are using firewall in your machines, then you run the below-mentioned command ask firewall to allow NFS service.:
• RPC Bind: As I asked before, if you are using firewall, then you need to allow another service known as “rpc-bind”. This service redirect the client to the port on
which it can communicate the server. I have mentioned the port for NFS service earlier which is 2049.
• Mountd Service: You need to allow another service named as “mountd”. This will allow the remote clients to mount the server NFS directory on their machines
as well.
• Firewall Reload: You need to reload firewall setting by running above command. You need these firewall related commands only when if you are using firewall.
If you are not using then, then you can simply skip these commands
Client-Side Configuration:
• Configuring Client: Run following command on client side which IP is 192.168.0.55:
14
LVM Documentation
• Configuring Client: Run the below-mentioned command to visualize whether the exported share from NFS server is showing on client side or not?:
• Create A Directory At Client Side: You need to create a directory on client side that you want to mount with NFS host server directory. Like follow:
• Create A Directory At Client Side: We have write the mount keyword with -t which shows the mount type which is nfs. After that, we have given the complete
address of NFS share that we have created on our server side with its IP and share path. And finally, we mounted the client side mount which is
“/mnt/client_share” with NFS share of our server.:
Verification:
• Create A File And Add At Clien-End: Create a File and add content in it:
• Read That File From Server-End: Read the same file at server end that you have created on your client.
15
LVM Documentation
Mount Using FSTAB:
• Unmount Client Directory: Just to see how you can mount a directory via fstab, please unmount the client directory first:
• Create A Directory At Client Side: Please made an entry in your client-side /etc/fstab file.
• Check Mount: Check mount by “mount -a” command
• Concept: Here is the concept. You made a share directory for your client which was originally mounted on LVM storage. And using NFS you just made it possible
to share that nfs share with your client machine (192.168.0.55). Now this client is able to not only access that directory content but create it on client as well
which can be seen at server end as well:
Acknowledgement: Thanks to Honorable Mr. Vikas Nehra for his wonderful tutorial on this topic. His tutorial helped us in setting up this LVM share setup on our VM. His
two different tutorials links are attached as well for further guidance:
• Video 1: https://www.youtube.com/watch?v=juESDilXJuU
• Video 2: https://www.youtube.com/watch?v=_gxBkilrJIA&t=1319s
LVM NFS portion covered with the help of ChatGPT.
Regards:
Khurram Shahzad
16