
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Increase Size of Linux LVM by Adding a New Disk
This article helps us to add a new disk to LVM ( Logical Volume Manager), the very best advantage of LVM over normal disk partitions is its support for “dynamic partitions”; you can create and resize (expand or shrink) LVM volumes dynamically as we needed. There is no limit of the physical disk boundary in LVM logical volumes, so you can create a large LVM volume that spans across multiple smaller physical disks. This flexibility partitioning allows you to manage storage space more efficiently as disk usage change from time to time.
If you want to add new disks to an existing LVM volume to expand its size, you can easily do it, and below is the procedure on how to do –
Configuration
We needed to login as root user and, run fdisk to check whether the new disks which is attached are detected by Linux on your system.
# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000c664e Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/sdc: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_root: 18.8 GB, 18798870528 bytes 255 heads, 63 sectors/track, 2285 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/VolGroup-lv_swap: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
In the above command, we found 3 disks (/dev/sda, /dev/sdb, /dev/sdc). The 1st disk (/dev/sda) is used by LVM, which shows partitions, while the other two (/dev/sdb and /dev/sdc) are not added to LVM, and do not have any partition on the disks.
Check the availability of LVM volume groups and logical volumes with the ‘lvs’ command.
# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lv_root VolGroup -wi-ao---- 17.51g lv_swap VolGroup -wi-ao---- 2.00g
In the example, one volume group (“lv”) exists, and two logical volumes (“root” and “swap”) are created in this volume group.
# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/VolGroup-lv_root 17938864 1997688 15023264 12% / tmpfs 502384 0 502384 0% /dev/shm /dev/sda1 487652 41991 420061 10% /boot
According to the df output, the “root” logical volume is mapped to /dev/mapper/VolGroup-lv-root by the device mapper.
Using this information, I will show you how to add two disks /dev/sdb and /dev/sdc to the “root” logical volume in the next steps.
Create Partitions on New Disks
The first step is to create a partition on each new disk before adding them to LVM. This step is needed only if you want to allocate only part of the disk to LVM. If you want to add the whole disk to LVM, creating a partition is not necessary, and you can skip this step.
Create Physical Volumes on New Disks
Next, create a physical volume on each new disk partition (/dev/sdb1 and /dev/sdc1).
# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created
Like this add the 3rd disk to the physical volume.
# pvcreate /dev/sdc Physical volume "/dev/sdc" successfully created
Using lvmdiskscan, verify that physical volumes are created successfully.
#lvmdiskscan -l /dev/ram0 [ 16.00 MiB] /dev/root [ 17.51 GiB] /dev/ram1 [ 16.00 MiB] /dev/sda1 [ 500.00 MiB] /dev/VolGroup/lv_swap [ 2.00 GiB] /dev/ram2 [ 16.00 MiB] /dev/sda2 [ 19.51 GiB] LVM physical volume /dev/sdb [ 20.00 GiB] LVM physical volume /dev/sdc [ 20.00 GiB] LVM physical volume 2 disks 2 LVM physical volume whole disks 1 LVM physical volume
Extend an Existing Logical Volume
Next, find the volume group which contains the logical volume to expand, and extend the group by adding newly created physical volumes to it.
In our example, the “root” logical volume belongs to the ” VolGroup-lv” volume group. Let’s add a /dev/sdb, the following command instead.
# vgextend yoda-vg /dev/sdb
Volume group “VolGroup” successfully extended. To verify that volume is added or not run, please check the below –
# vgs VG #PV #LV #SN Attr VSize VFree VolGroup 2 2 0 wz--n- 39.50g 20.00g # vgextend VolGroup /dev/sdc Volume group "VolGroup" successfully extended # vgs VG #PV #LV #SN Attr VSize VFree VolGroup 3 2 0 wz--n- 59.50g 39.99g
Given the resized volume group, now extend the “root” logical volume itself.
# lvextend -l+100%FREE /dev/VolGroup/lv_root Size of logical volume VolGroup/lv_root changed from 17.51 GiB (4482 extents) to 57.50 GiB (14720 extents). Logical volume lv_root successfully resized
The above command tells the “root” logical volume to use all available additional free space in its volume group. Note that /dev/VolGroup/lv_root is the device where “root” volume is mapped to.
The final step is to enlarge the file system created inside the “root” volume. Otherwise, the file system will not recognize additional free space in the volume.
# resize2fs -p /dev/VolGroup/lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required old desc_blocks = 2, new_desc_blocks = 4 Performing an on-line resize of /dev/VolGroup/lv_root to 15073280 (4k) blocks. The filesystem on /dev/VolGroup/lv_root is now 15073280 blocks long.
The resize2fs command supports resizing ext2/ext3/ext4 file systems. It also supports online resizing in case you expand a file system. No need to unmount the file system.
At this point, the file system should be expanded to take up 100% of the resized “root” logical volume.
If we have completed the above steps and add the disks to increase the volumes to extend the existing LVM we can increase the space without losing the data this will help the administrator to manage their disk spaces with our any down time.