centos disk partition, format, mount (permanent mount)


foreword

提示:这里可以添加本文要记录的大概内容:
When we add a new hard disk, how to partition, format and mount


提示:以下是本篇文章正文内容,下面案例可供参考

1. Add a hard disk?

——Operate when the virtual machine is shut down,
insert image description here
then continue to the next step, and
finally click OK to
enter the virtual machine to view, and found that there is already
insert image description here

Two, partition

[root@localhost dev]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)
 
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x131cb49f 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n  #分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p   #选择主分区
分区号 (1-4,默认 1):   #默认为1,可自行选择
起始 扇区 (2048-41943039,默认为 2048): #默认即可
将使用默认值 2048
Last 扇区, +扇区 or +size{
    
    K,M,G} (2048-41943039,默认为 41943039)+5G  #可自定义大小

命令(输入 m 获取帮助):p  #查看

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x131cb49f

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux

命令(输入 m 获取帮助):w  #保存并退出
The partition table has been altered!

Calling ioctl() to re-read partition table.

Run lsblk again to check

[root@localhost dev]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk 
└─sdb1            8:17   0    5G  0 part 
sr0              11:0    1  4.5G  0 rom  

If it does not show the use of command synchronization, generally I use it twice

partprobe /dev/sdb #Enter the disk path later

Three: Formatting

format via mkfs

[root@localhost dev]# mkfs  #查看可以格式化的类型
mkfs         mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.minix   mkfs.xfs     
[root@localhost dev]# mkfs.xfs /dev/sdb1   #格式化我们刚刚分区过的硬盘为xfs格式
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

The formatting is complete, and the sdb1 file exists under /dev, and the mounting operation starts

Four: mount

Create a folder, ready to mount the hard disk

[root@localhost dev]# mkdir /media/haha	#创建一个文件夹,准备挂载硬盘
[root@localhost dev]# mount /dev/sdb1 /media/haha/	#挂载
[root@localhost dev]# df 	#可以看到已经挂载上了
文件系统                   1K-块    已用     可用 已用% 挂载点
devtmpfs                10017944       0 10017944    0% /dev
tmpfs                   10029976       0 10029976    0% /dev/shm
tmpfs                   10029976   12004 10017972    1% /run
tmpfs                   10029976       0 10029976    0% /sys/fs/cgroup
/dev/mapper/centos-root 17811456 1290576 16520880    8% /
/dev/sda1                1038336  153512   884824   15% /boot
tmpfs                    2005996       0  2005996    0% /run/user/0
/dev/sdb1                5232640   32992  5199648    1% /media/haha #这个就是我们刚才挂载的操作结果 

The mount here is only temporarily mounted, and it will be gone after restarting. If you want to mount permanently, you need to add some commands to the /etc/fstab file.

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


#
# /etc/fstab
# Created by anaconda on Mon Feb  6 18:31:07 2023
#
# 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
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=a44c986d-8e72-4bb9-82ea-49346de95ab7 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sdb1 /media/haha  #挂载点                  xfs #格式    defaults #权限        0 0  #不自动备份;不自动校验。加快开机

:wq! Save and exit

 [root@localhost dev]# mount -a		#扫描配置文件,挂载配置文件上的硬件。fstab文件修改完成后执行该命令进行挂载。
[root@localhost dev]#  df
文件系统                   1K-块    已用     可用 已用% 挂载点
devtmpfs                10017944       0 10017944    0% /dev
tmpfs                   10029976       0 10029976    0% /dev/shm
tmpfs                   10029976   11972 10018004    1% /run
tmpfs                   10029976       0 10029976    0% /sys/fs/cgroup
/dev/mapper/centos-root 17811456 1290580 16520876    8% /
/dev/sda1                1038336  153512   884824   15% /boot
tmpfs                    2005996       0  2005996    0% /run/user/0
/dev/sdb1                5232640   32992  5199648    1% /media/haha

It's over here, restart and check the mount information again, it also shows that it has been mounted


Summarize

Tip: Here is a summary of the article:
Disk partitioning, formatting, and mounting are often encountered in work, and I hope it can help everyone

Guess you like

Origin blog.csdn.net/LShuo666/article/details/129121683