Introduction:
As your Linux server grows and your data storage needs increase, you may find yourself running out of disk space. In such cases, it becomes necessary to extend the disk space to accommodate your growing needs. One way to achieve this is by using Logical Volume Management (LVM) on your Linux server. In this article, we will guide you through the process of extending disk space with LVM on your Linux server.
Prerequisites:
Before we begin, please ensure that you have the following:
- A Linux server with LVM installed
- Root access or sudo privileges
Step 1: Check Current Disk Space Usage
The first step is to check the current disk space usage on your server. This will help you determine how much space you need to extend. To do this, open a terminal and run the following command:
df -h
This command will display a list of all mounted filesystems along with their disk usage information. Take note of the filesystem that you want to extend.
Step 2: Create a New Partition
Next, we need to create a new partition on the available disk space. To do this, follow these steps:
- Identify the disk that has available space by running the command:
fdisk -l
This command will display a list of all disks on your server. Identify the disk with available space and take note of its name (e.g., /dev/sdb).
- Run the following command to start the partitioning process:
fdisk /dev/sdb
Replace /dev/sdb with the name of the disk you identified in the previous step.
- Inside the fdisk utility, press "n" to create a new partition.
- Choose the partition type (primary or extended) by pressing "p" or "e" respectively.
- Specify the partition number and press Enter to use the default values.
- Choose the partition size by specifying the desired value or pressing Enter to use the default value (to use the entire available space).
- Press "w" to write the changes and exit the fdisk utility.
Step 3: Create a Physical Volume
Now that we have a new partition, we need to create a physical volume on it. Follow these steps:
- Run the following command to create a physical volume:
pvcreate /dev/sdb1
Replace /dev/sdb1 with the name of the partition you created in the previous step.
- Verify the creation of the physical volume by running the command:
pvs
This command will display a list of all physical volumes on your server. Make sure that the newly created physical volume is listed.
Step 4: Extend the Volume Group
Next, we need to extend the volume group to include the new physical volume. Follow these steps:
- Run the following command to extend the volume group:
vgextend existing_volume_group_name /dev/sdb1
Replace existing_volume_group_name with the name of the volume group that contains the filesystem you want to extend. Replace /dev/sdb1 with the name of the physical volume you created in the previous step.
- Verify the extension of the volume group by running the command:
vgs
This command will display a list of all volume groups on your server. Make sure that the volume group you extended is listed with the new physical volume included.
Step 5: Extend the Logical Volume
Finally, we can extend the logical volume to utilize the additional space. Follow these steps:
- Run the following command to extend the logical volume:
lvextend -r -l +100%FREE existing_logical_volume_path
Replace existing_logical_volume_path with the path of the logical volume you want to extend (e.g., /dev/myvg/mylv).
The -r option tells the lvextend command to resize the filesystem on the logical volume as well.
- Verify the extension of the logical volume by running the command:
lvs
This command will display a list of all logical volumes on your server. Make sure that the logical volume you extended shows the increased size.
Conclusion:
Congratulations! You have successfully extended the disk space with LVM on your Linux server. You can now enjoy the additional storage capacity for your data. Remember to always monitor your disk usage and extend it as needed to avoid running out of space.
| No. | Source |
|---|---|
| 1 | https://linux.die.net/man/8/fdisk |
| 2 | https://linux.die.net/man/8/pvcreate |
| 3 | https://linux.die.net/man/8/vgextend |
| 4 | https://linux.die.net/man/8/lvextend |