Skip to content

How To Add a New Disk in CentOS 7

Before Connecting Hard Drive

First of all, we must know how is the structure of CentOS 7 before the installation of the new hardware, for this we must be as root users and execute the following command:

fdisk -l

Once the hard disk is connected, run the same command, fdisk -l. As we can see the new hard drive, 20 GB, is assigned to the path /dev/sdb.

This name will be assigned taking into account the type of disk; if we use a virtual hard drive, it will be /dev/xvdc.

Partition the New Hard Drive in Linux

Once the new hard disk has been identified, the next step will be to partition it:

fdisk /dev/sdb

Common fdisk parameters are:

n: Create a new partition.
p: Print the partition table.
d: Remove a partition.
q: It leaves without saving the changes.
w: Save the changes and exit the command.

With this in mind we will perform the following process once the fdisk /dev/sdb command has been executed:

  • Enter the letter n to create the new partition.
  • Enter the letter p to define what is a primary partition.
  • Number 1 to establish a single partition of the new disk.
  • Establish the value of the first sector which is 2048 by default.
  • Establish the value of the last sector which is by default 41943039.
  • Save the changes using the letter w.

Rerun fdisk -l to look at the changes in the new disk (/dev/sdb) :

Format the New Hard Drive

Format the new hard drive with the desired file system using the command

mkfs (make file system)
mkfs.ext4 /dev/sdb1

Mount the new disk in the desired location, for example /data :

mount /dev/sdb1 /data

Edit the file /etc/fstab to mount partition permanently using the preferred editor and to enter the following line. We keep the changes.

/dev/sdb1 /data ext4 defaults 0 0

In this way, we have added the new hard drive in CentOS 7 and we are ready to take full advantage of it.

Published inLinuxOtherSecurityShell