Linux-磁盘挂载
创始人
2025-06-01 05:02:30
0

1 说明

避免一头雾水,请先看完说明,再看最下面的挂载教程

1.1 挂载流程

START–>查看要挂载的是哪块硬盘–>将硬盘分区–>格式化分区–>设置开机自启(即永久挂载)–>执行挂载命令–>END

1.2 查看当前挂载的磁盘,磁盘剩余的空间

$ df -h

在这里插入图片描述
查看某个文件夹/文件大小可以用这个命令du -sh /usr

1.3 查看分区情况

$ fdisk -l

在这里插入图片描述
当前系统一共存在三块磁盘:sda,sdb,sdc;其中sda已经有两个分区sda1和sda2。也可以使用lsblk命令查看具体的磁盘分区情况
在这里插入图片描述

2 挂载磁盘正文

我们以挂载未分区的vdb到/data目录为例子

2.1 查看分区情况

$ fdisk -l

Disk /dev/vdb: 200 GiB, 214748364800 bytes, 419430400 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.2 设置分区

$ fdisk /dev/vdb

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

2.3 输入m查看帮助(可跳过)

Command (m for help): m

Help:DOS (MBR)a   toggle a bootable flagb   edit nested BSD disklabelc   toggle the dos compatibility flagGenericd   delete a partitionF   list free unpartitioned spacel   list known partition typesn   add a new partitionp   print the partition tablet   change a partition typev   verify the partition tablei   print information about a partitionMiscm   print this menuu   change display/entry unitsx   extra functionality (experts only)ScriptI   load disk layout from sfdisk script fileO   dump disk layout to sfdisk script fileSave & Exitw   write table to disk and exitq   quit without saving changesCreate a new labelg   create a new empty GPT partition tableG   create a new empty SGI (IRIX) partition tableo   create a new empty DOS partition tables   create a new empty Sun partition table

2.4 输入g创建一个空的GPT分区表

Command (m for help): g

Created a new GPT disklabel (GUID: 3B765FDC-74EB-E34E-ADF3-34A6F616C8B6).
The old dos signature will be removed by a write command.

2.5 输入p查看磁盘已被转成GTP分区格式

Command (m for help): p

Disk /dev/sda: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: QEMU HARDDISK   
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: 046CA995-F20A-184D-BA13-D7C144240C87

2.6 输入n 创建分区 默认磁盘序号是1-128

Command (m for help): n

2.7 回车下一步,选择磁盘序号为默认

Partition number (1-128, default 1): 1

2.8 回车下一步,默认第一扇区为默认大小

First sector (2048-1048575966, default 2048):

2.9 回车下一步,默认最后一个扇区为默认大小

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1048575966, default 1048575966):

Created a new partition 1 of type 'Linux filesystem' and of size 500 GiB.
Partition #1 contains a ext4 signature.

2.10 输入yes,删除签名(可能不会出现这步,未出现可忽略)

Do you want to remove the signature? [Y]es/[N]o: yes

The signature will be removed by a write command.

2.11 输入w 保存设置

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

2.12 查看分区情况

$ fdisk -l

Disk /dev/vdb: 200 GiB, 214748364800 bytes, 419430400 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: 1A0C9D01-9A82-402F-B078-73CA4431DFB9#     Start       End   Sectors  Size Type
1   2048 419430366 419428319  200G Linux filesystem

2.13 格式化 vdb1 为ext4类型

$ mkfs.ext4 /dev/vdb1

mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 52428539 4k blocks and 13107200 inodes
Filesystem UUID: a7cf4158-cc23-49bf-81eb-d19882299d67
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

2.14 设置开机启用

2.14.1 查询分区uuid

$ ls -l /dev/disk/by-uuid/

total 0
lrwxrwxrwx 1 root root 10 Dec 14 14:10 5bb40f03-8000-4453-9218-a3cd77897ca0 -> ../../vda1
lrwxrwxrwx 1 root root 10 Dec 14 14:43 a7cf4158-cc23-49bf-81eb-d19882299d67 -> ../../vdb1

2.14.2 设置

$ vi /etc/fstab

UUID=a7cf4158-cc23-49bf-81eb-d19882299d67 /data                   ext4    defaults        0 0

上面是将vdb1挂载到/data目录,如果无此目录,请新建此目录

2.15 挂载分区

$ mount -a

2.16 检查分区挂载情况

$ df -h

相关内容

热门资讯

AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
AWR报告解读 WORKLOAD REPOSITORY PDB report (PDB snapshots) AW...
AWS管理控制台菜单和权限 要在AWS管理控制台中创建菜单和权限,您可以使用AWS Identity and Access Ma...
​ToDesk 远程工具安装及... 目录 前言 ToDesk 优势 ToDesk 下载安装 ToDesk 功能展示 文件传输 设备链接 ...
群晖外网访问终极解决方法:IP... 写在前面的话 受够了群晖的quickconnet的小水管了,急需一个新的解决方法&#x...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
Azure构建流程(Power... 这可能是由于配置错误导致的问题。请检查构建流程任务中的“发布构建制品”步骤,确保正确配置了“Arti...