Mount Hard Disk in Linux
In this article we will be looking at adding a new hard disk to a Linux virtual machine and mount it on a directory. 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.
Start the VM, and now it’s time to create a partition on 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
Format the newly created partition
Once you have created a full partition on the new hard disk, create a directory where you will mount this disk
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 lsblk
Edit /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