hello, everyone!
this post i want to introduce you how to mount hard disks in centos(linux), let's see it togther.
Background
The team's CI machine has two hard disks, one is a 256 GB SSD and the other is a 1 TB mechanical hard disk.
The system is installed on an SSD. The 1 TB HDD is idle and needs to be mounted to store some files.
Precautions
/dev/sda and /mnthhd_my mentioned in this article are examples only.
Replace the disk based on the actual situation. Pay special attention to formatting the disk.
Determining a New Hard Drive
Run the fdisk -l command.
If fdisk is used and the capacity of the target disk is 1 TB, the unmounted disk is /dev/sda.
sudo fdisk -l Disk /dev/nvme0n1: 238.5 GiB, 256060514304 bytes, 500118192 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: XXXXXX-C9A1-4D0D-8CF5-XXXXX Device Start End Sectors Size Type /dev/nvme0n1p1 2048 1230847 1228800 600M EFI System /dev/nvme0n1p2 1230848 3327999 2097152 1G Linux filesystem /dev/nvme0n1p3 3328000 500117503 496789504 236.9G Linux LVM Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/mapper/cl-root: 50 GiB, 53687091200 bytes, 104857600 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/cl-swap: 15.7 GiB, 16869490688 bytes, 32948224 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/cl-home: 171.2 GiB, 183798595584 bytes, 358981632 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
(Optional) Run the lsblk command.
You can run the lsblk command in the following situations:
The capacity of the new hard disk is the same as that of the existing hard disk.
Check whether the new hard disk is not mounted.
➜ ~ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 931.5G 0 disk nvme0n1 259:0 0 238.5G 0 disk ├─nvme0n1p1 259:1 0 600M 0 part /boot/efi ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 236.9G 0 part ├─cl-root 253:0 0 50G 0 lvm / ├─cl-swap 253:1 0 15.7G 0 lvm [SWAP] └─cl-home 253:2 0 171.2G 0 lvm /home
as above
The value of MOUNNTPOINT of sda is empty, indicating that the disk is not mounted.
(Optional) Creating a File System
This is actually formatting a new hard disk. This step is dangerous. Make sure that /dev/sda is the correct hard disk.
mkfs -t ext4 /dev/sda
This step is not necessary, but if such a question is required.
wrong fs type, bad option, bad superblock on /dev/sda, missing codepage or helper program, or other error
Perform this step.
Creating a mount point
sudo mkdir /mnthhd_my
In the preceding command, /mnthd_my is not limited and can be another path.
Mounting
sudo mount /dev/sda mnthhd_my
Verifying Mounting
➜ ~ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 931.5G 0 disk /mnthhd_my nvme0n1 259:0 0 238.5G 0 disk ├─nvme0n1p1 259:1 0 600M 0 part /boot/efi ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 236.9G 0 part ├─cl-root 253:0 0 50G 0 lvm / ├─cl-swap 253:1 0 15.7G 0 lvm [SWAP] └─cl-home 253:2 0 171.2G 0 lvm /home
The value of MOUNTPOINT corresponding to sda is changed to /mnthhd_my.
Automatic disk mounting upon startup
The preceding mounting takes effect only when the system is running.
To enable automatic mounting upon system startup, you need to modify it.
Implementation Procedure
Run the cp /etc/fstab /etc/fstab.backup command to back up the existing configuration file.
Run the sudo vim /etc/fstab command to open the configuration file.
Add the mounting configuration /dev/sda /mnthhd_my ext4 defaults 0 2 to the end of the file.
Save File
Run the mount -a command to check whether the fstab configuration is correct.
Restart the server for verification.