家里的笔记本买的比较早,当时的 SSD 还是比较贵的,就买了 128G 的版本。用了几年,平时上上网写点程序什么的还够用,最近准备装个虚拟机就发现比较捉襟见肘,于是决定买个 256G 的 SSD 来扩容。想把虚拟机的虚拟盘放在外置的 SSD 上,但 256G 全部拿来放虚拟机硬盘比较浪费,就打算把 SSD 格式化为 NTFS 格式同时兼做移动硬盘来用。

macOS 默认是支持 NTFS 文件系统的,连接硬盘到电脑上可以自动识别并挂载。但是,是以只读方式挂载的,想要以读写方式挂载,可以打开终端用命令行重新挂载,命令如下:

1
2
3
4
5
6
7
8
# 卸载只读挂载
sudo umount /dev/disk2s1

# 创建挂载目录
sudo mkdir -p /Volumes/SSD

# 重新挂载为 NTFS 读写模式到 /Volumes/SSD
sudo mount_ntfs -o rw,nobrowse /dev/disk2s1 /Volumes/SSD

/dev/disk2s1 是移动硬盘的块设备,这个是根据电脑当前连接了多少个硬盘动态变化的,我的电脑只有默认的硬盘占用了 disk1 因此外接的硬盘为 disk2, 一定要搞清楚了再挂载。/Volumes/SSD 是移动硬盘的挂载点(目录),挂载点可以自己定,必须先创建好挂载点再挂载,我自己写了个 Shell 脚本来帮我自动卸载并重新挂载,挂载点可以自己指定,脚本如下:

自动挂载脚本

macOS_mount_ntfs_as_rw.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/sh

FS_COLUMN=1
MP_COLUMN=9
USER_MOUNT_POINT=$1
DEFAULT_MOUNT_POINT=/Volumes

# Eject disk, arg1: disk
function eject_disk()
{
if [ -b "$1" ]; then
sudo umount $1
ret=`df | grep $1 | awk '{print $'$MP_COLUMN'}'`
if [ -d "$ret" ]; then
echo "Umount disk error!"
exit
fi
else
echo "$1 is not a disk!"
exit
fi
}

# Get mount point, arg1: disk, arg2: mount point
function get_mount_point()
{
local mp

# Mount point is specified by user
if [ "$USER_MOUNT_POINT" ]; then
mp=$USER_MOUNT_POINT
# User do not specified use disk basename
else
if [ "$2" ]; then
mp=$2
else
mp=`basename $1`
mp="$DEFAULT_MOUNT_POINT/$mp"
fi
fi

echo $mp
}

# Mount as NTFS arg1: disk, arg2: mount point
function mount_as_ntfs_rw()
{
# Create mount point if it's not exist
if [ ! -d "$2" ]; then
sudo mkdir -p $mp
fi

# Mount disk as NTFS
sudo mount_ntfs -o rw,nobrowse $1 $2
ret=`df | grep $1 | awk '{print $'$MP_COLUMN'}'`
if [ -d "$ret" ]; then
echo "Success, disk [$1] is mount as NTFS r/w mode to [$2]"
else
echo "Failed, disk [$1] mount to [$2] failed!"
exit
fi
}

# First get all external disks
external_disks=`ls /dev/disk[2-9]s[1-9]`

# Check if disk is already mounted
for disk in $external_disks; do

# Get disk mount point
mp=`df | grep $disk | awk '{print $'$MP_COLUMN'}'`

# Eject disk
if [ -d "$mp" ]; then
while true; do
read -p "Disk [$disk] is already mounted on [$mp], do you want to eject it? (Y/N)" option
case $option in
[Yy]*) eject_disk $disk; break;;
[Nn]*) echo "Mount as NTFS r/w mode must ejecd it first"; exit;;
*) echo "Unknown option $option";
esac
done
fi

# Re-mount as NTFS
while true; do
mp=$(get_mount_point $disk $mp)
read -p "Disk [$disk] is ejected, do you want to re-mount as r/w mode to [$mp]? (Y/N)" option
case $option in
[Yy]*) mount_as_ntfs_rw $disk $mp; break;;
[Nn]*) echo "exit!"; exit;;
*) echo "Unknown option $option";
esac
done
done

这个脚本会自动检测所有除了 disk1 外的所有硬盘,如果硬盘已经挂载,会先询问是否要弹出,然后再询问是否要重新挂载为 NTFS 读写模式。挂载点和之前只读模式的挂载点一样,通常为硬盘的名称,例如:/Volumes/SL-BG2, 如果硬盘已经弹出了,那么默认的挂载点为硬盘块设备的名称。

例如:/dev/disk2s1 如果已经已经弹出了,那么重新挂载为读写模式的挂载点为 /Volumes/disk2s1,当然也可以通过参数告诉脚本挂载点在哪里,在我的电脑上运行效果如下:

./macOS_mount_ntfs_as_rw.sh /Volumes/SSD
Disk [/dev/disk2s1] is already mounted on [/Volumes/SL-BG2], do you want to eject it? (Y/N)y
Disk [/dev/disk2s1] is ejected, do you want to re-mount as r/w mode to [/Volumes/SSD]? (Y/N)y
Success, disk [/dev/disk2s1] is mount as NTFS r/w mode to [/Volumes/SSD]