树莓派/Debian 挂载硬盘

前言

在 Linux 中要使用 Samba 文件协议来实现 NAS 配置,首先要挂载硬盘。本文来简述如何在 Linux 中来挂载硬盘。

格式化

将硬盘插入到主机对应接口。

查看硬盘信息

复制fdisk -l

可以看到插入的硬盘 /dev/sdb1 的文件系统类型为:FAT32 (LBA) 。

格式化硬盘

使用 fdisk 命令对 /dev/sdb1 进行分区

复制fdisk /dev/sdb1

具体过程如下:

复制root@debyogile:/home/yogile# fdisk /dev/sdb1

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

# 删除硬盘原分区
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

# 添加硬盘新分区
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
# 添加分区,默认的分区格式是 primary
Select (default p):

Using default response p.
# 分区号默认 1
Partition number (1-4, default 1):
# 指定分区的起始扇区,一般默认 2048
First sector (2048-62668799, default 2048):
# 指定分区的终止扇区,一般默认最大值
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-62668799, default 62668799):

Created a new partition 1 of type 'Linux' and of size 29.9 GiB.
Partition #1 contains a vfat signature.

# 询问删除签名,确认:y
Do you want to remove the signature? [Y]es/[N]o: y

The signature will be removed by a write command.

# 保存修改
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

复查硬盘信息

复制fdisk -l

可以看到插入的硬盘 /dev/sdb1 的硬盘类型为:Linux 。

格式化文件系统

将硬盘文件系统格式化为 ext4 。

复制mkfs -t ext4 /dev/sdb1

挂载硬盘

临时挂载

要临时挂载硬盘到 /mnt:

复制mount /dev/sdb1 /mnt

查看挂载点:

复制df -h

永久挂载

Debian 使用 UUID 来实现硬盘自动挂载。

  • 通过 blkid 查找所有硬盘的 UUID:

    复制sudo blkid
    

    可以看到挂载的硬盘 /dev/sdb1 的 UUID 为:ad5f412a-0a0c-42af-afd3-eecec6fd96d2 ,TYPE 为:ext4

  • 添加自动挂载点

    复制sudo vim /etc/fstab
    

    在最后一行添加:

    复制UUID=ad5f412a-0a0c-42af-afd3-eecec6fd96d2 /mnt            ext4    defaults 0       0
    
  • 执行挂载

    复制sudo mount -a
    
  • 查看挂载点:

    复制df -h
    

    这时,sudo reboot 重启后挂载点依然存在。

测试挂载

  • 查看硬盘挂载文件夹

    复制cd /mnt
    ls
    

    可以看到默认创建的文件夹 lost+found :

  • hdparm 测试硬盘读写速度

    下载 hdparm

    复制sudo apt install hdparm
    

    测试硬盘读写速度

    复制hdparm -Tt /dev/sdb1
    

    可以看到读取 10948.93 MB/sec ,写入 131.46 MB/sec ,这是由于本文是在虚拟机上实现的,读写有误,请根据实际查看。

作者:Yogile

出处:https://www.cnblogs.com/Yogile/p/12573326.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   Yogile  阅读(8863)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示
more_horiz
keyboard_arrow_up dark_mode palette
选择主题