In this article we’ll going to explore on how to extend a partition which resides in a Logical Volume. LVM (Logical Volume Manager) is a great tool for managing your storage devices on a Linux host.

Lets start with some vocabulary. In the order of the lowest layer (hard disks) towards the highest layer (the file system):

  • Your hard disks cabled in the waiter or in a SAN
  • Physical Volume: these are the hard disks, a volume RAID or a volume coming from a SAN
  • Volume Group: concatenation of the physical volumes
  • Logical Volume: cutting of the volumes groups
  • File system: controls how files are organized in the volumes groups

The goal here is to add a new hard disk (or LUN) to the system and then to extend the “/oracle” file system. Once the machine is turned off a new disk is attached to the system (eg: disk02.vdi or disk03.vmdk) and the virtual machine is restarted (Note: Enterprise configurations will not need to reboot for adding a new device).

Currently the storage distribution of the system looks like this:

[root@vmreforadg02 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 3.0G 0 3.0G 0% /dev/shm
/dev/sda1 243M 105M 126M 46% /boot
/dev/mapper/vgdata-lvdata
48G 40G 8G 83% /oracle

As a new device was added to the system this device is now visible in the device tree: /dev/vdb

[root@vmoracle02 ~]# fdisk -l
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: 0x2bbb9b95

Create a new partition:

[root@vmoracle02 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x2bbb9b95.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

To switch to the partition menu press “p”:

Command (m for help): p
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: 0x2bbb9b95
Device Boot Start End Blocks Id System

Follow the steps below to create a new primary partition:

Command (m for help): n
Command action
e extended
p primary partition (1-4) p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

8e is the code for LVM and the partition now looks like this.

Command (m for help): p
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: 0x2bbb9b95
..
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 8e Linux LVM

The final step is to write the partition table to disk by pressing “w”:

Command (m for help): w
The partition table has been altered!
..
Calling ioctl() to re-read partition table.
Syncing disks.

The volume group “vgdata” can now be extended by adding the new partition:

[root@vmoracle02 ~]# vgextend vgdata /dev/sdb1
Physical volume "/dev/sdb1" successfully created
Volume group "vgdata" successfully extended
[root@vmoracle02 ~]#

Execute the following command to extend the new space available of the logical volume.:

[root@vmoracle02 ~]# lvextend -l +100%FREE /dev/mapper/vgdata-lvdata
Size of logical volume vgdata/lvdata changed from 47.75 GiB (12225 extents) to 67.75 GiB (17343 extents).
Logical volume lvdata successfully resized
[root@vmoracle02 ~]#
[root@vmoracle02 ~]# resize2fs /dev/mapper/vgdata-lvdata
resize2fs 1.43-WIP (20-Jun-2013)
Filesystem at /dev/mapper/vgdata-lvdata is mounted on /oracle; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 5
Performing an on-line resize of /dev/mapper/vgdata-lvdata to 17759232 (4k) blocks.
The filesystem on /dev/mapper/vgdata-lvdata is now 17759232 blocks long.

Verify if the change was made on the file system “/oracle”:

[root@vmoracle02 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 3.0G 0 3.0G 0% /dev/shm
/dev/sda1 243M 105M 126M 46% /boot
/dev/mapper/vgdata-lvdata
67G 40G 27G 58% /oracle
[root@vmoracle02 ~]#

Free space available again.


Thumbnail [60x60]
by
DevOps