How to Add a New Disk to an Existing Linux Server

As system administrators, we would have got requirements wherein we need to configure raw hard disks to the existing servers as part of upgrading server capacity or sometimes disk replacement in case of disk failure.

In this article, I will take you through the steps by which we can add the new raw hard disk to an existing Linux server such as RHEL/CentOS or Debian/Ubuntu.

Suggested Read: How to Add a New Disk Larger Than 2TB to An Existing Linux

Important: Please note that the purpose of this article is to show only how to create a new partition and doesn’t include partition extension or any other switches.

I am using fdisk utility to do this configuration.

I have added a hard disk of 20GB capacity to be mounted as a /data partition.

fdisk is a command line utility to view and manage hard disks and partitions on Linux systems.

# fdisk -l

This will list the current partitions and configurations.

Find Linux Partition Details
Find Linux Partition Details

After attaching the hard disk of 20GB capacity, the fdisk -l will give the below output.

# fdisk -l
Find New Partition Details
Find New Partition Details

New disk added is shown as /dev/xvdc. If we are adding physical disk it will show as /dev/sda based of the disk type. Here I used a virtual disk.

To partition a particular hard disk, for example /dev/xvdc.

# fdisk /dev/xvdc

Commonly used fdisk commands.

  • n – Create partition
  • p – print partition table
  • d – delete a partition
  • q – exit without saving the changes
  • w – write the changes and exit.

Here since we are creating a partition use n option.

Create New Partition in Linux
Create New Partition in Linux

Create either primary/extended partitions. By default we can have upto 4 primary partitions.

Create Primary Partition
Create Primary Partition

Give the partition number as desired. Recommended to go for the default value 1.

Assign a Partition Number
Assign a Partition Number

Give the value of the first sector. If it is a new disk, always select default value. If you are creating a second partition on the same disk, we need to add 1 to the last sector of the previous partition.

Assign Sector to Partition
Assign Sector to Partition

Give the value of the last sector or the partition size. Always recommended to give the size of the partition. Always prefix + to avoid value out of range error.

Assign Partition Size
Assign Partition Size

Save the changes and exit.

Save Partition Changes
Save Partition Changes

Now format the disk with mkfs command.

# mkfs.ext4 /dev/xvdc1
Format New Partition
Format New Partition

Once formatting has been completed, now mount the partition as shown below.

# mount /dev/xvdc1 /data

Make an entry in /etc/fstab file for permanent mount at boot time.

/dev/xvdc1	/data	ext4	defaults     0   0
Conclusion

Now you know how to partition a raw disk using fdisk command and mount the same.

We need to be extra cautious while working with the partitions especially when you are editing the configured disks. Please share your feedback and suggestions.

Lakshmi Dhandapani
I work on various platforms including IBM-AIX, Solaris, HP-UX, and storage technologies ONTAP and OneFS and have hands on experience on Oracle Database.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Leave a Reply to Håkan Franzén Cancel reply

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.