An easy way of extending Linux logical volumes

Some vendors like 1and1 deliver Linux servers with pre-configured partitioning scheme with reduced logical volumes. A Logical Volume Manager (LVM) manager is here to help us.

First we need to see if we have an extra space at all by running pvs command on Ubuntu and pvs -av on CentOS (http://www.centos.org/docs/5/html/Cluster_Logical_Volume_Manager/move_ne... recommends runing pvs -o+pv_used, however it did not work on CentOS 5.8)

root@host:~# pvs
PV VG Fmt Attr PSize PFree
/dev/md3 vg00 lvm2 a- 925.91g 913.91g

So on the system in example there was initially 913.91 GB of free space. Now to see actual partitioning scheme on your machine run df -h:

root@host:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/md1 3.7G 431M 3.3G 12% /
none 7.9G 200K 7.9G 1% /dev
none 7.9G 0 7.9G 0% /dev/shm
none 7.9G 50M 7.8G 1% /tmp
none 7.9G 112K 7.9G 1% /var/run
none 7.9G 4.0K 7.9G 1% /var/lock
none 7.9G 0 7.9G 0% /lib/init/rw
/dev/mapper/vg00-usr 4.0G 1.2G 2.9G 30% /usr
/dev/mapper/vg00-var 4.0G 2.3G 1.8G 57% /var
/dev/mapper/vg00-home
4.0G 2.3G 1.8G 57% /home

Now, let's see what is inside that vg00 group by running lvdisplay /dev/vg00:

root@host:~# lvdisplay /dev/vg00
--- Logical volume ---
LV Name /dev/vg00/usr
VG Name vg00
LV UUID IZjw9f-29IB-8Blj-t67B-GdcM-cpu8-1fktoX
LV Write Access read/write
LV Status available
# open 1
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0

--- Logical volume ---
LV Name /dev/vg00/var
VG Name vg00
LV UUID 9q9ulL-Tmos-dowb-xy8b-1pvQ-aIZ2-eLYhz6
LV Write Access read/write
LV Status available
# open 1
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1

--- Logical volume ---
LV Name /dev/vg00/home
VG Name vg00
LV UUID lXpEOW-20Nu-Xt3y-tmLL-1jCK-nVie-0kWTI8
LV Write Access read/write
LV Status available
# open 1
LV Size 4.00 GiB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:2

Now you have to decide which volume you would like to expand. I needed more space on /home volume, so I ran lvextend -L+1G /dev/vg00/home:

lvextend -L+500G /dev/vg00/home
Extending logical volume home to 504.00 GiB
Logical volume home successfully resized

Now that you’ve extended the volume, you’ll have to extend the filesystem:

root@host:~# xfs_growfs /home
meta-data=/dev/mapper/vg00-home isize=256 agcount=504, agsize=262144 blks
= sectsz=512 attr=2
data = bsize=4096 blocks=132120576, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=0
realtime =none extsz=4096 blocks=0, rtextents=0

If running xfs_growfs complains abouth filesystem incompatability:

root@hoste:/# xfs_growfs /
xfs_growfs: / is not a mounted XFS filesystem

then try the following command:

root@host:/# resize2fs /dev/mapper/usr-root
resize2fs 1.41.11 (14-Mar-2010)
Filesystem at /dev/mapper/usr-root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/mapper/usr-root to 5170176 (4k) blocks.
The filesystem on /dev/mapper/usr-root is now 5170176 blocks long.
(http://tldp.org/HOWTO/LVM-HOWTO/extendlv.html)

Finally you can check on for how much space you've expanded your volume and how much space left not used:

root@host:~# pvs
PV VG Fmt Attr PSize PFree
/dev/md3 vg00 lvm2 a- 925.91g 413.91g

That's it, congratulations - now you have expanded /home volume!

Comments

Worked on CentOS 6 on 1&1, THANK YOU for a solution that was concise, clear and simple, after reading lots of verbage elsewhere which was confusing and didn't quite work.

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
To