Add Disk to CentOS 7
Sometimes it is required to add additional disk space to Virtual Machines. This is relatively straight forward from the hypervisor level. However the process for recognising and utilising that space will differ depending on the OS. In this article I show the steps I have used in order to use a new hard disk that I have already added via vCenter to a Cent OS 7 VM.
Process
First we can run the below command to check the size of our attached disk.
lsblk
Partition the disk
In the above case the disk is listed as sdb. I can now go ahead and partition this new drive. Ensure that you are partitioning the correct drive:
fdisk /dev/sdb
There are many parameters that can be used within fdisk. Below I listed out the procedure I used after running the command above.
- Press n to create the new partition
- Press p to define that this will be a primary partition
- Press 1 to establish a single partition
- Establish the value of the first sector which is 2048 by default
- Establish the value of the last sector which by default will be 41943039
- Save all the changes by pressing w
Once the partitioning has finished we can check the disk and partitions by running
fdisk -l
Format the new drive
The next step is to format the new hard drive with the desired file system using the command
mkfs.ext4 /dev/sdb1
Now we can mount the newly formatted disk. In my case I want to mount it to a new directory called data
Mkdir /data Mount /dev/sdb1 /data
In order to make the mount permanent I need to edit the fstab file. Firstly though I need to change the permissions on that file.
chmod 644 /etc/fstab
Now I can edit fstab
Sudo vi /etc/fstab
Within the file need to add the below line
/dev/sdb1/data ext4 defaults 0 0