How to add a new hard drive partition in CentOS?

To add a new hard drive partition on CentOS, you can follow the steps below:

  1. First, connect the new hard drive to the computer and make sure it is correctly recognized and installed.
  2. Use the fdisk -l command to view all disks and partitions in the system.
  3. Use the command “fdisk /dev/sdX” to open the newly added hard drive. Replace /dev/sdX with the device name of the new hard drive, such as /dev/sdb.
  4. Press the “n” key at the fdisk command prompt to create a new partition.
  5. Choose the type of partition you want to create. You can choose between primary partition (p) or logical partition (l).
  6. Enter the partition number (starting from 1).
  7. Please input the starting and ending sectors of the partition. Press Enter twice if you want to use the entire hard drive for the partition.
  8. Press the ‘t’ key to change the type of partition.
  9. Please enter the filesystem type code for the partition. Common filesystem type codes include 83 (Linux) and 82 (Linux swap partition).
  10. Press the ‘w’ key to save and exit fdisk.
  11. Use the partprobe command to refresh the partition table.
  12. Run the command mkfs.ext4 /dev/sdX1 to create an ext4 file system (if ext4 is your chosen type).
  13. Run the command mkdir /mnt/newpartition to create a directory for mounting the new partition.
  14. Execute the command “mount /dev/sdX1 /mnt/newpartition” to mount the new partition to the newly created directory.
  15. Run the “df -h” command to verify that the new partition has been successfully mounted.

You have successfully added a new hard drive partition. You can access and use it in the /mnt/newpartition directory.

bannerAds