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

相关内容

热门资讯

前端-session、jwt 目录:   (1)session (2&#x...
linux入门---制作进度条 了解缓冲区 我们首先来看看下面的操作: 我们首先创建了一个文件并在这个文件里面添加了...
关于测试,我发现了哪些新大陆 关于测试 平常也只是听说过一些关于测试的术语,但并没有使用过测试工具。偶然看到编程老师...
前缀和与对数器与二分法 1. 前缀和 假设有一个数组,我们想大量频繁的去访问L到R这个区间的和,...
nodejs:本地安装nvm实... 一、背景-使用不同版本node的原因 vue3+ts、nuxt3版本,node...
JAVA集合知识整理 Java集合知识整理 HashMap相关 HashMap的底层数据结构:jdk1.8之...
无刷直流电机介绍及单片机控制实... 无刷直流电机介绍及单片机控制实例前言基本概念优势与劣势使用寿命基本结构使用单片机控制实例电子调速器&...
fwdiary(2) dp2 1.传纸条  AcWing 275. 传纸条 - AcWing 走两条路,走一条最大的...
常用的DOS命令 常用的DOS命令 DOS(Disk Operating System,磁...
<C++> 类和对象(下) 1.const成员函数将const修饰的“成员函数”称之为const成员函数,cons...