Open In App

How to Add New Disk in Linux CentOS 7 Without Rebooting

Improve
Improve
Like Article
Like
Save
Share
Report

Let’s Say we hosted the DataBase on our Server Initially with 500GB given space and as we know  Database should run 24/7 because the user’s using it. One day it consumes space about 400GB only 100GB left Now we want to Increase the Space at the runtime only and In the case of static partitioning we need to restart the server but If we restart the server then our database goes down. So, here the role of the LVM concept comes into play. If you have noticed normally all the Linux flavor OS (except some lightweight) uses the LVM concept for the root folder also so that we are able to increase storage in online mode only.

Understand the Structure of LVM

Here, from this image, you will understand fastly. 

Now, Logically You Can Think Whenever You Wants to Extend the Size of the LV then You can add more size from the volume group and If the VG space is exhausted then add more HDD/EBS then create the PV of its then add those PV to VG so, that VG expands its size.

Steps to Add new disk space to Linux server using VMWare/VirtualBox

  • Goto -> Settings-> Storage

  • Click to Add Hard disk

  • Find the newly added hard disks. You can able to find the newly inserted disk by these commands.
$fdisk -l (List Partitions/Disks)

$lsblk

How we can increase the size of the Root Folder Without Restarting the Server?

Let’s First See the Detail about the mounted disk to the Root folder (/).

$df -h 

Detail about the ubuntu Logical Volume and Volume Group of it.

$ lvdisplay ubuntu-lv 

$ vgdisplay ubuntu-vg

After you added the Extra storage device to your server, create the PV as we know that VG supports the PV only.

$ pvcreate /dev/sdb1 (I have also done the partitioning of /dev/sdb with the help of $fdisk /dev/sdb.)

creating PV

$ pvdisplay (We are displaying here for the complete PV, So we can see the new PV added or not.)

Now, let’s extend the Volume Group with new PV

$ vgextend ubuntu-vg /dev/sdb1

vgextend output

Our VG Size Expanded or Not?

$ vgdisplay ubuntu-vg

Before Increasing the Size of the Same Logical Volume which is attached to the Root Lets see the details of it.

$ lvdisplay /dev/ubuntu-vg/ubuntu-lv

Extend the size of Logical Volume

$ lvextend --size +253G /dev/ubuntu-vg/ubuntu-lv

$ lvdisplay /dev/ubuntu-vg/ubuntu-lv 

As we can see the size of the LV is Increased but if do $df -h still it will so the previous size because we haven’t resize the format Which we are using i.e (ext4) [Most Important that this Resize Command only support format-type i.e ext4]. Only Half Part is formatted but not the complete part. This Command has a feature to formate it on the fly/online (Which means the read/write on that lv is going on).

$  resize2fs /dev/ubuntu-vg/ubuntu-lv (Expanding Space without Rebooting VM)

$ df -h

df -h output


Last Updated : 06 Dec, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads