top of page

Mount Hard Disk in Linux

In this article we will be looking at mounting external hard drive in Linux onto a directory. This can be achieved by adding a hard disk to virtual machine, formatting the disk and mounting the disk on a specific Linux directory.

Add hard disk virtual-box

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 disk

Start the VM, and now it’s time to create one single partition on the newly added disk

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

# fdisk /dev/xvdb

n                        --> to create new partition
-- hit enter
-- hit enter
-- hit enter
-- hit enter
w                        --> to save newly created partition

Run below command to re-discover partitions without re-booting the server


Format the newly created partition

mkfs.xfs <partition_name>

Mount disk

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

mkdir /u03

List the exact name of the partition using 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 directory

# mount /dev/xvdb01 /u03

Verify the mount is done

df -h
mount -a

Update /etc/fstab file

We want the new hard disk to mount on /u03 even after server restart. To achieve that, we must add entry to /etc/fstab file. First thing, 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 xfs defaults 0 0

Related Posts

Heading 2

Add paragraph text. Click “Edit Text” to customize this theme across your site. You can update and reuse text themes.

bottom of page