Add Disk Storage to VirtualBox on Centos7

Add the Virtual Dirve

  • Open Oracle VM VirtualBox Manager, select the virtual box which we want to add the storage, click Settings
  • Click Storage, Select Drive (Controller: SCSI or Controller: IDE etc.) and click Adds hard disk
  • Follow the instructions to enter all the details, such as disk file location, size etc.

Partition the New Drive and file system

# the new driver assigned to /dev/sdb
ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb

# partition with fdisk
fdisk /dev/sdb
# change: DOS Compatibility flag is not set (command 'c') and Changing display/entry units to sectors (command 'u')
# enter n (new partion) , p(primary partition), 1 (partition number)

ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1

# create a file system
/sbin/mkfs.ext4 -L /data /dev/sdb1

Mount the file system

# create a directory for the mounting
mkdir /data
# mount the drive to the created directory
mount /dev/sdb1 /data
# show all the current mounted systems
mount

Mount the file system automatically

For this to happen, we need to add an entry in /etc/fstab file

vim /etc/fstab
# LABEL=/data     /data   ext4    defaults        1       2


Check mounting


# list all the mounting with UUID
blkid

lsblk -f

lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk
└─sdb1            8:17   0   20G  0 part /data