[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Add disk to CentOS7 using LVM

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

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

(You can easily find it if you search) I will focus on the work that uses fdisk.

 

Change the disk size allocated on vSphere

First, you need to make a quota disk allocation in vSphere.

From the VM settings screen, click Edit settings.

VM settings screen

Select the hard disk item from the left side of the pop-up screen and adjust the provisioned size.

Setting the disk size

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

 

Create a new partition

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

I think it would be a good idea to follow the steps
here to create a partition This page has the same content as this work, so you can use it as a reference, but since the addition to LVM is easy, I would like to write more about it in the next section. .

 

Expand using LVM

When you add a disk for the first time, a partition called /dev/sda3 will probably have been created, so we will choose /dev/sda3 as the partition we want to expand to LVM this time.
This depends on your environment, so please read it accordingly.

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

# 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 item "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, use the vgextend command to extend cl by adding /dev/sda3.

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

 

/dev/sda3 is now added to cl.
However, the available disk space has not increased at this point, so use the lvextend command to expand the logical volume.

Check the logical volume (LV) to be expanded using the lvdisplay command.

# 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 LVs existing on the system will be displayed, so search for the LV you want to increase capacity.
This time, we will try increasing 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 with the -L option.
If you want to expand all VGs registered in LV like this time, use "-l +100%FREE".

Lastly, to expand the file system, in the case of CentOS7, use the xfs_growfs command to expand it.

# 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 the lvmdiskscan command worked.

# 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 target LV for this work, and it seems to be expanding successfully.

The disk addition is now complete.
When you check the free space using the df command,

# df -h File system size Used Remaining Used % Mount position /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

 

You can see that the number is steadily increasing.

 

summary

This time, we added a virtual disk using LVM, but even if this was a physical disk, the work would be the same.
This article is about the work itself, which you can easily find if you search for it, but it's like a warning to myself (maybe I'm getting farsighted...) who couldn't tell the difference between the looks of pvdisplay, vgdisplay, and lvdisplay. It's a thing.

 
That's it.

If you found this article helpful , please give it a like!
0
Loading...
0 votes, average: 0.00 / 10
6,794
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author

Yoichi Bandai

My main job is developing web APIs for social games, but I'm also fortunate to be able to do a lot of other work, including marketing.
Furthermore, my portrait rights in Beyond are treated as CC0 by him.