Linux新磁盘分区并挂载

2025年3月11日 999+浏览

1、查看是否识别到新磁盘

[root@localhost ~]# fdisk -l

2、新硬盘分区

[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

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

命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
分区号 (1-4,默认 1):
起始 扇区 (2048-104857599,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-104857599,默认为 104857599):
将使用默认值 104857599
分区 1 已设置为 Linux 类型,大小设为 50 GiB

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。

3、创建文件系统。

常用的文件系统是 ext4,使用以下命令在刚刚创建的分区(我的是 /dev/sdb1)上创建 ext4 文件系统:

[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13106944 blocks
655347 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2162163712
400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成   

4、创建挂载点、挂载分区

[root@localhost ~]# mkdir /data
[root@localhost ~]# mount /dev/sdb1 /data

5、添加开机自动挂载

[root@localhost ~]# vim /etc/fstab

#在文件末尾添加一行
/dev/sdb1 /data ext4 defaults 0 0

6、刷新分区表

(base) [root@localhost ~]# partprobe

7、查看当前磁盘及挂载信息