Add Hard Disk on Linux and Mount on a Directory

While you are practicing Oracle on virtual box, you might need additional hard disk space.

This can be achieved by adding a hard disk to virtual box machine under settings and mounting it on a specific directory.

Add hard disk virtualbox

Shutdown the VM, go to settings, select storage and add new HDD. Give the HDD size as to how much space you want to add.

Format new hard disk

Start the VM, and now it’s time to format the newly added hard disk

# fdisk -l

-- select the name of the newly added hard disk. look at the size

# fdisk /dev/xvdb

-- create a primary partition. enter (p)
-- hit enter
-- hit enter
-- hit enter
-- type w to save newly created partition

Create directory and mount disk

Once you have created a full partition of the hard disk, create a directory where you will mount this disk

mkdir /u03

List the exact name of the partition suing below command

# fdisk -l /dev/xvdb

Generally the partition will always be <disk_name> + 01 for first partition. Example, in our case, the partition name is /dev/xvdb01.

Mount the partition on /u03

# mount /dev/xvdb01 /u03

Verify the mount is done

df -h
lsblk
mount -a
ldblk

Add to /etc/fstab file

Find the UUID of the hard disk

ls -lrt /dev/disk/by-uuid

Copy the UUID from above output for /dev/xvdb disk and add below entry to /etc/fstab file. Make sure to change the UUID as per your server details

vi /etc/fstab

UUID=2a20cd87-f89e-4c59-945f-3700d8d1e08f /u03 ext4 defaults 0 0

Was this article helpful?

Related Articles

Leave a Comment