树莓派(Debian)- 挂载外接硬盘开机自动挂载

Debian 专栏收录该内容
6 篇文章 0 订阅

格式化硬盘为ext4

查看硬盘信息

fdisk -l
Disk /dev/sda: 232.9 GiB, 250059350016 bytes, 488397168 sectors
Disk model: MC4BK           
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 890AECA3-9F22-4C24-B3E1-BD116AB8D340

Device         Start       End   Sectors  Size Type
/dev/sda1         40    409639    409600  200M EFI System
/dev/sda2     409640 390478727 390069088  186G unknown
/dev/sda3  390479872 488396799  97916928 46.7G Microsoft basic data


Disk /dev/sdb: 58.6 GiB, 62930117632 bytes, 122910386 sectors
Disk model: Mass Storage    
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: 0x3da66558

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1  *     2048 122908671 122906624 58.6G 83 Linux
root@raspbian:~# 

可以看到外接的两个硬盘(一个ssd、一个u盘)

以U盘为例

fdisk /dev/sdb1
//sdb1是选择的这个u盘的位置(/dev/sdb1)
root@raspbian:~# 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.

The old ext4 signature will be removed by a write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x4478bacb.

使用d命令删除分区

Command (m for help): d
No partition is defined yet!

 

使用n命令新建分区,一直回车就好

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-122906623, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-122906623, default 122906623): 

Created a new partition 1 of type 'Linux' and of size 58.6 GiB.

 使用w命令保存退出

Command (m for help): w
The partition table has been altered.
Failed to add partition 1 to system: Invalid argument

The kernel still uses the old partitions. The new table will be used at the next reboot. 
Syncing disks.

 新建分区

mkfs -t ext4 /dev/sdb1

 

root@raspbian:~# mkfs -t ext4 /dev/sdb1
mke2fs 1.44.5 (15-Dec-2018)
Found a dos partition table in /dev/sdb1
Proceed anyway? (y,N) y
Creating filesystem with 15363328 4k blocks and 3842048 inodes
Filesystem UUID: 5f8902b9-0008-44e1-9953-d24c61c4fa1d
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done   

root@raspbian:~# 

使用fdisk - l查看一下

fdisk -l
Disk /dev/sdb: 58.6 GiB, 62930117632 bytes, 122910386 sectors
Disk model: Mass Storage    
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: 0x3da66558

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1  *     2048 122908671 122906624 58.6G 83 Linux

挂载硬盘

把U盘的/dev/sdb1挂载到/mnt目录

mount /dev/sdb1 /mnt

 使用df -h 命令查看磁盘信息

root@raspbian:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        59G  7.1G   49G  13% /
devtmpfs        918M     0  918M   0% /dev
tmpfs           950M   12K  950M   1% /dev/shm
tmpfs           950M   17M  933M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           950M     0  950M   0% /sys/fs/cgroup
/dev/mmcblk0p1  252M   71M  181M  29% /boot
tmpfs           190M     0  190M   0% /run/user/0
/dev/sdb1        58G   53M   55G   1% /mnt
root@raspbian:~# 

看到/mnt目录的空间已经是U盘空间大小了

开机自动挂载

vi /etc/fstab 

添加一行

/dev/sdb1 /mnt /ext4 defaults,noatime,nodiratime 0 0

保存退出

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 黑客帝国 设计师:白松林 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值