# Add hard disk to VMware Linux VM

There are two easy steps to add a hard disk for a VMware Linux VM.

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

This example assigns a new 5 GB hard disk as the `/backup` directory on CentOS 7

## **Assign hard disk in vSphere**

1.  In VMware vSphere, right click on the VM and select **"Edit Settings..."**
    
    ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/336c55cd-cc38-48ee-9739-ca126a1409c8.webp align="center")
    
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.
    
    ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/5f3676d0-ee96-4428-957d-7c6a5fa23d33.webp align="center")
    
3.  Right click **"Edit Settings..."** again and select **"New Hard Disk"**
    
    ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/a604baf0-a0e1-465a-a471-50332ee75ede.webp align="center")
    
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.
    
    ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/acc3fbef-44fd-4e2d-8149-5e2a275ea0f1.webp align="center")
    

## **Configure new hard disk in CentOS**

1.  SSH into the CentOS VM and sudo to root  
    `sudo su -`
    
2.  List the block device to see the newly assigned vSphere hard disk.  
    `lsblk`  
    
    ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/c60f5aaa-fa3c-4717-b623-48616bce19e9.webp align="center")
    
    If you do not see the vSphere hard disk, force a rescan
    
    ```shell
    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
    ```
    

3.  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)*
    
    ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/6ea93cef-06ae-420f-b064-8482ae535531.webp align="left")
    

4.  List the block device again to display the new disk partition /dev/sdb1  
    `lsblk`
    
    ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/2b4fe6d3-03f4-4b15-97d5-37c19eb60c0c.webp align="left")
    
5.  Initialize the physical volume  
    `pvcreate /dev/sdb1`  
    *T*o display the new physical volume  
    `pvs`
    
    ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/27e18c16-daed-4364-9354-e06bef4c01a8.webp align="left")
    
6.  Create the volume group  
    Note: vgBackup is just an name for this example. The volume group name can be whatever you want  
    `vgcreate vgBackup /dev/sdb1`  
    To display the volume group  
    `vgs`
    
7.  Create the logical volume for the volume group  
    Note: lvBackup is just an name for this example. The logical volume name can be whatever you want  
    `lvcreate -n lvBackup -l +100%FREE vgBackup`  
    To display the logical volume  
    `lvs`
    
    ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/b1de7bb2-6c45-4597-b02a-e4c44a542525.webp align="center")
    
8.  Construct an XFS filesystem on the new logical volume  
    `mkfs.xfs /dev/vgBackup/lvBackup`  
    
    ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/f4234b3b-f600-4af9-bb60-4bd5992d8261.webp align="center")
    
      
    
9.  Edit the text file **/etc/fstab** and add the line below:
    
    ```plaintext
    /dev/vgBackup/lvBakup /backup xfs defaults 1 2
    ```
    
10.  Mount a Unix directory to the logical volume  
     `mkdir -p /backup`  
     `mount /backup`
     

11.  You now have a new 5 GB hard disk assigned as the `/backup` directory
     
     ![](https://cdn.hashnode.com/uploads/covers/69c85d2b7cf270651076d644/bfccc567-b487-4636-8473-08bccf6e2af9.webp align="center")
     

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)
