How can I add a hard drive and expand the root partition on CentOS?

To add a hard drive and expand it to the root partition in a CentOS system, follow these steps:

  1. Firstly, insert the new hard drive into the server, and use the following command to view the disk device information:
lsblk

Find the name of the newly added hard drive device, such as /dev/sdb.

  1. Partition and format the new hard drive using the following command.
fdisk /dev/sdb

Type in ‘n’ to create a new partition, choose the default option to create the new partition. Then type in ‘w’ to save the changes and exit.

  1. Format the new partition.
mkfs.ext4 /dev/sdb1
  1. Mount a new partition to a temporary directory.
mkdir /mnt/newdisk
mount /dev/sdb1 /mnt/newdisk
  1. Copy the root partition to a new partition.
rsync -avx / /mnt/newdisk
  1. The file located at /etc/fstab
/dev/sdb1 /           ext4    defaults        1 1
  1. Remount the root partition:
umount /
mount -a
  1. Use the following command to check if the root partition has been resized:
df -h

Please make sure to back up important data before proceeding with the above operations to prevent any unexpected situations.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds