我把我在学校时笔记本电脑废弃了,把硬盘拆了下来,并格式化成了 Linux 的 ext4 文件系统,通过 USB 挂载在了我的树莓派上。 但是我偶尔要在 macOS 上查看上面的文件,无奈 macOS 竟然不能识别 Linux 的 ext系列文件系统(ext2/ext3/ext4),真是个奇葩。 macOS 和 Linux 都是类 Unix 操作系统,。本是同根生,相煎何太急。 所以,需要在 macOS 安装能识别 ext文件系统的模块,安装[FUSE(用户空间文件系统)](https://en.wikipedia.org/wiki/Filesystem_in_Userspace)即可。 ## 安装 OSXFUSE [OSXFUSE](https://github.com/osxfuse/osxfuse)是 FUSE 的 macOS 版本。 直接使用 brew 安装。 ```- $ brew tap homebrew/cask $ brew cask install osxfuse ``` ### 安装 FUSE-EXT2 [FUSE-EXT2](https://github.com/alperakcan/fuse-ext2/) 使得 OSXFUSE 支持 ext2/ext3/ext4 文件系统的挂载。 把下面的代码保存到一个shell脚本中,执行即可。原代码在这里:[https://github.com/alperakcan/fuse-ext2/#macos](https://github.com/alperakcan/fuse-ext2/#macos)。 这个脚本有一些小问题,可能出错不会【很明显地】报告,需要自己仔细看一下有没有出错。 ```bash #!/bin/sh export PATH=/opt/gnu/bin:$PATH export PKG_CONFIG_PATH=/opt/gnu/lib/pkgconfig:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH mkdir fuse-ext2.build cd fuse-ext2.build if [ ! -d fuse-ext2 ]; then git clone https://github.com/alperakcan/fuse-ext2.git fi # m4 if [ ! -f m4-1.4.17.tar.gz ]; then curl -O -L http://ftp.gnu.org/gnu/m4/m4-1.4.17.tar.gz fi tar -zxvf m4-1.4.17.tar.gz cd m4-1.4.17 ./configure --prefix=/opt/gnu make -j 16 sudo make install cd ../ # autoconf if [ ! -f autoconf-2.69.tar.gz ]; then curl -O -L http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz fi tar -zxvf autoconf-2.69.tar.gz cd autoconf-2.69 ./configure --prefix=/opt/gnu make sudo make install cd ../ # automake if [ ! -f automake-1.15.tar.gz ]; then curl -O -L http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz fi tar -zxvf automake-1.15.tar.gz cd automake-1.15 ./configure --prefix=/opt/gnu make sudo make install cd ../ # libtool if [ ! -f libtool-2.4.6.tar.gz ]; then curl -O -L http://ftpmirror.gnu.org/libtool/libtool-2.4.6.tar.gz fi tar -zxvf libtool-2.4.6.tar.gz cd libtool-2.4.6 ./configure --prefix=/opt/gnu make sudo make install cd ../ # e2fsprogs if [ ! -f e2fsprogs-1.43.4.tar.gz ]; then curl -O -L https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v1.43.4/e2fsprogs-1.43.4.tar.gz fi tar -zxvf e2fsprogs-1.43.4.tar.gz cd e2fsprogs-1.43.4 ./configure --prefix=/opt/gnu --disable-nls make sudo make install sudo make install-libs sudo cp /opt/gnu/lib/pkgconfig/* /usr/local/lib/pkgconfig cd ../ # fuse-ext2 export PATH=/opt/gnu/bin:$PATH export PKG_CONFIG_PATH=/opt/gnu/lib/pkgconfig:/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH cd fuse-ext2 ./autogen.sh CFLAGS="-idirafter/opt/gnu/include -idirafter/usr/local/include/osxfuse/" LDFLAGS="-L/opt/gnu/lib -L/usr/local/lib" ./configure make sudo make install ``` 这个脚本跑成功之后,会在系统偏好设置里面增加一项如下的设置,表明安装已成功。 ![fuse-ext2.png](fuse-ext2.png) ## 重启操作系统 一定要重启,不然不会生效。比如执行 fese-ext2 命令无任何反应,也没有错误输出。 ## 查看磁盘 把 ext4 文件系统的硬盘插到 macOS 上会被提示:插入的磁盘不能被电脑读取。点击“忽略”。 可以在系统磁盘管理工具里面看到这块硬盘,但是,不可用。 ![disks.png](disks.png) 其中的`disk2s1`表示磁盘2、分区1。 这个信息也可以通过在终端执行命令看到: ```bash $ diskutil list /dev/disk0 (internal): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme 500.3 GB disk0 1: EFI EFI 314.6 MB disk0s1 2: Apple_APFS Container disk1 500.0 GB disk0s2 /dev/disk1 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +500.0 GB disk1 Physical Store disk0s2 1: APFS Volume Macintosh HD 473.8 GB disk1s1 2: APFS Volume Preboot 49.2 MB disk1s2 3: APFS Volume Recovery 509.9 MB disk1s3 4: APFS Volume VM 3.2 GB disk1s4 /dev/disk2 (external, physical): #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *500.1 GB disk2 1: Linux 500.1 GB disk2s1 ``` ## 挂载磁盘 使用以下命令**只读**挂载到桌面: ```bash $ sudo fuse-ext2 /dev/disk2s1 ~/Desktop/disk2s1 ``` 使用以下命令**读写**挂载到桌面: ```bash $ sudo fuse-ext2 /dev/disk2s1 ~/Desktop/disk2s1 -o rw+ ``` 使用以下命令取消挂载: ```bash $ sudo umount ~/Desktop/disk2s1/ ``` 或者在磁盘上点菜单进行弹出。如果弹出后桌面图标仍然存在,可能是弹出失败,请在终端用命令弹出。