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:
- First, connect the new hard drive to the computer and make sure it is correctly recognized and installed.
- Use the fdisk -l command to view all disks and partitions in the system.
- 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.
- Press the “n” key at the fdisk command prompt to create a new partition.
- Choose the type of partition you want to create. You can choose between primary partition (p) or logical partition (l).
- Enter the partition number (starting from 1).
- 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.
- Press the ‘t’ key to change the type of partition.
- Please enter the filesystem type code for the partition. Common filesystem type codes include 83 (Linux) and 82 (Linux swap partition).
- Press the ‘w’ key to save and exit fdisk.
- Use the partprobe command to refresh the partition table.
- Run the command mkfs.ext4 /dev/sdX1 to create an ext4 file system (if ext4 is your chosen type).
- Run the command mkdir /mnt/newpartition to create a directory for mounting the new partition.
- Execute the command “mount /dev/sdX1 /mnt/newpartition” to mount the new partition to the newly created directory.
- 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.