zoukankan      html  css  js  c++  java
  • 树莓派/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 ,这是由于本文是在虚拟机上实现的,读写有误,请根据实际查看。

  • 相关阅读:
    双向链表的创建,查找,删除
    atoi 函数自实现
    strcmp,strcpy,strcat,strncmp,strncpy,strncat,自实现精炼版本
    天生棋局(堆上申请二维空间的应用)
    使用二级指针,初始化一级指针
    指针数组的简单理解
    输入二进制数,输出10进制数
    阶乘循环联系题
    [剑指offer] 二叉搜索树的第k个节点
    二叉树的序列化和反序列化
  • 原文地址:https://www.cnblogs.com/Yogile/p/12573326.html
Copyright © 2011-2022 走看看