What is LVM in Linux LVM (Logical Volume Management) is a flexible and powerful system for managing disk storage in Linux. It allows administrators to create, resize, and manage storage volumes more easily and dynamically than with traditional partitioning schemes. LVM provides abstraction layers between the physical storage (like hard drives or SSDs) and the logical volumes that the operating system and applications use. Key Concepts of LVM LVM works by creating logical volumes (LVs) that can span across multiple physical disks, allowing for easy resizing and reorganization of storage as needed. The main components in an LVM setup are: Physical Volume (PV): A physical volume is typically a disk or a partition on a disk that is initialized for use by LVM. A physical volume is the foundational storage device for LVM. It can be a whole disk (e.g., /dev/sda) or a partition (e.g., /dev/sda1). Volume Group (VG): A volume group is a collection of physical volumes (PVs) that are grouped together. It acts as a pool of storage. Once the physical volumes are initialized into a volume group, the space in the VG can be used to create logical volumes. The VG abstracts the underlying physical storage, enabling easier management and allocation of storage space. Logical Volume (LV): A logical volume is essentially a virtualized partition within a volume group. It can be resized and managed dynamically, making it much more flexible than traditional partitions. Logical volumes are what the operating system recognizes as "partitions," and they are formatted with a filesystem (e.g., ext4, xfs). Physical Extents (PE): Physical extents are the smallest units of storage within a physical volume. They are fixed-size chunks of storage space. The size of the physical extent is set when initializing the physical volume, and it is usually 4MB or 8MB by default. When you create a logical volume, LVM allocates physical extents from the available physical volumes. Logical Extents (LE): Logical extents are the virtual equivalent of physical extents and represent the smallest unit of storage for a logical volume. They are mapped directly to physical extents on the physical volumes, but they are part of the abstraction layer that LVM provides. Key Advantages of LVM Dynamic Volume Resizing: With LVM, you can resize logical volumes without needing to reformat or delete data. You can increase or decrease the size of volumes on the fly as your storage needs change. Disk Pooling: LVM allows you to pool multiple physical disks into a single volume group. This means you can combine several physical devices (e.g., /dev/sda, /dev/sdb, /dev/sdc) into one larger storage space, which simplifies management. Snapshot Support: LVM allows you to create snapshots of logical volumes. A snapshot is a read-only copy of a logical volume at a particular point in time, making it useful for backups or system restore. Flexibility: LVM provides great flexibility in managing storage. You can easily add new physical volumes to expand your volume group, move logical volumes between different physical volumes, and grow/shrink logical volumes as required. Improved Data Management: You can move data between physical volumes without unmounting the logical volume. This means you can relocate files to different physical disks or reorganize your storage without downtime. RAID-like Functionality: LVM can provide some RAID-like features, such as mirroring and striping, using the LVM RAID feature, which can improve redundancy and performance. Commnd Start 1.sudo fdisk -l : find new drive or lsblk or df -h 2.sudo pvscan 3.sudo fdisk /dev/sdb n p 1 [enter] [enter] t 8e w 5.lsblk and see /dev/sdb1 added if /dev/sdb1 is not seen then reboot before continuing further 5.lsblk and see /dev/sdb1 added if /dev/sdb1 is not seen then reboot before continuing further 1 - pvcreate /dev/sdb1 <create a LVM physical volume on the partition we just created> pvdisplay <Checking Commnd> Vg Create Commnd Create volume Group 2 - vgcreate vgapps /dev/sdb1 /dev/sdb2 Lv Create Commnd lvcreate -L 1G -n app1-lv vgapps lvcreate -L 1G -n app2-lv vgapps lvdisplay <Checking LV Create Or Not> Formating Commnd mkfs.ext4 /dev/vgapps/app1-lv Create a mount point and then mount the volume somewhere you can use it. 5 - mkdir /mnt/app1 6 mount /dev/vgapps/app1-lv /mnt/app1 Checking All HDD Disk Space Commnd - df -th HDD Add to Fstab Configuration cat /etc/mtab Space Extend Add New HDD Disk Then Follow Step fdisk /dev/sdc n = create new partition p = creates primary partition 1 = makes partition the first on the disk t = change partition type 8e = changes to LVM partition type p = view partition setup so we can review before writing changes to disk w = write changes to disk pvcreate /dev/sdbc <create a LVM physical volume on the partition we just created> 6 - vgextend vgapps /dev/sdc1 Extend Logical Volume 7 - lvextend -L +1G /dev/vgapps/app1-lv 8 - resize2fs /dev/vgapps/app1-lv How To Cheking Linux Ubantu Disk Status lsblk fdisk -l df -hT lsblk -f <Cheking Formating Partition > mount -av <cheking Mounting> How To Create Linux Ubantu LVM Step#01 fdisk /dev/sdb <Go To HDD > Step#02 n, p, t, 8e, w <New Partion Create> Step#03 partprobe /dev/sdb <Karnel Infom For New HDD Partition> Step#04 pvcreate /dev/sdb1 <Create Pv> Step#05 vgcreate nextcloud /dev/sdb1 <Create VG> Step#06 lvcreate -L 500G -n nextcloud nextcloudlv <Create LV> Step#07 mkfs.ext4 /dev/mapper/nextcloud-nextcloudlv <Formating> Step#08 mount /dev/mapper/nextcloud-nextcloudlv /var/www/html <Create Mount Point For Use Disk Space> Step#09 df -hT <For Checking Mount> Step#10 cat/etc/mtab <Copy Full Path nextcloud-nextcloudlv For Entry Fstab> Step#11 nano /etc/fstab Step#12 /dev/mapper/nextcloud-nextcloudlv /var/www/html ext4 errors=remount-ro 0 1 <Paste This Line Fstab Then Save How To Cheking Linux Ubantu LVM Status pvdisplay vgdisplay lvdisplay lvs vgs pvs lvscan pvscan vgscan How To Remove Linux Ubantu LVM lvremove /dev/nextcloud/nextcloudlv How to vgextended Commnd vgextend vgapps /dev/sdc1 Extend Logical Volume lvextend -L +1G /dev/vgapps/app1-lv resize2fs /dev/vgapps/app1-lv