Overview #
LVM stands for Logical Volume Manager, and it’s a widely used technique in Linux and Unix-like operating systems for managing disk drives and storage. It offers a level of abstraction between the operating system and physical storage devices, allowing administrators to create logical volumes that can span multiple physical disks. Key components of LVM:
Physical Volumes (PVs): Physical volumes are typically individual hard drives, solid-state drives (SSDs), or partitions on those drives. LVM combines one or more physical volumes into volume groups.
Volume Groups (VGs): Volume groups are pools of physical volumes that are grouped together to form a larger storage entity. Multiple physical volumes can be added to a volume group, and they contribute their storage capacity to the group. You can create multiple volume groups on a single system.
Logical Volumes (LVs): Logical volumes are the virtual partitions created within volume groups. They can be resized dynamically, unlike traditional partitions. LVs are what you actually use to store data, and they’re mounted like regular partitions.
Physical Extents (PEs): Physical extents are the smallest unit of storage within LVM. When you create a volume group, the physical volumes are divided into equal-sized chunks called physical extents. Logical volumes are created by allocating a certain number of physical extents from the volume group.
Logical Extents (LEs): Logical extents are similar to physical extents, but they are used within logical volumes instead of volume groups. Logical extents are the smallest unit of allocation for data within a logical volume.
LVM Commands: LVM provides a set of commands for managing physical volumes, volume groups, and logical volumes. Some common commands include pvcreate (to initialize physical volumes), vgcreate (to create volume groups), lvcreate (to create logical volumes), lvextend (to extend logical volumes), and many more.
LVM features #
Logical Volume Manager (LVM) offers several useful features and functionalities that make it a valuable tool for managing storage in Linux and Unix-like operating systems. Here are some common usages of LVM:
Flexible Disk Management: LVM allows for dynamic resizing of logical volumes (LVs) and volume groups (VGs) without needing to unmount the file system or disrupt data access. This flexibility is particularly beneficial in environments where storage needs change over time.
Volume Management: LVM enables the aggregation of multiple physical volumes (PVs) into logical volume groups (VGs), providing a unified storage pool. This allows administrators to manage storage resources efficiently and allocate space to different partitions or file systems as needed.
Snapshot Creation: LVM supports the creation of snapshots, which are point-in-time copies of logical volumes. Snapshots can be used for various purposes, including backup operations, system recovery, and testing software updates or configurations without affecting the original data.
Data Migration and Mobility: LVM facilitates the movement of data between physical devices and storage arrays without disrupting services or applications. Administrators can migrate data between different types of storage devices or redistribute data across storage arrays to optimize performance or capacity.
Volume Striping and Mirroring: LVM supports volume striping and mirroring for improved performance and data redundancy. Striping distributes data across multiple physical volumes to enhance I/O performance, while mirroring duplicates data across separate physical volumes to provide fault tolerance and data protection against disk failures.
Thin Provisioning: LVM offers thin provisioning, allowing administrators to allocate storage space on-demand rather than preallocating it upfront. Thin provisioning helps optimize storage utilization by reducing wasted space and enables more efficient management of storage resources.
Data Encryption: LVM provides support for encrypting data at the volume level using technologies such as dm-crypt and LUKS (Linux Unified Key Setup). This feature enhances data security by encrypting sensitive information stored on logical volumes, protecting it from unauthorized access or theft.
Resilience and Fault Tolerance: LVM enhances system resilience and fault tolerance by providing features such as RAID (Redundant Array of Independent Disks) and volume mirroring. These features help protect against data loss and minimize downtime in the event of disk failures or other hardware issues.
Disk Resizing with LVM #
RELIANOID Appliances are delivered in a lightweight format in order to make easy the deployment and installation in any platform, but if it’s required more storage for the logging system or custom application integration a filesystem resize is needed.
This guide provides step-by-step instructions for resizing partitions on RELIANOID Load Balancer using Logical Volume Manager (LVM). In this case, it is explained how to attach a new disk to the system and extend the logs partition that is running out of enough space.
Identify Partitions for Resizing #
Use the command lvdisplay to identify the partitions eligible for resizing.
root@ee-noid-01:~# lvdisplay | grep "LV Path" | grep root LV Path /dev/root/backup LV Path /dev/root/config LV Path /dev/root/log LV Path /dev/root/root LV Path /dev/root/swap
Note: If the LV Path doesn’t appear then your root partition can’t be increased.
Check Current Disk Space #
Use df to check the current disk space and identify available space for resizing.
root@ee-noid-01:~# df -h Filesystem Size Used Avail Use% Mounted on udev 983M 0 983M 0% /dev tmpfs 200M 3.0M 197M 2% /run /dev/mapper/root-root 5.0G 1.5G 3.3G 30% / tmpfs 998M 0 998M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 998M 0 998M 0% /sys/fs/cgroup /dev/mapper/root-log 3.4G 15M 3.2G 1% /var/log /dev/mapper/root-config 430M 2.4M 401M 1% /usr/local/zevenet/config /dev/mapper/root-backup 874M 2.2M 811M 1% /usr/local/zevenet/backups tmpfs 200M 0 200M 0% /run/user/0
Attach a New Virtual Disk #
From the Hypervisor Client in case that it is a virtual appliance or phisically with a new disk in case of hardware appliance, attach a new virtual disk with the desired space (e.g., 2GB). Identify the new disk, for instance, /dev/sdb, using fdisk.
root@ee-noid-01:~# fdisk -l Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Disk model: Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sda: 12 GiB, 12884901888 bytes, 25165824 sectors [...]
Create a Partition #
Use fdisk /dev/sdb to create a partition covering the entire disk space. Select partition type p for primary and assign it the entire disk space. Change the partition type to Linux LVM using t command. Write changes using w command.
root@ee-noid-01:~# fdisk /dev/sdb Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0xeb0c8ed2. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-4194303, default 2048):Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-4194303, default 4194303): Created a new partition 1 of type 'Linux' and of size 2 GiB. Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
Confirm Partition Creation #
Verify the creation of /dev/sdb1 using fdisk -l /dev/sdb.
root@ee-noid-01:~# fdisk -l /dev/sdb Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Disk model: VBOX HARDDISK Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xeb0c8ed2 Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 4194303 4192256 2G 8e Linux LVM
Identify Volume Group #
Verify the current details of the volume group to be extended with the vgdisplay command.
root@ee-noid-01:~# vgdisplay --- Volume group --- VG Name root System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 5 Open LV 5 Max PV 0 Cur PV 1 Act PV 1 VG Size <12.00 GiB PE Size 4.00 MiB Total PE 3071 Alloc PE / Size 2862 / <11.18 GiB Free PE / Size 209 / 836.00 MiB VG UUID FxCrfj-5Rt7-1CrE-9hUv-7qwj-0yAb-AJ2euu
Extend Volume Group #
Use vgextend root /dev/sdb1 to extend the volume group with the new partition.
root@ee-noid-01:~# vgextend root /dev/sdb1 Physical volume "/dev/sdb1" successfully created. Volume group "root" successfully extended
Confirm Volume Group Extension #
Verify the extension of the volume group using vgdisplay.
root@ee-noid-01:~# vgdisplay --- Volume group --- VG Name root System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 5 Open LV 5 Max PV 0 Cur PV 2 Act PV 2 VG Size 13.99 GiB PE Size 4.00 MiB Total PE 3582 Alloc PE / Size 2862 / <11.18 GiB Free PE / Size 720 / 2.81 GiB VG UUID FxCrfj-5Rt7-1CrE-9hUv-7qwj-0yAb-AJ2euu
Assign Extra Space to Desired Partition #
Use lvextend -l +100%FREE /dev/root/log to assign the extra space to the desired partition (e.g., logs).
root@ee-noid-01:~# lvextend -l +100%FREE /dev/root/log Size of logical volume root/log changed from 3.46 GiB (886 extents) to 6.27 GiB (1606 extents). Logical volume root/log successfully resized.
Confirm Assignment #
Confirm the assignment using lvdisplay.
root@ee-noid-01:~# lvdisplay [...] --- Logical volume --- LV Path /dev/root/log LV Name log VG Name root LV UUID 3TJZYd-gT8Z-JjJY-2mNB-wxLr-Xcdt-6bMrVs LV Write Access read/write LV Creation host, time zva6000, 2023-06-20 12:43:08 +0000 LV Status available # open 1 LV Size 6.27 GiB Current LE 1606 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:4 [...]
Resize the Partition #
Use resize2fs /dev/root/log to resize the partition with the new free space.
root@ee-noid-01:~# resize2fs /dev/root/log resize2fs 1.44.5 (15-Dec-2018) Filesystem at /dev/root/log is mounted on /var/log; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 The filesystem on /dev/root/log is now 1644544 (4k) blocks long.
Confirm Resizing #
Verify the new free space is available using df.
root@ee-noid-01:~# df -h Filesystem Size Used Avail Use% Mounted on udev 983M 0 983M 0% /dev tmpfs 200M 3.1M 197M 2% /run /dev/mapper/root-root 5.0G 1.5G 3.3G 30% / tmpfs 998M 0 998M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 998M 0 998M 0% /sys/fs/cgroup /dev/mapper/root-config 430M 2.4M 401M 1% /usr/local/zevenet/config /dev/mapper/root-backup 874M 2.2M 811M 1% /usr/local/zevenet/backups /dev/mapper/root-log 6.2G 17M 5.8G 1% /var/log tmpfs 200M 0 200M 0% /run/user/0
By following these steps, you can effectively resize partitions on RELIANOID Load Balancer using LVM, ensuring optimal utilization of disk space and ready to scale more services.