Linux: Extend LVM by adding disk

Here is the current scenario: /u01 is under a LVM which is running out of space. The idea is to add space by adding a new disk (since this is a virtual machine, the disk being added is 15GB only)

Here is the initial output of df -h:

[root@demodb11g ~]# df -h
Filesystem            Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       27G  3.6G   22G  15% /
/dev/sda1              99M   24M   71M  25% /boot
tmpfs                 676M     0  676M   0% /dev/shm
repo                  146G  130G   17G  89% /media/share
/dev/mapper/VolDatabase00-lvol0
                       29G   26G  1.7G  94% /u01

Once the new disk is connected to the server, let’s partition it with fdisk:

[root@demodb11g ~]# fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklab el
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

The number of cylinders for this disk is set to 1958.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
 (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
 e extended
 p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1958, default 1): <Enter>
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1958, default 1958): <Enter>
Using default value 1958

Command (m for help): type
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

You can get the LVM and VG information from lvdisplay, here is an example:

[root@demodb11g ~]# lvdisplay
 --- Logical volume ---
 LV Name /dev/VolDatabase00/lvol0
 VG Name VolDatabase00
 LV UUID i0u35c-oMrd-0tB1-3H0n-YBIa-Meno-XmCOXZ
 LV Write Access read/write
 LV Status available
 # open 1
 LV Size 29.00 GB
 Current LE 7423
 Segments 4
 Allocation inherit
 Read ahead sectors auto
 - currently set to 256
 Block device 253:2

Now to start extending with the new disk, we use vgextend <VG name> </path/disk>

[root@demodb11g ~]# vgextend VolDatabase00 /dev/sdf1
 No physical volume label read from /dev/sdf1
 Writing physical volume data to disk "/dev/sdf1"
 Physical volume "/dev/sdf1" successfully created
 Volume group "VolDatabase00" successfully extended

We can check the new disk is added using pvscan:

[root@demodb11g ~]# pvscan
 PV /dev/sdb1 VG VolDatabase00 lvm2 [4.99 GB / 0 free]
 PV /dev/sdc1 VG VolDatabase00 lvm2 [4.99 GB / 0 free]
 PV /dev/sdd1 VG VolDatabase00 lvm2 [4.99 GB / 1000.00 MB free]
 PV /dev/sde1 VG VolDatabase00 lvm2 [15.00 GB / 0 free]
 PV /dev/sdf1 VG VolDatabase00 lvm2 [15.00 GB / 15.00 GB free]
 PV /dev/sda2 VG VolGroup00 lvm2 [29.88 GB / 0 free]
 Total: 6 [74.84 GB] / in use: 6 [74.84 GB] / in no VG: 0 [0 ]

Now that the disk has been added to the Volume Group, we can extend the Logical Volume using lvextend <path/to/lv> <path/disk>

[root@demodb11g ~]# lvextend /dev/VolDatabase00/lvol0 /dev/sdf1
 Extending logical volume lvol0 to 43.99 GB
 Logical volume lvol0 successfully resized

Finally, we run the resize2fs (or xfs_growfs if you are using CentOS or Red Hat 7 or newer with XFS filesystem) in order to see the changes reflect to df. If you try to check df before executing resize2fs, you will still see the old sizes.

[root@demodb11g ~]# resize2fs /dev/VolDatabase00/lvol0
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolDatabase00/lvol0 is mounted on /u01; on-line resizing required
Performing an on-line resize of /dev/VolDatabase00/lvol0 to 11532288 (4k) blocks.
The filesystem on /dev/VolDatabase00/lvol0 is now 11532288 blocks long.

That completes the resize!

[root@demodb11g ~]# df -h
Filesystem            Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       27G  3.6G   22G  15% /
/dev/sda1              99M   24M   71M  25% /boot
tmpfs                 676M     0  676M   0% /dev/shm
repo                  146G  130G   17G  89% /media/share
/dev/mapper/VolDatabase00-lvol0
                       44G   26G  16G  62% /u01
Advertisements

About Bruno Carvalho

Coffee addicted tech guy.
This entry was posted in Linux and tagged , , , , , , , , , , . Bookmark the permalink.

2 Responses to Linux: Extend LVM by adding disk

  1. Simple, but gold.
    Well done, buddy!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s