Using lvresize Command to Change the Size of a Logical Volume (with examples)

Using lvresize Command to Change the Size of a Logical Volume (with examples)

The lvresize command in Linux allows users to change the size of a logical volume. In this article, we will explore eight different use cases of the lvresize command, along with their code examples and explanations.

Use Case 1: Change the size of a logical volume to 120 GB

Code:

lvresize --size 120G volume_group/logical_volume

Motivation: This use case is helpful when we want to resize a logical volume to a specific size, such as increasing its capacity to accommodate more data.

Explanation:

  • --size 120G: Specifies the desired size of the logical volume to be 120 GB.
  • volume_group/logical_volume: Specifies the name of the volume group and the logical volume to be resized.

Example Output:

Logical volume "logical_volume" successfully resized.

Use Case 2: Extend the size of a logical volume and underlying filesystem by 120 GB

Code:

lvresize --size +120G --resizefs volume_group/logical_volume

Motivation: In scenarios where both the logical volume and the filesystem need to be extended, this use case comes in handy. It saves us from the hassle of performing additional steps to resize the filesystem separately.

Explanation:

  • --size +120G: Expands the logical volume by an additional 120GB.
  • --resizefs: Automatically resizes the underlying filesystem to match the new size of the logical volume.
  • volume_group/logical_volume: Specifies the name of the volume group and the logical volume to be resized.

Example Output:

Logical volume "logical_volume" successfully resized.
Filesystem successfully resized.

Use Case 3: Extend the size of a logical volume to 100% of the free physical volume space

Code:

lvresize --size 100%FREE volume_group/logical_volume

Motivation: This use case is beneficial when we want to utilize all the available free space in the physical volume to extend the logical volume to its maximum capacity.

Explanation:

  • --size 100%FREE: Sets the size of the logical volume to be 100% of the free space in the volume group.
  • volume_group/logical_volume: Specifies the name of the volume group and the logical volume to be resized.

Example Output:

Logical volume "logical_volume" successfully resized.

Use Case 4: Reduce the size of a logical volume and underlying filesystem by 120 GB

Code:

lvresize --size -120G --resizefs volume_group/logical_volume

Motivation: In situations where we need to decrease the capacity of a logical volume and simultaneously adjust the size of the underlying filesystem, this use case comes in handy.

Explanation:

  • --size -120G: Shrinks the logical volume by 120GB.
  • --resizefs: Automatically resizes the underlying filesystem to match the new size of the logical volume.
  • volume_group/logical_volume: Specifies the name of the volume group and the logical volume to be resized.

Example Output:

Logical volume "logical_volume" successfully resized.
Filesystem successfully resized.

By utilizing these different use cases of the lvresize command, users can easily manage the size of logical volumes to suit their specific needs. Whether it is expanding or reducing the volume, these examples provide a comprehensive guide to resizing logical volumes effectively.

Related Posts

How to use the command `mount` (with examples)

How to use the command `mount` (with examples)

The mount command is used in Windows to mount Network File System (NFS) network shares.

Read More
How to Use the `git archive` Command (with examples)

How to Use the `git archive` Command (with examples)

Git is a powerful version control system that allows developers to track and manage changes to their codebase.

Read More
How to use the command 'brightness' (with examples)

How to use the command 'brightness' (with examples)

The ‘brightness’ command is used to get and set the brightness level of all internal and certain external displays.

Read More