Sponsored Links

Resize Linux storage with LVM

So you need more space on your server/desktop/etc.. This guide will help you add it to the volume you’re currently using on your system. For the sake of making this an easy-to-follow guide, we’ll assume that  you already have the new drive showing in your Linux installation from fdisk, but it’s not yet usable (ie: you made it available from shared storage, you installed a new harddrive, etc..). I have also included a note on how to grow vmware disks.

First, let’s see if the system can see the new storage:

# fdisk -l
Disk /dev/sdc doesn't contain a valid partition table

Note: you’ll also see information about your current drives. 

First things first, create a partition on the drive using fdisk, cfdisk, etc.. toggle it type ’8e’.

# fdisk /dev/sdc

Note: If growing a vmware disk at this step you will create a new partition and then just follow the same commands as below but on the new partition to grow the existing volume on the same disk. 

Now it should show up a little better in the fdisk -l command.

Next, create the physical volume on the new partition on the new drive:

# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created

Now, find out the volume group and logical volume names on your system. Make note of these..
# vgdisplay
# lvdisplay

We’ll assume that the information is:
Volume Group: test_vg
Logical Volume: test_lv

Now, use vgextend to add your new drive to the existing volume group:

# vgextend test_vg /dev/sdc1
  Volume group "test_vg" successfully extended

You can see, by viewing ‘vgdisplay’ again, it will show you the added space:
# vgdisplay

Now, pull it across into the logical volume:
# lvextend -l +100%FREE /dev/test_vg/test_lv
  Extending logical volume test_lv to 6.88 TiB
  Logical volume test_lv successfully resized

You’re almost home free – now, vgdisplay shows the correct info and so does lvdisplay – but a simple df -h still shows the filesystem size has not changed. Let’s tell the filesystem to stretch out across the full logical volume:
# resize2fs /dev/test_vg/test_lv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/test_vg/test_lv is mounted on /TEST; on-line resizing required
old desc_blocks = 347, new_desc_blocks = 441
Performing an on-line resize of /dev/test_vg/test_lv to 1848109056 (4k) blocks.
The filesystem on /dev/test_vg/test_lv is now 1848109056 blocks long.

And to see how it worked out:
# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/test_vg-test_lv   6.8T  4.9T  1.9T  73% /TEST

It worked!

Comments are closed.