How to mount a new hard drive to the root directory in CentOS?
To mount a new hard drive to the root directory of CentOS, the following steps need to be followed:
- Firstly, connect the new hard drive to the computer and boot up the CentOS system.
- Open the terminal or console.
- Run the following command to view the list of recognized hard drives in the system:
- List all available disks and their partitions.
- All connected hard drives and partitions will be displayed in the list.
- The device name for a new hard drive is typically displayed in the format /dev/sdX (for example, /dev/sdb).
- Run the following command to create a new partition:
- Partitioning the device /dev/sdX with fdisk.
- Please replace /dev/sdX with the name of your hard drive device.
- In the fdisk command line interface, press “n” to create a new partition, and then follow the prompts to set up the partition, including selecting the partition type, starting and ending positions, etc. By default, choose primary partition (p) and the default partition number (1).
- Use the following command to format a new partition as an EXT4 file system:
- Format the device /dev/sdX1 with the ext4 file system.
- Please replace /dev/sdX1 with the name of your new partition device.
- Create a directory to use as a mounting point.
- Create a new directory called “new_disk” in the /mnt directory.
- You can choose another directory to use as a mount point, but /mnt is a common directory used for mounting.
- Run the following command to mount the new partition to the mount point:
- Mount the new disk on /mnt/new_disk from /dev/sdX1.
- Please replace /dev/sdX1 with the name of your new partition device.
- Currently, the new hard drive has been successfully mounted to the root directory.
- If you want to automatically mount the hard drive at every system startup, you can edit the /etc/fstab file and add the following line:
- Mount the ext4 filesystem on /dev/sdX1 to /mnt/new_disk with default settings.
- Please replace /dev/sdX1 with the name of your new partition device.
- Therefore, the new hard drive will be automatically mounted to the root directory during system startup.
- Finally, verify if the new hard drive has been successfully mounted by running the following command:
- Show disk usage in a human-readable format.
- You should be able to see the mounting point of the new hard drive in the output.