ubuntu磁盘分区、格式化、挂载方式

 更新时间:2026年02月09日 08:50:31   作者:立昂  
文章介绍了如何查看设备、进行分区、格式化和挂载磁盘的步骤,以及可能遇到的问题和解决方案

一、查看设备

1、列出系统上的所有块设备:sudo fdisk -l

xxx@xxx:~$ sudo fdisk -l
Disk /dev/ram0: 8 MiB, 8388608 bytes, 16384 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/ram1: 8 MiB, 8388608 bytes, 16384 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/ram2: 8 MiB, 8388608 bytes, 16384 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/ram3: 8 MiB, 8388608 bytes, 16384 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/ram4: 8 MiB, 8388608 bytes, 16384 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/ram5: 8 MiB, 8388608 bytes, 16384 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/ram6: 8 MiB, 8388608 bytes, 16384 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/ram7: 8 MiB, 8388608 bytes, 16384 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/ram8: 8 MiB, 8388608 bytes, 16384 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/ram9: 8 MiB, 8388608 bytes, 16384 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/ram10: 8 MiB, 8388608 bytes, 16384 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/ram11: 8 MiB, 8388608 bytes, 16384 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/ram12: 8 MiB, 8388608 bytes, 16384 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/ram13: 8 MiB, 8388608 bytes, 16384 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/ram14: 8 MiB, 8388608 bytes, 16384 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/ram15: 8 MiB, 8388608 bytes, 16384 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/loop0: 16 MiB, 16777216 bytes, 32768 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: dos
Disk identifier: 0x00000000


Disk /dev/mtdblock0: 4 MiB, 4194304 bytes, 8192 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


GPT PMBR size mismatch (26769407 != 244023295) will be corrected by w(rite).
Disk /dev/mmcblk0: 116.4 GiB, 124939927552 bytes, 244023296 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: 2D215E13-695C-4DAB-B877-B01320240ACB

Device          Start      End  Sectors  Size Type
/dev/mmcblk0p1  28672 61067263 61038592 29.1G Linux filesystem
/dev/mmcblk0p2   2048     2303      256  128K Linux filesystem
/dev/mmcblk0p3   4096     4991      896  448K Linux filesystem
/dev/mmcblk0p4   6144     7295     1152  576K Linux filesystem
/dev/mmcblk0p5   8192     8319      128   64K Linux filesystem
/dev/mmcblk0p6  10240    10623      384  192K Linux filesystem
/dev/mmcblk0p7  12288    13055      768  384K Linux filesystem
/dev/mmcblk0p8  14336    14463      128   64K Linux filesystem
/dev/mmcblk0p9  16384    17279      896  448K Linux filesystem
/dev/mmcblk0p10 18432    19327      896  448K Linux filesystem
/dev/mmcblk0p11 20480    22015     1536  768K Linux filesystem
/dev/mmcblk0p12 22528    22655      128   64K Linux filesystem
/dev/mmcblk0p13 24576    24959      384  192K Linux filesystem
/dev/mmcblk0p14 26624    26879      256  128K Linux filesystem

Partition table entries are not in disk order.


Disk /dev/zram0: 2 GiB, 2078359552 bytes, 507412 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/zram1: 2 GiB, 2078359552 bytes, 507412 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/zram2: 2 GiB, 2078359552 bytes, 507412 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/zram3: 2 GiB, 2078359552 bytes, 507412 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

可以看到磁盘/dev/mmcblk0中还有剩余的空间未被分区。

2、打开需要进行分区的磁盘进行分区操作:sudo fdisk /dev/sdX

xxx@xxx:~$ sudo fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

GPT PMBR size mismatch (26769407 != 244023295) will be corrected by w(rite).
GPT PMBR size mismatch (26769407 != 244023295) will be corrected by w(rite).

Command (m for help): e
e: unknown command

Command (m for help): m

Help:

  Generic
   d   delete a partition
   F   list free unpartitioned space  # 列出空闲的未分区的空间
   l   list known partition types
   n   add a new partition  # 增加一个新的分区
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): F

Unpartitioned space /dev/mmcblk0: 87.2 GiB, 93673471488 bytes, 182955999 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

   Start       End   Sectors  Size
61067264 244023262 182955999 87.2G

Command (m for help): n
Partition number (15-128, default 15): 15
First sector (61067264-244023262, default 61067264): 
Last sector, +sectors or +size{K,M,G,T,P} (61067264-244023262, default 244023262): 

Created a new partition 15 of type 'Linux filesystem' and of size 87.2 GiB.

Command (m for help): F
Unpartitioned space /dev/mmcblk0: 0 B, 0 bytes, 0 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

Command (m for help): w
GPT PMBR size mismatch (26769407 != 244023295) will be corrected by w(rite).

The partition table has been altered.
Syncing disks.

二、格式化

1、挂载可能会遇到的格式问题

xxx@jxxx:~$ sudo mount /dev/mmcblk0p15 /home/xxx/node
NTFS signature is missing.
Failed to mount '/dev/mmcblk0p15': Invalid argument
The device '/dev/mmcblk0p15' doesn't seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?

xxx@jxxx:~$ sudo fdisk -l /dev/mmcblk0p15
Disk /dev/mmcblk0p15: 87.2 GiB, 93673471488 bytes, 182955999 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

2、格式化

xxx@jxxx:~$ 
xxx@jxxx:~$ 
xxx@jxxx:~$ sudo mkfs.ntfs /dev/mmcblk0p15
Cluster size has been automatically set to 4096 bytes.
Initializing device with zeroes:  26%
                                                                                                                                                                                                             61%
                                                                                                                                                                                                                                                    100% - Done.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.

三、挂载

xxx@xxx:~$ sudo mount /dev/mmcblk0p15 /home/xxx/node

开机挂载

xxx@xxx:~$ sudo vim /etc/fstab
# <file system> <mount point>             <type>          <options>                               <dump> <pass>
/dev/root            /                     ext4           defaults                                     0 1
/dev/mmcblk0p15  /home/rushi/node          ntfs           defaults                                   0 0

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • linux系统获取硬盘使用信息

    linux系统获取硬盘使用信息

    linux查看硬盘信息要用的几个命令:df命令、du命令、statfs结构及函数,这里用图文说明一下使用方法。
    2013-10-10
  • Apache Shiro 使用手册(五) Shiro 配置说明

    Apache Shiro 使用手册(五) Shiro 配置说明

    这篇文章主要为大家分享了Apache Shiro 配置说明,需要的朋友可以参考下
    2014-06-06
  • 在Apache服务器上启用GZip压缩静态内容的方法

    在Apache服务器上启用GZip压缩静态内容的方法

    这篇文章主要介绍了在Apache服务器上启用GZip压缩静态内容的方法,通过配置.htaccess文件即可轻松实现,同时附带了一些GZip的常用命令,需要的朋友可以参考下
    2015-08-08
  • Linux删除文件不同方法效率对比

    Linux删除文件不同方法效率对比

    这篇文章主要介绍了Linux删除文件不同方法效率对比,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-08-08
  • Linux进程排查实战之strace和lsof命令使用指南

    Linux进程排查实战之strace和lsof命令使用指南

    这篇文章主要为大家详细介绍了Linux进程排查实战之strace和lsof命令使用的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下
    2025-12-12
  • Linux中让alias设置永久生效的方法详解

    Linux中让alias设置永久生效的方法详解

    在Linux中为我们提供了一个很方便的重命名命令 alias ,它的作用为如果要执行命令太长又不符合用户的习惯,那么我们可以为它指定一个别名。下面这篇文章主要给大家介绍了关于Linux中让alias设置永久生效的相关资料,需要的朋友可以参考下。
    2017-12-12
  • 在centos 7中安装配置k8s集群的步骤详解

    在centos 7中安装配置k8s集群的步骤详解

    这篇文章主要给大家介绍了关于在centos 7中安装配置k8s集群的步骤,文中通过示例代码将步骤介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习下吧。
    2017-09-09
  • Apache服务的主要目录和配置文件详解

    Apache服务的主要目录和配置文件详解

    这篇文章主要介绍了Apache服务的主要目录和配置文件详解,需要的朋友可以参考下
    2017-05-05
  • Linux下使用使用socket实现TCP服务端的示例代码

    Linux下使用使用socket实现TCP服务端的示例代码

    套接字(socket)是 Linux 下的一种进程间通信机制(socket IPC),它不仅支持同一主机的不同进程间通信,还支持跨网络的不同主机的进程间通信,本文介绍了 Linux 下使用 socket 接口实现 TCP 服务端的示例程序,需要的朋友可以参考下
    2024-03-03
  • Linux运维之磁盘分区与挂载详解

    Linux运维之磁盘分区与挂载详解

    磁盘分区是将物理硬盘划分为不同的逻辑部分,每个分区都可以被视为一个独立的存储设备,这篇文章主要介绍了Linux系统中的磁盘分区原理以及如何创建、格式化、临时和永久挂载分区的相关内容,有需要的小伙伴可以了解下
    2025-12-12

最新评论