Adding Disk Space to a Logical Volume Manager
In many scenarios, the default disk allocation for Linux partitions is inadequate for installation of larger HANA-based systems. This guide will detail formatting additional disk volumes and extending the Linux Volume Manager (LVM) partitions to include the added space.
In my scenario, I found it necessary to extend both /var and /opt directories when installing Hadoop, which I will walk through below.
Steps:
- Creating the Volume
- Adding the volume to volume group
- Extending the volume partitions
Creating the Volume
This step will be specific to your environment. In cloud scenarios additional virtual disks can often be attached to nodes in your cluster, or actual physical disks can be added to each node. Once added, the disk should be accessible from /dev/sd*. The exact letter will depend on the number of disks attached (/dev/sda, /dev/sdb, /dev/sdc, etc.)
Adding the volume to volume group
Next we need to SSH to the instance where we attached the volume. Once connected log in as root.
In my case, my disk is available at /dev/sdb by default
# ls -al /dev/xxxx/vol-e338e620 lrwxrwxrwx 1 root root 6 Feb 14 20:13 /dev/xxxx/vol-e338e620-> ../sdb
Right now, our connected hard drive is on /dev/sda and is split into two paritions: a boot partition (sda1) and the LVM hard drive partition (sda2). Our attached storage (sdb) is still un-formatted and without a filesystem:
# fdisk -l /dev/sda Disk /dev/sda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 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: 0x0009dda3 Device Boot Start End Blocks Id System /dev/sda1 * 1 39 307200 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 39 7833 62606336 8e Linux LVM # fdisk -l /dev/sdb Disk /dev/sdb: 268.4 GB, 268435456000 bytes 255 heads, 63 sectors/track, 32635 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
We need to identify the volume group (VG) being used as this is what we will need to extend. You can confirm the name of the VG using vgdisplay like below:
# vgdisplay --- Volume group --- VG Name VOL System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 6 Open LV 6 Max PV 0 Cur PV 1 Act PV 1 VG Size 59.69 GiB PE Size 32.00 MiB Total PE 1910 Alloc PE / Size 1910 / 59.69 GiB Free PE / Size 0 / 0 VG UUID YthGca-Su6c-LgkQ-5Miy-XIOI-heyb-da4nuO
We’ll use fdisk to create a new partition of type 8e (Linux LVM). The order of commands is below:
# fdisk /dev/sdb n - create a new partition p - specify primary [enter] x2 - use the entire disk t - change type 8e - Linux LVM type w - write partition table to disk and exit
Within fdisk, press m at any point to see a list of possible commands. Once written, your new disk should look like this:
Device Boot Start End Blocks Id System /dev/sdb1 1 32635 262140606 8e Linux LVM
Now we create a new Physical Volume (PV) to use this new partition using pvcreate command:
# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created
Next, use pvextend to extend our volume group VOL to include the new volume:
# vgextend /dev/VOL /dev/sdb1 Volume group "VOL" successfully extended
Extending the volume partitions
Finally we’ll extend our partitions and then resize the filesystem. You can see a list of all partitions under /dev/VOL/.
First, we’ll use lvextend to extend each logical volume. In this example I am assigning an additional 100GB to each node:
# lvextend -L +100G /dev/VOL/opt Size of logical volume VOL/opt changed from 7.72 GiB (247 extents) to 107.72 GiB (3447 extents). Logical volume opt successfully resized # lvextend -L +100G /dev/VOL/var Size of logical volume VOL/var changed from 5.94 GiB (190 extents) to 105.94 GiB (3390 extents). Logical volume var successfully resized.
Now in order to use the new space, we need to extend the filesystem. The command run will depend on the filesystem in use. Issuing df -T will provide the filesystems for all disks. For ext2, ext3, and ext4 filesystems we can use resize2fs:
# resize2fs /dev/VOL/var resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/VOL/var is mounted on /var; on-line resizing required old desc_blocks = 1, new_desc_blocks = 7 Performing an on-line resize of /dev/VOL/var to 27770880 (4k) blocks. The filesystem on /dev/VOL/var is now 27770880 blocks long. # resize2fs /dev/VOL/opt resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/VOL/opt is mounted on /opt; on-line resizing required old desc_blocks = 1, new_desc_blocks = 7 Performing an on-line resize of /dev/VOL/opt to 28237824 (4k) blocks. The filesystem on /dev/VOL/opt is now 28237824 blocks long.
Your volumes should now be extended! You can confirm by issuing df -h. Below, we can see /var is now 105G and /opt is 106G:
# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VOL-root 32G 2.3G 28G 8% / tmpfs 16G 0 16G 0% /dev/shm /dev/sda1 283M 32M 236M 12% /boot /dev/mapper/VOL-home 2.9G 4.6M 2.8G 1% /home /dev/mapper/VOL-opt 106G 4.8G 96G 5% /opt /dev/mapper/VOL-tmp 7.5G 48M 7.1G 1% /tmp /dev/mapper/VOL-var 105G 2.5G 97G 3% /var
What is the reason to use fdisk before pvcreate? Doesn't seem to add anything except an extra step.