Linux 创建磁盘分区以及挂载磁盘-详解(图文)

命令

查看磁盘使用情况命令:

# 查看系统分区
fdisk -l 
# 查看硬盘分区
fdisk 路径

查看所有可用的块设备信息,并显示他们之间的依赖关系。

lsblk

我这里是已经挂载好了 

确定分区文件系统类型

blkid    目录路径

使用fdisk 创建分区
[root@localhost ~]# fdisk /dev/sdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

命令(输入 m 获取帮助):m
命令操作
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)


Command (m for help): n  #添加新分区
Partition number (1-128, default 1): 1  #输入分区号,默认1,按下enter 接受默认值
First sector (34-11252048526, default 2048): #输入分区的起始扇区,默认值为2048,按下enter 接受默认值
# 输入分区的结束分区,这里是3T可以根据自己的需要加入,可以使用+前缀来指定大小,单位可以是K(千字节)、M(兆字节)、G(千兆字节)、T(TB)、P(PB)
Last sector, +sectors or +size{K,M,G,T,P} (2048-11252048526, default 11252048526): 6442450944    --3T
Created partition 1 #已成功创建了第一个分区


Command (m for help): w  #将表写入磁盘并退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

查看分区

挂载目录

首先要确保 挂载点已经存在,如果不存在就创建

sudo mkdir -p /mnt/hdd1 /mnt/hdd2

挂载命令

可以使用 mount 命令将分区挂载到相应的挂载点:

sudo mount /dev/sda1 /mnt/hdd1
sudo mount /dev/sda2 /mnt/hdd2

编辑 /etc/fstab 文件以实现自动挂载,在编辑之前,您可以通过 blkid 命令获取分区的 UUID(Universally Unique Identifier),以确保正确地将其添加到 /etc/fstab

sudo blkid /dev/sda1
sudo blkid /dev/sda2

然后 vim /etc/fstab  编辑此文件,添加以下行

UUID=分区1的UUID /mnt/hdd1 分区1的文件系统类型 defaults 0 2
UUID=分区2的UUID /mnt/hdd2 分区2的文件系统类型 defaults 0 2

完成后,保存并退出编辑器,然后使用命令重新加载 /etc/fstab 文件以应用更改

sudo mount -a

现在,系统应该会在启动时自动挂载这两个分区到指定的挂载点 /mnt/hdd1/mnt/hdd2

注意:

图片中的 Type 可不是 文件系统类型 

最后使用 lsblk 查看

注意:

在物理服务器上添加 内存条后,我的这个挂载点就掉了,不清楚是不是这个原因,如果有读者知道可以在评论区评论,大家一起进步

相关推荐

  1. Linux 磁盘分区详解以及知识点分解

    2024-04-23 15:58:01       18 阅读
  2. Linux磁盘挂载

    2024-04-23 15:58:01       7 阅读
  3. Linux 设置自动挂载磁盘

    2024-04-23 15:58:01       33 阅读
  4. Linux磁盘分区

    2024-04-23 15:58:01       34 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-23 15:58:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-23 15:58:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-23 15:58:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-23 15:58:01       20 阅读

热门阅读

  1. PySide6之QEasingCurve.Type

    2024-04-23 15:58:01       14 阅读
  2. Swift常用的第三方库

    2024-04-23 15:58:01       15 阅读
  3. 工作后的自我介绍

    2024-04-23 15:58:01       12 阅读
  4. ATFX:注册邀请码怎么弄?

    2024-04-23 15:58:01       15 阅读
  5. 大数据——Scala 模式匹配

    2024-04-23 15:58:01       11 阅读
  6. 第4章:GO的错误处理机制

    2024-04-23 15:58:01       10 阅读
  7. 在 C 中打印字符串 - 如何在 C 中打印字符串

    2024-04-23 15:58:01       15 阅读
  8. Postgresql数据库高级sql总结3

    2024-04-23 15:58:01       11 阅读
  9. oracle sql 示例

    2024-04-23 15:58:01       11 阅读