How to resize a LVM volume

December 19th, 2009 Categories: Linux

Here’s a quick run-down on how to resize an existing LVM volume on Linux. I’m currently using LVM2.

Let’s see what LVM volumes I have configured right now:

[root@Rudi-PC ~]# lvscan
ACTIVE ‘/dev/vg_rudipc/swap’ [5.80 GB] inherit
ACTIVE ‘/dev/vg_rudipc/var’ [2.00 GB] inherit
ACTIVE ‘/dev/vg_rudipc/home’ [20.00 GB] inherit
ACTIVE ‘/dev/vg_rudipc/root’ [8.00 GB] inherit
ACTIVE ‘/dev/vg_rudipc/data’ [10.00 GB] inherit

I used lvscan for this, but you can also use lvs or lvdisplay to get more info on the volumes.

Now, I want to resize the data partition, so I run the following:

[root@Rudi-PC ~]# lvresize /dev/vg_rudipc/data -L +10GB
Extending logical volume data to 20.00 GB
Logical volume data successfully resized

With lvresize, I basically told LVM to resize the data lv with 10GB extra storage (with the -L +10GB switch) inside the vg_rudipcPV vg

As you can see below, the logical volume has been increased by 10GB.

[root@Rudi-PC ~]# lvscan
ACTIVE ‘/dev/vg_rudipc/swap’ [5.80 GB] inherit
ACTIVE ‘/dev/vg_rudipc/var’ [2.00 GB] inherit
ACTIVE ‘/dev/vg_rudipc/home’ [20.00 GB] inherit
ACTIVE ‘/dev/vg_rudipc/root’ [8.00 GB] inherit
ACTIVE ‘/dev/vg_rudipc/data’ [20.00 GB] inherit

This is the easy part. Now you still need to tell Linux that the LVM partition was resized.

[root@Rudi-PC ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_rudipc-root
7.9G 3.8G 3.8G 51% /
/dev/sda1 194M 15M 170M 8% /boot
/dev/mapper/vg_rudipc-var
2.0G 230M 1.7G 12% /var
/dev/mapper/vg_rudipc-home
20G 297M 19G 2% /home
tmpfs 2.0G 1.3M 2.0G 1% /dev/shm
/dev/mapper/vg_rudipc-data
9.9G 151M 9.2G 2% /data

As you can see, /data is still only 10GB, not 20GB as it is on the LVM partition

Now I resize the “/data” partition, using resize2fs

[root@Rudi-PC ~]# resize2fs /dev/vg_rudipc/data
resize2fs 1.41.4 (27-Jan-2009)
Filesystem at /dev/vg_rudipc/data is mounted on /data; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_rudipc/data to 5242880 (4k) blocks.
The filesystem on /dev/vg_rudipc/data is now 5242880 blocks long.

Now, when I check the space, I can see that it’s been resized:

[root@Rudi-PC ~]# df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_rudipc-data
20G 156M 19G 1% /data

Note: I used “df -h /data” to view the size of only the data partition, just to make it easier to process :)

Further reading:

  • http://tldp.org/HOWTO/LVM-HOWTO/
  • http://linux.die.net/man/8/lvm
  • http://www.linux.org/docs/ldp/howto/LVM-HOWTO/lvm2faq.html
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • De.lirio.us
  • email
  • Furl
  • laaik.it
  • LinkedIn
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb
  • Print
  • TwitThis
Tags: , , , , , , , ,

One Response to “How to resize a LVM volume”

You must be logged in to post a comment.