海思ntfs-3g移植、挂载ntfs格式的U盘

海思ntfs-3g移植、挂载ntfs格式的U盘 程序员小贾 2024-02-23 17:17:26 95

前言

  • 一般 Linux 系统默认都支持挂载 FAT32 格式的移动硬盘,但并不支持挂载 NTFS 格式的。那么我们在开发产品过程中,怎么应对这些需求呢?
  • 有人可能第一时间会想到修改内核配置,以达到支持挂载 NTFS 格式的移动硬盘。在此只能说很遗憾,虽然内核支持 NTFS 格式的挂载,但是它只支持可读,不支持可写。
  • 也正因为如此,我们如果想要让系统支持挂载 NTFS 格式的移动硬盘,并且让它可读可写,一般都需要移植第三方开源的工具:ntfs-3g。

1、NTFS-3G 简要说明

NTFS-3G 是一个开源的软件,可以实现 Linux、Free BSD、Mac OSX、NetBSD 和 Haiku 等操作系统中的 NTFS 读写支持。它可以安全且快速地读写 Windows 系统的 NTFS 分区,而不用担心数据丢失。

2、NTFS-3G 工具安装

2.1 离线下载 ntfs-3g

https://github.com/tuxera/ntfs-3g/releases

2.2 在线下载 ntfs-3g(推荐优先)

wget https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2022.10.3.tgz

2.3 解压安装 ntfs-3g

# 如果是在根目录的路径下安装,需要使用超级权限
sudo su

# 使安装交叉编译器的环境变量生效
source /etc/profile

# 解压压缩包
tar -zxf ntfs-3g_ntfsprogs-2022.10.3.tgz

# 进入解压目录
cd ntfs-3g_ntfsprogs-2022.10.3/

# 配置编译参数
./configure CC=arm-hisiv400-linux-gcc --host=arm-hisiv400-linux --prefix=/my_work/tools/ntfs-3g_ntfsprogs-2022.10.3/install --exec-prefix=/my_work/tools/ntfs-3g_ntfsprogs-2022.10.3/install

# 编译生成工具与库文件
make clean;make
make install

./configure 参数配置说明:

./configure CC=arm-hisiv400-linux-gcc —host=arm-hisiv400-linux —prefix=/my_work/tools/ntfs-3g_ntfsprogs-2022.10.3/install —exec-prefix=/my_work/tools/ntfs-3g_ntfsprogs-2022.10.3/install
CC=arm-hisiv400-linux-gcc // 交叉编译器;
—host=arm-hisiv400-linux // 交叉编译工具链;
—prefix=/my_work/tools/ntfs-3g_ntfsprogs-2022.10.3/install // 指定二进制文件、库文件、配置文件的安装路径(必须要填写实际安装的绝对路径)
—exec-prefix=/my_work/tools/ntfs-3g_ntfsprogs-2022.10.3/install // 指定可执行文件的安装路径(必须要填写实际安装的绝对路径)

3、NTFS-3G 工具移植到文件系统(rootfs)

cd ntfs-3g_ntfsprogs-2022.10.3/install
cp ./bin/ntfs-3g rootfs/bin                        //ntfs硬盘挂载工具
cp ./bin/ntfsfix rootfs/bin                      //ntfs硬盘修复工具
cp ./sbin/mkntfs rootfs/bin                        //ntfs格式化分区工具
cp ./lib/libntfs-3g.so.89.0.0 rootfs/lib        //ntfs依赖的动态库

cd rootfs/lib                                   //创建软链接libntfs-3g.so.89 和 libntfs-3g.so
ln -s libntfs-3g.so.89.0.0 libntfs-3g.so.89
ln -s libntfs-3g.so.89.0.0 libntfs-3g.so

arm-hisiv400-linux-strip xxx (xxx表示目标文件) 可以去掉相应的符号和调试信息来节省空间,例如:

arm-hisiv400-linux-strip ./install/bin/ntfs-3g
arm-hisiv400-linux-strip ./install/lib/libntfs-3g.so.89.0.0

4、NTFS-3G 工具挂载

4.1 查看U盘盘符

fdisk -l

# Device    Boot      Start         End      Blocks   Id  System
# /dev/sda1   *      355462    51298533    16180960    7  HPFS/NTFS

4.2 U盘挂载

mkdir -p /mnt/usb
ntfs-3g /dev/sda1 /mnt/usb

5、NTFS-3G 源码编译报错问题记录

5.1 问题1:参数配置报错及解决方法

  • 问题描述:执行 ./configure 配置报错如下:

    /bin/rm: cannot remove ‘libtoolT’: No such file or directory
    You can type now ‘make’ to build ntfs-3g.

  • 问题原因:在根目录下安装工具,没有使用超级权限,或者没有执行 make。

  • 解决方法:(若在根目录下安装需要超级权限)执行 make:
sudo make

5.2 问题2:工具安装过程报错及解决方法

  • 问题描述:执行 make install 报错如下:

ln -s -f /tools/ntfs-3g_ntfsprogs-2022.10.3/install/sbin/mkntfs /sbin/mkfs.ntfs
ln: failed to create symbolic link ‘/sbin/mkfs.ntfs’: Permission denied
Makefile:1427: recipe for target ‘install-exec-hook’ failed
make[3]: [install-exec-hook] Error 1
make[3]: Leaving directory ‘/tools/ntfs-3g_ntfsprogs-2022.10.3/ntfsprogs’
Makefile:1346: recipe for target ‘install-exec-am’ failed
make[2]:
[install-exec-am] Error 2
make[2]: Leaving directory ‘/tools/ntfs-3g_ntfsprogs-2022.10.3/ntfsprogs’
Makefile:1283: recipe for target ‘install-am’ failed
make[1]: [install-am] Error 2
make[1]: Leaving directory ‘/tools/ntfs-3g_ntfsprogs-2022.10.3/ntfsprogs’
Makefile:494: recipe for target ‘install-recursive’ failed
make:
[install-recursive] Error 1

  • 问题原因:ntfs-3g 工具在根目录下安装,需要超级权限执行。
  • 解决方法:使用超级权限执行安装命令:
sudo make install

5.3 问题3:使用超级权限安装工具报错及解决方法

  • 问题描述:执行 sudo make install 报错如下:

../libtool: line 1085: arm-hisiv400-linux-ranlib: command not found
Makefile:433: recipe for target ‘install-libLTLIBRARIES’ failed
make[2]: [install-libLTLIBRARIES] Error 127
make[2]: Leaving directory ‘/tools/ntfs-3g_ntfsprogs-2022.10.3/libntfs-3g’
Makefile:930: recipe for target ‘install-am’ failed
make[1]:
[install-am] Error 2
make[1]: Leaving directory ‘/tools/ntfs-3g_ntfsprogs-2022.10.3/libntfs-3g’
Makefile:494: recipe for target ‘install-recursive’ failed
make: * [install-recursive] Error 1

  • 问题原因:切换到超级权限后找不到对应的工具链 arm-hisiv400-linux。
  • 解决方法:临时配置交叉工具链环境,再重新安装即可:
sudo su
source /etc/profile
make install

5.4 问题4:fuse device is missing

  • 问题描述:ntfs-3g /dev/sda1 /mnt/usb 挂载报错如下:

# ntfs-3g /dev/sda1 /mnt/usb
modprobe: module fuse not found in modules.dep
ntfs-3g-mount: fuse device is missing, try ‘modprobe fuse’ as root

  • 问题原因:内核默认没有加载 fuse 驱动。
  • 解决方法:打开内核配置界面(make menuconfig),配置如下:
File systems  --->        
    <*> FUSE (Filesystem in Userspace) support

声明:本文内容由易百纳平台入驻作者撰写,文章观点仅代表作者本人,不代表易百纳立场。如有内容侵权或者其他问题,请联系本站进行删除。
红包 点赞 收藏 评论 打赏
评论
0个
内容存在敏感词
手气红包
    易百纳技术社区暂无数据
相关专栏
置顶时间设置
结束时间
删除原因
  • 广告/SPAM
  • 恶意灌水
  • 违规内容
  • 文不对题
  • 重复发帖
打赏作者
易百纳技术社区
程序员小贾
您的支持将鼓励我继续创作!
打赏金额:
¥1易百纳技术社区
¥5易百纳技术社区
¥10易百纳技术社区
¥50易百纳技术社区
¥100易百纳技术社区
支付方式:
微信支付
支付宝支付
易百纳技术社区微信支付
易百纳技术社区
打赏成功!

感谢您的打赏,如若您也想被打赏,可前往 发表专栏 哦~

举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-专栏模块

审核失败

失败原因
备注
拼手气红包 红包规则
祝福语
恭喜发财,大吉大利!
红包金额
红包最小金额不能低于5元
红包数量
红包数量范围10~50个
余额支付
当前余额:
可前往问答、专栏板块获取收益 去获取
取 消 确 定

小包子的红包

恭喜发财,大吉大利

已领取20/40,共1.6元 红包规则

    易百纳技术社区