Support > About independent server > How to mount a new hard disk and expand the capacity of a CentOS server
How to mount a new hard disk and expand the capacity of a CentOS server
Time : 2025-06-18 16:54:55
Edit : Jtti

In daily operation and maintenance and enterprise-level application scenarios, as the amount of data continues to grow, the disk capacity of the CentOS server often gradually fails to meet business needs. At this time, adding a new hard disk to the server and completing the mounting and expansion operations have become important tasks to improve storage capacity and ensure the smooth operation of the business.

Before adding a new hard disk to the CentOS server, you should ensure that the following work has been completed: for example, the physical server needs to correctly insert the new hard disk into the disk slot; the cloud server needs to mount the new disk in the console. After the new hard disk is connected, you can use system commands to confirm whether the hard disk is recognized. The newly added hard disk is generally named /dev/sdb, /dev/sdc, etc. Pay attention to distinguish between existing data disks and new hard disks to avoid misoperation.

Partitioning and formatting of new hard disks

Partitioning and formatting of new hard disks must be completed before mounting. The following takes the new hard disk device /dev/sdb as an example.

Create a new partition and use the fdisk tool to partition the hard disk:

fdisk /dev/sdb

Interactive command description:

After the partition is created, the new partition is usually /dev/sdb1.

Format the partition

In order to mount it, you need to format the new partition as a file system. The commonly used file system is ext4:

mkfs.ext4 /dev/sdb1

If you have special needs, you can also choose xfs, ext3 and other file systems.

Mount partition

Create a mount directory, for example:

mkdir /data

Then mount the new partition to that directory:

mount /dev/sdb1 /data

At this point, the new hard disk has been mounted to /data and can be used immediately. However, to ensure that it is automatically mounted at boot, you also need to write the mounting information to /etc/fstab:

echo "/dev/sdb1 /data ext4 defaults 0 0" >> /etc/fstab

You can use mount -a to verify the correctness of the configuration to prevent the system from failing to start normally due to configuration errors.

Expand the capacity of the existing directory (based on logical volumes)

If the server's original disk uses LVM (Logical Volume Management), expansion can be more flexible to directly increase the capacity on the original file system without changing the mount directory.

View the existing volume group information

vgs

Confirm the volume group name (e.g. centos).

Partition the new disk for LVM

Create a physical volume:

pvcreate /dev/sdb1

Add the physical volume to the volume group:

vgextend centos /dev/sdb1

Expand the logical volume

Assuming the logical volume path is /dev/centos/root, you can use the following command to expand the capacity (the example increases 100G):

lvextend -L +100G /dev/centos/root

Or directly allocate all new space to the logical volume:

lvextend -l +100%FREE /dev/centos/root

Extend the file system

For ext4 file system:

resize2fs /dev/centos/root

For xfs file systems:

xfs_growfs /

After completion, you can use df -h to view the expansion effect.

Common precautions

In the process of mounting a new hard disk and expanding the capacity of the CentOS server, the following details are particularly important:

1. Data backup. Before partitioning, expanding, adjusting and mounting the production server, important data should be backed up in advance to prevent data damage due to operational errors or unexpected power outages.

2. Distinguish between physical disks and partitions. During operation, the device path should be confirmed to avoid incorrect partitioning or formatting of existing data disks. You can check it through information such as hard disk capacity and device identification.

3. Carefully check the fstab configuration. When configuring /etc/fstab, ensure that the format, path, and file system type are correct. It is recommended to execute mount -a to verify the configuration immediately after modification to prevent the system from shutting down due to abnormal mounting the next time it starts.

4. Differences in cloud server operations. After mounting a new hard disk on some cloud platforms, you need to complete the hard disk initialization or cloud disk expansion operation in the cloud console before mounting it in the system. The operation process may be slightly different, and you should refer to the official documentation of the platform.

5. LVM expansion is more flexible. If the business has high requirements for storage elasticity, it is recommended to use the LVM architecture during initial deployment to facilitate future expansion at any time.

Mounting new hard disks and expanding capacity on CentOS servers are common and important tasks in daily operation and maintenance work. Whether it is expanding storage space by mounting new directories or dynamically expanding logical volumes based on LVM, operation and maintenance personnel are required to have rigorous operating habits and solid command line skills. Although expansion operations are routine, they must be cautious. It is recommended to back up data and plan expansion plans before each expansion, and operate during off-peak hours to minimize the impact on the business.

Relevant contents

CentOS Server RAID Disk Array Configuration Guide What issues should be paid attention to when building an IPv6 game server How does the Korean dedicated server compare to the Japanese dedicated server? Which is better, Taiwan CN2 server or Hong Kong CN2 server? How much bandwidth should the Japanese short video server choose? What are the specific requirements for AI large model servers? How to choose a server rental provider in California, USA? CDN accelerates the core role of domain names and multi-scenario application resolution What are the coping strategies for the bandwidth resource bottleneck of enterprise servers What are the types of high-frequency CPUs for server rental in 2025?
Go back

24/7/365 support.We work when you work

Support