bash 是win10下挺方便的linux子系统,但我发现它不会自动挂载 U盘和移动硬盘。哪怕是开机前就已经插在电脑上的U盘,也不能识别。在 /mnt/ 下映射的只有内置硬盘的win盘符

要实现挂载也不难,稍微搜一下就找到方法了,备忘如下:

挂载脚本 mountdish.sh

#!/bin/bash
# mount U盘或移动硬盘
# 用法 挂载 J盘
# ./mountdish.sh j


typeset -u targetDrv
targetDrv=$1
targetPath="/mnt/$1"

if [ ! -x "$targetPath" ]; then
    mkdir "$targetPath"
    echo "new path created $targetPath"
fi

sudo mount -t drvfs ${targetDrv}: ${targetPath}

echo "done ${targetDrv}:"

卸载U盘 umountdisk.sh

#!/bin/bash
# umount U盘或移动硬盘
# 用法 卸载 J盘
# ./umountdisk.sh j

targetPath="/mnt/$1"

sudo umount ${targetPath}

echo "done umount ${targetPath}:"

用完记得要 umount,否则win会锁定读写状态不给安全移除。


参考文:
https://www.cnblogs.com/tl542475736/p/8486440.html

标签: win10, bash, mount, 移动硬盘

添加新评论