Linux extend lvm partition

How to Extend LVM Partition with lvextend Command in Linux

In this post, we will show you how to extend the size of lvm partition in linux with lvextend command on the fly.

Resizing the file system size is an important task of Linux admin’s profile. In Linux , LVM(Logical Volume Manager) provides the facility to increase and reduce the file system size. One of benefit of using lvm partition is that we can increase or decrease its size on the fly without any downtime. It is recommended to have lvm partitions in production Linux or UNIX servers.

Scenario : Suppose we have a LVM partition(/home) and running out of space and want to extend or increase file system size. So, to increase the size of the file system first we must see whether in volume group has free space or not. If the volume group has free space then use the below steps :

Step1) View Disk Usage of File System

Run df command followed by the file system to view total ,used and available disk space

[[email protected] home]# df -h /home/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_cloud-LogVol00 9.7G 9.2G 0 100% /home

As we can see above, /home is 100 % utilized.

Step 2) Check Free Space in Volume Group

To display volume group details, execute the vgdisplay or vgs command followed by volume group name,

[[email protected] home]# vgdisplay vg_cloud --- Volume group --- VG Name vg_cloud System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 27.01 GiB PE Size 4.00 MiB Total PE 6915 Alloc PE / Size 5256 / 20.53 GiB Free PE / Size 1659 / 6.48 GiB VG UUID 1R89GB-mIP2-7Hgu-zEVR-5H02-7GdB-Ufj7R4

Output above confirms that we 6.48 GB free space in the volume group (vg_cloud)

Читайте также:  Find module version linux

Step 3) Increase the size with lvextend Command

Run below lvextend command to extend the file system,

[[email protected] ~]# lvextend -L +2G /dev/mapper/vg_cloud-LogVol00 Extending logical volume LogVol00 to 11.77 GiB Logical volume LogVol00 successfully resized

Above command will extend the file system size by 2GB. You can also specify the size in MB , just replace G with M.

If you want all free space available in volume group to be added to file system then run

[[email protected] ~]# lvextend -l +100%FREE /dev/mapper/vg_cloud-LogVol00

Now, run the resize2fs command to implement above size to file system.

[[email protected] ~]# resize2fs /dev/mapper/vg_cloud-LogVol00

Note: You can also extend the file system size using single lvextnd command by adding -r at end, example is shown below

[[email protected] ~] lvextend -L +2G /dev/mapper/vg_cloud-LogVol00 -r

After running above command, you don’t need to resize2fs command.

Step 4) Verify File system Size after Extension

Re-run the df -h command followed by /home file system, now we can see that file system has been extended by 2 GB, before the extension size was 10 GB

[[email protected] ~]# df -h /home/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_cloud-LogVol00 12G 9.2G 1.9G 84% /home 

That’s all from this post, I hope found it informative. Kindly do post your queries and feedback in below comments sections.

Источник

How to resize a logical volume with 5 simple LVM commands

How to manage logical volumes with 5 simple LVM commands

Have you ever wondered how to extend your root or home directory filesystem partition using LVM? You might have low storage space and you need to increase the capacity of your partitions. This article looks at how to extend storage in Linux using Logical Volume Manager (LVM).

Читайте также:  Разработчик astra linux special edition

Process summary

The process is straightforward. Attach the new storage to the system. Next, create a new Physical Volume (PV) from that storage. Add the PV to the Volume Group (VG) and then extend the Logical Volume (LV).

Look at the picture below. The red line mark shows the original size of the root mount point. The xvdc disk is the new disk attached to it. Extend the root partition to make it 60G in size.

lsblk command displays volume sizes

[ Want to test your sysadmin skills? Take a skills assessment today. ]

Create a Physical Volume

pvcreate command to create a new physical volume

[root@redhat-sysadmin ~]# pvcreate /dev/xvdc Physical volume "/dev/xvdc" successfully created.

When you attach the new storage /dev/xvdc , you need to use the pvcreate command in order for the disk to be initialized and be seen by the Logical Volume Manager (LVM).

Identify the Volume Group

Next, you need to identify the Volume Group (VG) to which you are extending the new disk with the vgs command. Mine is called centos, and that’s the only VG available currently on my LVM.

vgs command displays volume group information

Extend the Volume Group

The vgextend command allows you to add one or more initialized Physical Volumes to an existing VG to extend its size.

As you can see, you want to extend the centos Volume Group.

vgextend command

After extending it, type the vgs or vgdisplay commands for a more detailed overview of the VG.

The vgs command shows only the VG in with a few lines.

vgs command displays volume group information

The vgdisplay shows all the VGs in the LVM and displays the complete information about them.

vgdisplay command displays volume group information

Cloud services

As you can see from the image above, marked with red, you have 10GB free. You can decide to extend all or some amount of storage size to it.

Читайте также:  Linux флешка сохранение изменений

Identify the Logical Volume

The lvs or lvdisplay command shows the Logical Volume associated with a Volume Group. Use the lvs command, and the Logical Volume you’re trying to extend is the root, which belongs to the centos VG. As you can see above, you’ve already extended the VG. Next, extend the Logical Volume.

lvs command displays logical volume information

Extend the Logical Volume

Extend the LV with the lvextend command. The lvextend command allows you to extend the size of the Logical Volume from the Volume Group.

lvextend command displays logical volume information

[root@redhat-sysadmin ~]# lvextend -l +100%FREE /dev/centos/root.

Extend the filesystem

You need to confirm the filesystem type you’re using, Red Hat uses the XFS filesystem, but you can check the filesystem with lsblk -f or df -Th .

Resize the filesystem on the Logical Volume after it has been extended to show the changes. Resize the XFS filesystem by using the xfs_growfs command.

xfs_grow command extends the XFS filesystem

Finally, verify the size of your extended partition.

df -h command displays storage capacity

Wrap up

You can extend any other partition with the steps shown. You just have to ensure you’re using LVM and know the partition you’re extending. If you want to learn more about LVM, check out other articles from Enable Sysadmin by searching LVM.

Источник

Оцените статью
Adblock
detector