Linux-centos first uninstalls and then mounts the simple version of the hard disk - super detailed

1. Detailed version of the hanging disk tutorial:

Linux-centos mount hard disk detailed tutorial - graphic version : https://mp.csdn.net/mp_blog/creation/editor/128508351

2. Uninstall the hard disk tutorial:

Note: Before formatting and uninstalling the hard disk, and deleting any data, please think clearly, please operate with caution! ! ! Here I am a blank test machine, blank data. For testing use only.

1. If you need to unmount the hard disk, first execute the vi /etc/fstab command, enter the configuration file to delete the UUID of the corresponding partition, and wq to exit and save, this is to remove the way of automatically mounting the disk at startup. Please ignore without uninstalling.

Because I have mounted the hard disk in the detailed version of the mounting disk tutorial, so I need to delete it here, and directly attach the steps to uninstall the hard disk for reference.

[root@localhost dell]# vi /etc/fstab

2. Execute lsblk to check the partition status and find the corresponding partition name. You can also use df -h to view, I am used to using lsblk.

3. Execute umount / directory to unmount the mounted disk directory. As shown below

[root@localhost dell]# umount /dev/sdb /data1

 

4. Format the hard disk, not the partitions, because if you format the hard disk, the partitions will be gone, and if you format the partitions, the partitions of the hard disk will still be there. My hard drive is sdb. Finally, execute lsblk to check, and found that the hard disk sdb has no information.

[root@localhost dell]# mkfs -t ext4 /dev/sdb
[root@localhost dell]# mkfs -t ext4 /dev/sdb
mke2fs 1.45.4 (23-Sep-2019)
在 gpt 中发现一个 /dev/sdb 分区表
Proceed anyway? (y,N) y
创建含有 244190646 个块(每块 4k)和 61054976 个inode的文件系统
文件系统UUID:b9f38529-13fd-4081-82f1-98bbf1f81a55
超级块的备份存储于下列块: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848

正在分配组表: 完成                            
正在写入inode表: 完成                            
创建日志(262144 个块)完成
写入超级块和文件系统账户统计信息: 已完成   

[root@localhost dell]# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 931.5G  0 disk 
├─sda1        8:1    0   600M  0 part /boot/efi
├─sda2        8:2    0     1G  0 part /boot
└─sda3        8:3    0 929.9G  0 part 
  ├─cl-root 253:0    0    50G  0 lvm  /
  ├─cl-swap 253:1    0   7.8G  0 lvm  [SWAP]
  └─cl-home 253:2    0 872.2G  0 lvm  /home
sdb           8:16   0 931.5G  0 disk 
sr0          11:0    1  1024M  0 rom

 5. Delete the data1 directory under the previous root:

[root@localhost dell]# cd /
[root@localhost /]# ls
bin  boot  data1  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@localhost /]# rm -rf data1
[root@localhost /]# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@localhost /]#

 2. Mount the hard disk steps:

1. As usual, the first step is to check the name of the unmounted hard disk. here is sdb 

[root@localhost /]# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 931.5G  0 disk 
├─sda1        8:1    0   600M  0 part /boot/efi
├─sda2        8:2    0     1G  0 part /boot
└─sda3        8:3    0 929.9G  0 part 
  ├─cl-root 253:0    0    50G  0 lvm  /
  ├─cl-swap 253:1    0   7.8G  0 lvm  [SWAP]
  └─cl-home 253:2    0 872.2G  0 lvm  /home
sdb           8:16   0 931.5G  0 disk 
sr0          11:0    1  1024M  0 rom

2. Format the unmounted hard disk:

[root@localhost /]# mkfs.ext4 /dev/sdb
mke2fs 1.45.4 (23-Sep-2019)
 /dev/sdb 有一个 ext4 文件系统
	创建于 Sat Dec 31 21:57:25 2022
Proceed anyway? (y,N) y
创建含有 244190646 个块(每块 4k)和 61054976 个inode的文件系统
文件系统UUID:624164c4-4fb8-4d33-914b-a5a9bd630cac
超级块的备份存储于下列块: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848

正在分配组表: 完成                            
正在写入inode表: 完成                            
创建日志(262144 个块)完成
写入超级块和文件系统账户统计信息: 已完成

3. Create a mounted directory, such as the /data directory:

[root@localhost /]# mkdir /data

4. Mount the hard disk to the /data directory:

[root@localhost /]# mount /dev/sdb /data

5. Execute lsblk to check whether the sdb hard disk is mounted in the /data directory:

[root@localhost /]# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 931.5G  0 disk 
├─sda1        8:1    0   600M  0 part /boot/efi
├─sda2        8:2    0     1G  0 part /boot
└─sda3        8:3    0 929.9G  0 part 
  ├─cl-root 253:0    0    50G  0 lvm  /
  ├─cl-swap 253:1    0   7.8G  0 lvm  [SWAP]
  └─cl-home 253:2    0 872.2G  0 lvm  /home
sdb           8:16   0 931.5G  0 disk /data
sr0          11:0    1  1024M  0 rom

6. Set up automatic mounting at startup: Execute the following command and press Enter to enter the configuration file page:

[root@localhost /]# vi /etc/fstab

7. Add configuration files:

#
# /etc/fstab
# Created by anaconda on Fri Dec 30 05:49:31 2022
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root     /                       xfs     defaults        0 0
UUID=4a6fef63-7beb-404b-9aad-6e6d28d13dde /boot                   ext4    defaults        1 2
UUID=2383-9F76          /boot/efi               vfat    umask=0077,shortname=winnt 0 2
/dev/mapper/cl-home     /home                   xfs     defaults        0 0
/dev/mapper/cl-swap     swap                    swap    defaults        0 0
/dev/sdb /data ext4 defaults 0 0
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
~                                                                                                               
:wq

8. Restart: reboot

9. Finally, just check the hard disk mounting status. If you check, it means that the hard disk is automatically mounted after booting. If not, please check the operation steps:

[root@localhost dell]# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 931.5G  0 disk 
├─sda1        8:1    0   600M  0 part /boot/efi
├─sda2        8:2    0     1G  0 part /boot
└─sda3        8:3    0 929.9G  0 part 
  ├─cl-root 253:0    0    50G  0 lvm  /
  ├─cl-swap 253:1    0   7.8G  0 lvm  [SWAP]
  └─cl-home 253:2    0 872.2G  0 lvm  /home
sdb           8:16   0 931.5G  0 disk /data
sr0          11:0    1  1024M  0 rom 

The two articles about hard drives are more suitable for beginners to view and operate, please do not spray them.

 Inappropriate thanks for pointing out

You can private message me if you need anything

The operation is a test machine, and it will be reset after the test

Guess you like

Origin blog.csdn.net/m0_58871083/article/details/128509080