Adding a disk to CentOS7 using LVM

Hello.
I'm Mandai, the Wild team member in charge of development.

The development server I created on vSphere ran out of disk space, so I tried expanding the disk using LVM

This article focuses on what to do using fdisk (as you can find it easily by searching)

 

Change the allocated disk size on vSphere

First, you need to allocate disk space in vSphere

On the VM settings screen, click Edit Settings

VM settings screen

In the pop-up screen, select the hard disk item on the left and adjust the provisioned size

Disk size setting

The virtual machine will be reconfigured, and once complete, the machine will have the new disk attached.
For now, let's restart the VM.

 

Create a new partition

Create a partition on the disk you added in the previous step

create partitionshereby following the instructions
This page covers the same steps as this one, so you can refer to it without any problems, but the part about adding to LVM is explained rather briefly, so I'd like to write about it in more detail in the next section.

 

Expanding using LVM

When you add a disk for the first time, a partition named /dev/sda3 should be created. Therefore, we will assume that the partition we want to extend to LVM is /dev/sda3.
This may vary depending on your environment, so please adjust accordingly.

First, initialize the partition added with the pvcreate command as a physical volume using LVM

# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created

 

Next, use the pvdisplay command to check the volume group (VG) to be added

# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name cl PV Size 15.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 3839 Free PE 0 Allocated PE 3839 PV UUID N2FEPJ-GjMb-D3OM-8sAE-CeHW-SKHu-KdlyWe

 

The field labeled "VG Name" is the name of the VG whose free space you want to increase.
In this example, "cl" is the name of the VG.

Next, add and extend /dev/sda3 to cl with the vgextend command

# vgextend cl /dev/sda3 Volume group "cl" successfully extended

 

This adds /dev/sda3 to cl.
However, the available disk space hasn't increased yet, so we'll extend the logical volume using the lvextend command.

Use the lvdisplay command to check the logical volume (LV) to be expanded

# lvdisplay --- Logical volume --- LV Path /dev/cl/root LV Name root VG Name cl LV UUID yroqAX-k0kh-6NyT-IUaZ-50v3-nZjX-7thw7Y LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-10-05 00:02:04 +0900 LV Status available # open 1 LV Size 13.39 GiB Current LE 3429 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 --- Logical volume --- LV Path /dev/cl/swap LV Name swap VG Name cl LV UUID 0Eh5Ss-mFH1-GVME-rfJl-mGR6-hNed-AtHfxo LV Write Access read/write LV Creation host, time localhost.localdomain, 2017-10-05 00:02:11 +0900 LV Status available # open 2 LV Size 1.60 GiB Current LE 410 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1

 

All existing Level Values ​​(LVs) on the system will be displayed, so find the LV whose capacity you want to increase.
This time, we'll increase the capacity of the LV called "root".

Now let's run the lvextend command again

# lvextend -l +100%FREE /dev/cl/root Size of logical volume cl/root changed from 13.39 GiB (3429 extents) to 97.39 GiB (24932 extents). Logical volume cl/root successfully resized.

 

The lvextend command allows you to specify the size to extend using the -L option.
In this case, to extend all VGs registered in the LV, you would use "-l +100%FREE".

Finally, to expand the file system, in the case of CentOS7, you can use the xfs_growfs command

# xfs_growfs /dev/cl/root meta-data=/dev/mapper/cl-root isize=512 agcount=4, agsize=877824 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=3511296, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 3511296 to 25530368

 

Check if it worked with the lvmdiskscan command

# lvmdiskscan /dev/cl/root [ 97.39 GiB] /dev/sda1 [ 1.00 GiB] /dev/cl/swap [ 1.60 GiB] /dev/sda2 [ 15.00 GiB] LVM physical volume /dev/sda3 [ 84.00 GiB] LVM physical volume 2 disks 1 partition 0 LVM physical volume whole disks 2 LVM physical volumes

 

/dev/cl/root is the LV we are working on this time, and it appears to have been expanded successfully

The disk addition is now complete.
If you check the free space with the df command,

# df -h Filesystem Size Used Remaining Used% Mounted on /dev/mapper/cl-root 98G 14G 85G 14% /devtmpfs 486M 0 486M 0% /dev tmpfs 497M 0 497M 0% /dev/shm tmpfs 497M 6.7M 490M 2% /run tmpfs 497M 0 497M 0% /sys/fs/cgroup /dev/sda1 1014M 139M 876M 14% /boot tmpfs 100M 0 100M 0% /run/user/0 tmpfs 100M 0 100M 0% /run/user/1000

 

As you can see, the number is increasing successfully

 

summary

This time, we added a virtual disk using LVM, but the process would be the same even if it were a physical disk.
This article is a reminder to myself that I couldn't distinguish between the appearances of pvdisplay, vgdisplay, and lvdisplay (maybe my eyesight is getting worse...).

 
That's all

If you found this article helpful,please give it a "Like"!
1
Loading...
1 vote, average: 1.00 / 11
7,343
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author

Yoichi Bandai

My main job is developing web APIs for social games, but thankfully I'm also given the opportunity to work on various other tasks, including marketing.
My image rights within Beyond are treated as CC0.