Add hard disk to VMware CentOS 7 VM
Tags: vmware, centos, unix
Published: 2018-10-26 16:23:58

---
title: Add hard disk to VMware CentOS 7 VM
published: true
description: Step-by-Step Pictorial guide to add disk space to a CentOS 7 VM hosted on VMware
tags: VMware, CentOS, Unix
cover_image: https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/vmware_hd_centos4.png
---
There are two easy steps to add a hard disk for a VMware CentOS 7 VM. 

1. Assign a new hard disk in VMware vSphere
2. Configure the new hard disk in CentOS


## Assign hard disk in vSphere

1. In VMware vSphere, right click on the VM and select **"Edit Settings..."**
    ![VMware edit settings] (https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/vmware_add_disk1.png)


2. In the **"New device:"** section, select **"SCSI Controller"**, and click the **"OK"** button. Note, there is a hard limit of 4 SCSI Controllers per VM.
    ![VMware SCSI Controller](https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/vmware_add_disk_2.png)


3. Right click **"Edit Settings..."** again and select **"New Hard Disk"**
    ![VMware New Hard Disk](https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/vmware_add_disk_03.png)


4. Input the byte size of the new hard disk (in this example, 5 GB). In the **"Virtual Device Node"** section, assign the new SCSI controller number. Click the **"OK"** button.
    ![VMware Assign SCSI](https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/vmware_add_disk_04.png)


## Configure new hard disk in CentOS

* SSH into the CentOS VM and sudo to root
*sudo su -*
    <p />   
    
    


* List the block device to see the newly assigned vSphere hard disk.
*lsblk* 
    ![CentOS lsblk](https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/centos_add_disk_lsblk.png)
If you do not see the vSphere hard disk, force a rescan
```bash
for host in $(ls -1d /sys/class/scsi_host/*); do echo "- - -" > ${host}/scan ; done
for device in $(ls -1d /sys/class/scsi_disk/*); do echo "1" > ${device}/device/rescan ; done
    
```


* Format the disk partition. Get the device name from the previous *lsblk* output
*fdisk /dev/sdb*
    See the screenshot for the options you should pick
    *n* (new partition)
    *p* (primary)
    *(Press ENTER)* (Use default partition number)
    *(Press ENTER)* (Use default first sector)
    *(Press ENTER)* (Use default last sector)
    
    *t* (change the partition type)
    *8e* (Linux LVM)
    
    *w* (write) 

    ![CentOS fdisk](https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/centos_add_disk_fdisk.png)
    <p />   
    
    


* List the block device again to display the new disk partition /dev/sdb1
    ![CentOS lsblk2](https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/centos_add_disk_lsblk02.png)
    <p />   
    
    

* Initialize the physical volume
*pvcreate /dev/sdb1*
*pvs* (to display the new physical volume)
    ![CentOS pv](https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/centos_add_disk_pv.png)
    <p />   
    
    


* Create the volume group
*vgcreate vgBackup /dev/sdb1* (vgBackup is just an name for this example. The volume group name can be whatever you want)
*vgs* (to display the volume group)
    <p />   
    
    
    

* Create the logical volume for the volume group
*lvcreate -n lvBackup -l +100%FREE vgBackup* (lvBackup is just an name for this example. The logical volume name can be whatever you want)
*lvs* (to display the logical volume)
    ![CentOSlv](https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/centos_add_disk_lv.png)
    <p />   
    
    

* Construct an XFS filesystem on the new logical volume
*mkfs.xfs /dev/vgBackup/lvBackup*
    ![CentOS mkfs](https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/centos_add_disk_mkfs.png)
    <p />    
    
    

    
* Mount a Unix directory to the logical volume
Edit the text file /etc/fstab and add the line below:
**/dev/vgBackup/lvBackup  /backup xfs defaults 1 2**

    *mkdir -p /backup*
    *mount /backup*
    *df -h* (to display the new directory) 
    ![CentOS fstab](https://raw.githubusercontent.com/juttayaya/stackoverflow/master/vmware-disk-img/centos_add_disk_fstab.png)
    <p />



To learn more about Unix Logical Volumes, go to official [RedHat LVM docs](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/lvm_definition)