Linux(Debian)磁盘挂载
场景
双系统 win上有一个机械硬盘 要共享给linux作为smb目录使用
准备工作
- media 目录初识 linux 系统会自动识别一些设备,例如U盘、光驱等等,当识别后,Linux 会把识别的设备挂载到这个目录下
- 创建挂载目录 /media/[要挂载的文件夹名]
sudo mkdir /media/smb
- 发现未挂载的硬盘
sudo fdisk -l
sout
Disk /dev/nvme0n1: 953.87 GiB, 1024209543168 bytes, 2000409264 sectors
Disk model: ZHITAI TiPlus7100 1TB
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: 3BAA79F0-3A67-4F4E-BEB5-A016E28FBF14
Device Start End Sectors Size Type
/dev/nvme0n1p1 40 8388647 8388608 4G EFI System
/dev/nvme0n1p2 8388648 8421415 32768 16M Microsoft reserved
/dev/nvme0n1p3 8421416 525172735 516751320 246.4G Microsoft basic data
/dev/nvme0n1p4 525172736 2000407182 1475234447 703.4G Microsoft basic data
Disk /dev/nvme1n1: 953.87 GiB, 1024209543168 bytes, 2000409264 sectors
Disk model: GLOWAY YCT1TNVMe-M.2/80
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: FCDEE9A1-85B0-4335-83D0-313797A4F598
Device Start End Sectors Size Type
/dev/nvme1n1p1 2048 2000408575 2000406528 953.9G Linux filesystem
Disk /dev/sda: 3.64 TiB, 4000787030016 bytes, 7814037168 sectors
Disk model: WDC WD40EZAX-00C
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: D1D4B812-1377-4396-96D4-01E681403215
Device Start End Sectors Size Type
/dev/sda1 34 32767 32734 16M Microsoft reserved
/dev/sda2 32768 7814033407 7814000640 3.6T Microsoft basic data
硬盘信息很全 可以看到我们本次要挂载的机械硬盘就是 : Disk /dev/sda: 3.64 TiB 微软有默认的分区通过大小不看出 /dev/sda2 是我们双系统要共享过来的资源分区记住他接下来我们会用到
- 查找对应分区的uuid
sudo blkid /dev/sda2
sout
/dev/sda2: LABEL="M-fM-^VM-0M-eM-^JM- M-eM-^MM-7" BLOCK_SIZE="512" UUID="365249EC5249B203" TYPE="ntfs" PARTLABEL="Basic data partition" PARTUUID="57cba059-d9c0-4d57-816c-16c4091cdc8a"
这里的关键信息有 TYPE ntfs 代表磁盘格式 UUID 365249EC5249B203 这个就是这个分区的系统坐标 一会挂载时使用
- 修改配置文件开始挂载 滴!滴!滴! 画重点 先备份先备份 备份命令
sudo cp /etc/fstab /etc/fstab.backup
开始编辑
sudo vim /etc/fstab
sout
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/nvme1n1p1 during installation
UUID=769cbc60-db5b-45ba-bcfb-edf4e42bec2d / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=1885-1058 /boot/efi vfat umask=0077 0 1
然后加上对应的配置
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/nvme1n1p1 during installation
UUID=769cbc60-db5b-45ba-bcfb-edf4e42bec2d / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=1885-1058 /boot/efi vfat umask=0077 0 1
# smb硬盘挂载目录
UUID=365249EC5249B203 /media/smb ntfs nofail 0 0
nofail的意思是磁盘不存在不报错 第一个0对应 dump 备份标记 1启用 0忽略 第二个0对应 pass 检查顺序 允许的数字是 [0,1,2] 0不检测,1最高的优先权比如根目录等,2其他要检测的目录
- 重启看看是否自动挂载
sudo reboot