Tuesday, 2 July 2024

How to LVM resize filesystem Guide

 Increase the size of an LVM logical volume - Step-by-step Guide.

Tested on

Debian (Etch, Lenny, Squeeze)
Fedora (14)
Ubuntu (Hardy, Intrepid, Jaunty, Karmic, Lucid, Maverick, Natty)

Objective

To increase the size of an existing LVM logical volume

Background

Be aware that extending a logical volume does not by itself let you to store more files in a filesystem located on that volume. If that is your aim then you will need to:
  1. increase the size of the underlying block device (the logical volume), then
  2. increase the size of the filesystem to fill the block device.
These instructions cover the first step only. The method for the second step will depend on the type of filesystem (and in some cases there will be no practicable method). See below for further information.

Scenario

Suppose that /dev/vg0/foo is a logical volume of size 80GB. You wish to increase its size by 40GB to 120GB.

Method

A logical volume can be extended using the lvextend command. You can specify either the amount by which you want to increase the size of the volume:
lvextend --size +40G /dev/vg0/foo

or the final size that you want to achieve:
lvextend --size 120G /dev/vg0/foo

If successful you should see a response of the form:
Extending logical volume foo to 8.00 GB
Logical volume foo successfully resized

Testing

Verify the new size of the logical volume using the lvdisplay command:
lvdisplay /dev/vg0/foo

This should give a response of the form:
--- Logical volume ---
LV Name /dev/vg0/foo
VG Name vg0
LV UUID w2q9ZN-hKnN-CLGf-6Z5g-e1QZ-DCKX-1DYZvR
LV Write Access read/write
LV Status available
# open 0
LV Size 120.00 GB
Current LE 30720
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:85

You should not at this stage expect to see any increase in the amount of usable space within whatever filesystem located on the logical volume, for example, as reported by the df command: it is only the size of the underlying block device that has been changed.

Next steps

If the logical volume contains a filesystem then you will probably now want to extend it to fill the newly available space. Filesystems that can be extended include ext2, ext3, ext4, jfs, reiserfs and xfs. See:
Some filesystems cannot be extended, either because their design makes this impracticable or because the necessary software has not been written. In that case your only option is to move the files somewhere else, then recreate the filesystem, then move the files back.

Troubleshooting

Alternatives

lvresize

An alternative to lvextend is to use the lvresize command:
lvresize --size +40G /dev/vg0/foo

or:
lvresize --size 120G /dev/vg0/foo

The difference is that lvextend can only increase the size of a volume, whereas lvresize can increase or reduce it. This makes lvresize more powerful but more dangerous. If you accidentally reduce the size of a volume without first reducing the size of the filesystem contained within it then the filesystem is likely to be damaged irreparably. For scenarios similar to the one described here, lvextend is recommended because mistakes of this type are not then possible.

See also

No comments:

Post a Comment

How to check for open ports on Linux

Checking for open ports is among the first steps to secure your device. Listening services may be the entrance for attackers who may exploit...