Articles Comments

LinuxOS Pro » Featured, Storage » Resize Linux storage with LVM

Resize Linux storage with LVM

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..). online storage

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

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!


Filed under: Featured, Storage · Tags:

9 Responses to "Resize Linux storage with LVM"

  1. Jeffrey says:

    Nice. Believe lvextend can do the filesystem resize itself saving a step with the -r option. I also prefer the lvm executable with lvextend as an argument. The you just have to remember lvm command versus all the individual.

    [root@one jwacase]# lvm lvextend –help | grep -i resize
    [-r|--resizefs]

  2. Kees says:

    Nice article, but the biggest advantage that you don’t mention is that it can be done on-line! I.e. as the filesystem is mounted, so you don’t have to stop applications. Which is importend if you run a server.

    You also don’t mention shrinking, which is also possible, but that has to be done off-line, so you first have to unmount the filesytem and than have to run fsck first.

  3. Rob says:

    Kees: you’re right.. thanks! I’ve done this probably a dozen times.. but have never tried the shrinking as of yet.. Maybe that’s the next article.

  4. Kees says:

    Okay, but it is also possible with other filesystems, I had some good experiances with reiserfs under SuSe Enterprise 9.

    Good luck with your articles,

    Kees

  5. sudy9 says:

    Every time it wont be hdc in HDD otherwise good article. G8 keep it up.

  6. bryce12 says:

    I have not done much space management but this sounds exciting. I was not aware of lvextend , so thanks for posting this article. I’m going to try it on a spare machine in my company so that I don’t mess up anything by chance.

  7. Brian Schonecker says:

    Tip for downsizing file systems:

    If you want to downsize a file system from 100G to 75G (for example), resize the file system to 74G, then resize the logical volume to 75G, then upsize the filesystem to 75G. Even though this is a couple of extra steps, it ensures that you don’t have any trouble ‘overlapping’ your LV with your FS. LVM is smart enough not to let you screw up your file system but the extra effort is worth the safety.

Leave a Reply

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>