How to add a new disk to an existing Linux system

Summary: As a system administrator, we have some requirements: As part of upgrading server capacity, or sometimes replacing disks in the event of a disk failure, we need to configure new hard disks to existing servers. In this article, I will walk you through the steps to add a new hard drive to an existing RHEL/CentOS or Debian/Ubuntu Linux system.

As a system administrator, we have some requirements: as part of upgrading server capacity, or sometimes replacing disks in the event of a disk failure, we need to configure new hard disks to existing servers.

In this article, I will walk you through the steps to add a new hard drive to an existing RHEL/CentOS or Debian/Ubuntu Linux system.

Suggested Read: How to Add a New Hard Drive Over 2TB to an Existing Linux.

Important: Please note that the purpose of this article is to show you how to create new partitions, not partition extensions or other options.

I use the fdisk tool to do these configurations.

I have added a 20GB hard drive mounted to the /data partition.

fdisk is a command line tool for displaying and managing hard disks and partitions on Linux systems.

# fdisk -l
This command will list the current partition and configuration.

Viewing Linux Partition Details
Viewing Linux Partition Details

After adding a 20GB hard drive, the output of fdisk -l looks like the following.

# fdisk -l
View new partition details
View new partition details

The newly added disk appears as /dev/xvdc. If we were adding a physical disk, it would appear like /dev/sda based on the disk type. Here I am using a virtual disk.

To partition on a specific hard disk, such as /dev/xvdc.

# fdisk /dev/xvdc
Common fdisk commands.

n - create partition
p - print partition table
d - delete a partition
q - exit without saving changes
w - save changes and exit
Here since we are creating a partition, use the n option.

Create a new partition on Linux Create a new partition
on Linux

Create a primary or extended partition. By default we can have up to 4 primary partitions.

Create Primary Partition
Create Primary Partition

Enter the partition number as required. The default value of 1 is recommended.

Assign Partition Number
Assign Partition Number

Enter the size of the first sector. If it is a new disk, usually choose the 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.

Allocate Sectors
to Partition

Enter a value for the last sector or partition size. The size of the input partition is generally recommended. Always prefix + to prevent value out of range errors.

Allocate partition size
Allocate partition size

Save changes and exit.

Save partition changes
Saving partition changes

Now format the disk using the mkfs command.

# mkfs.ext4 /dev/xvdc1
Formatting the new partition
Formatting the new partition

After formatting is complete, follow the command below to mount the partition.

# mount /dev/xvdc1 /data
Adds an entry in the /etc/fstab file to automatically mount on permanent boot.

/dev/xvdc1 /data ext4 defaults 0 0Summary Now
you know how to create and mount partitions on a new disk using the fdisk command. We need to be extra careful when dealing with partitions, especially when editing configured disks. Please share your feedback and suggestions. The original release time is: 2017-04-27 This article is from Yunqi Community Partner "Linux China"






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326396916&siteId=291194637