If you use a Linux server, you may need to upgrade the server capacity or replace disks. How to add a new disk in Linu?
Creating a new partition can be configured through the fdisk utility, if we need to add a 20GB mount for the /data partition. Fdisk is an imperative utility that can view and manage hard drives and partitions on Linux systems:
# fdisk -l
The result is the current partition and configuration. After connecting the 20GB hard drive, continue to use the command:
fdisk-1
The newly added disk is displayed as /dev/xvdc. If we are adding a physical disk, it will appear /dev/sda based on the disk type. Partition the disk according to the specific disk, for example, /dev/xvdc.
# fdisk /dev/xvdc
Here's how it all fits into one paragraph:
fdisk is a common disk partitioning tool, and its common commands include: n for creating partitions, p for printing partition tables, d for deleting partitions, q for exiting without saving changes, and w for writing changes and exiting. By default, a maximum of four primary partitions can be created for creating partitions or extended partitions. Enter the partition number as required. The recommended default value is 1. Give the first sector value, if it is a new disk use the default value, if the same disk create 2 partitions, add 1 to the last sector of the previous partition.
Gives the value of the last sector or partition size. It is always recommended to give the size of the partition. Always add a prefix + to avoid value out-of-range errors. Save the changes and exit.
Then use the mkfs command to format the disk:
# mkfs.ext4 /dev/xvdc1
Mount the partition after formatting:
# mount /dev/xvdc1 /data
Create an entry in the /etc/fstab file to be mounted permanently at startup.
/dev/xvdc1 /data ext4 defaults 0 0
This is how the fdisk command is used to mount and partition a disk.