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定时任务Crontab命令使用详解与总结

    Linux定时任务Crontab命令使用详解与总结

    本为大家介绍了Linux定时任务Crontab命令使用详解并总结Crontab命令的一些使用技巧以及工作中遇到的一些问题解决方法
    2018-10-10
  • Linux正确删除软链接方式

    Linux正确删除软链接方式

    在Linux上删除软链接时,只删除软链接而不要删除源文件,最推荐的做法是使用`rm`命令,其次的做法是使用`unlink`命令,不建议使用`rm-rf`命令,因为它会误删源文件
    2026-01-01
  • Ubuntu 下安装和配置 FTP服务器

    Ubuntu 下安装和配置 FTP服务器

    本篇文章主要介绍了Ubuntu 下安装和配置 FTP服务,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-04-04
  • 浅谈简单使用CentOS7防火墙及开放端口

    浅谈简单使用CentOS7防火墙及开放端口

    这篇文章主要介绍了浅谈简单使用CentOS7防火墙及开放端口,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-09-09
  • Linux中的内核态&用户态使用

    Linux中的内核态&用户态使用

    本文详细介绍了Linux系统内核态与用户态的概念、区别及实现原理,包括特权级、地址空间划分、系统调用机制、页表结构等核心内容,文章通过对比用户态与内核态的特征,以及具体的操作系统实现细节,帮助读者理解Linux系统中这两个重要概念的运行机制和实际应用
    2026-01-01
  • linux下php-fpm开启关闭使用方法

    linux下php-fpm开启关闭使用方法

    自php5.3.3开始,php源码中包含了php-fpm,不需要单独通过补丁的方式安装php-fpm,在源码安装的时候直接 configure 中增加参数 –enable-fpm即可,使用方法如下
    2014-03-03
  • 【Linux】linux常用基本命令总结(推荐)

    【Linux】linux常用基本命令总结(推荐)

    Linux中许多常用命令是必须掌握的,这里将我学linux入门时学的一些常用的基本命令分享给大家一下,有兴趣的可以了解一下。
    2016-11-11
  • Linux系统非正常关机导致磁盘异常的问题及解决

    Linux系统非正常关机导致磁盘异常的问题及解决

    文章介绍了在VMware ESXi虚拟化环境中,由于断电导致的Linux系统非正常关机和磁盘异常问题及其解决方案,主要问题包括文件系统损坏和报错信息,解决方案涉及检查和修复`/etc/fstab`文件中的语法错误,并使用`dmsetup`命令恢复设备映射
    2025-11-11
  • linux系统磁盘存储扩容根目录逻辑卷扩容详解

    linux系统磁盘存储扩容根目录逻辑卷扩容详解

    文章详细介绍了如何将新增磁盘增加到Linux根目录,包括区分逻辑卷和物理卷、查看新增磁盘信息、对新磁盘进行分区和格式化、创建物理卷、扩展卷组、扩展逻辑卷、扩展文件系统以及查看扩容效果
    2026-01-01
  • 浅谈RHEL 7中systemctl 的用法(替代service和chkconfig)

    浅谈RHEL 7中systemctl 的用法(替代service和chkconfig)

    下面小编就为大家带来一篇浅谈RHEL 7中systemctl 的用法(替代service和chkconfig)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-11-11

最新评论