参考:https://www.jianshu.com/p/040bb60aa468
1. 下载fuse库
https://github.com/libfuse/libfuse.git //git仓库地址
2. 编译需要的模块安装
apt install meson
apt install ninja-build
pip3 install pytest //如果失败,是因为源的问题,替换成国内源就行了。 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pytest
3. 编译安装fuse
cd libfuse
mkdir build
cd build
meson ..
出现以下内容编译成功:
Checking for function "fork": YES
Checking for function "fstatat": YES
Checking for function "openat": YES
Checking for function "readlinkat": YES
Checking for function "pipe2": YES
Checking for function "splice": YES
Checking for function "vmsplice": YES
Checking for function "posix_fallocate": YES
Checking for function "fdatasync": YES
Checking for function "utimensat": YES
Checking for function "copy_file_range": YES
Checking for function "fallocate": YES
Checking for function "setxattr": YES
Checking for function "iconv": YES
Checking whether type "struct stat" has member "st_atim": YES
Checking whether type "struct stat" has member "st_atimespec": NO
Configuring config.h using configuration
Message: Compiler warns about unused result even when casting to void
Dependency threads found: YES
Library iconv found: NO
Library dl found: YES
Library rt found: YES
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Native dependency udev found: YES 237
Program install_helper.sh found: YES (/mnt/hgfs/libfuse/util/install_helper.sh)
Build targets in project: 26
Found ninja-1.8.2 at /usr/bin/ninja
然后继续:
cd .. //libfuse
python3 -m pytest test/
cd build
ninja install
到这里fuse的编译安装就完成了。
接下来进行一个简单的测试:
cd libfuse/example
gcc -Wall hello.c `pkg-config fuse3 --cflags --libs` -o hello //编译hello.c 编译方式在文件的注释中有
cd /mnt
mkdir hello_test //建立挂载目录
cd libfuse/example
./hello /mnt/hello_test/ //挂载
若显示:
./hello: error while loading shared libraries: libfuse3.so.3: cannot open shared object file: No such file or directory
是因为没有配置ldconfig:
vim /etc/ld.so.conf.d/fuse.conf
输入:
/usr/local/lib
执行:
ldconfig
重新挂载:
./hello /mnt/hello_test/
现在挂载成功啦!!!
进入hello_test目录,可以看到hello文件:
cat hello
Hello World! //显示结果