文章目录
使Linux支持exFAT和NTFS文件系统,U盘自动挂载
查看系统支持什么文件系统
cat /proc/filesystems
nodev sysfs
nodev rootfs
nodev ramfs
nodev bdev
nodev proc
nodev cgroup
nodev tmpfs
nodev devtmpfs
nodev configfs
nodev debugfs
nodev securityfs
nodev sockfs
nodev pipefs
nodev rpc_pipefs
nodev devpts
ext3
ext2
ext4
vfat
msdos
exfat #添加成功
nodev nfs
nodev nfs4
ntfs #需要在内核勾选
nodev jffs2
nodev autofs
fuseblk
nodev fuse
nodev fusectl
nodev ubifs
exFAT
源码下载
git clone https://github.com/dorimanx/exfat-nofuse.git
编译
拷贝源码到内核/fs/
下,并改名为exfat
cd [linux]
cp -rvf exfat-nofuse [linux]/fs/exfat
修改[linux]/fs/Kconfig
menu "DOS/FAT/NT Filesystems"
source "fs/fat/Kconfig"
+source "fs/exfat/Kconfig" #添加
source "fs/ntfs/Kconfig"
endmenu
修改[linux]/fs/Makefile
obj-$(CONFIG_FAT_FS) += fat/
+obj-$(CONFIG_EXFAT_FS) += exfat/ #添加
obj-$(CONFIG_BFS_FS) += bfs/
添加相应配置
cd [linux]
make menuconfig
#File systems > DOS/FAT/NT check exfat as MODULE (M) (437) Default codepage for exFAT (utf8) Default iocharset for exFAT
CONFIG_FAT_DEFAULT_CODEPAGE=437
CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
CONFIG_EXFAT_FS=y
CONFIG_EXFAT_DISCARD=y
CONFIG_EXFAT_DELAYED_SYNC=y
CONFIG_EXFAT_KERNEL_DEBUG=y
CONFIG_EXFAT_DEBUG_MSG=y
CONFIG_EXFAT_DEFAULT_CODEPAGE=437
CONFIG_EXFAT_DEFAULT_IOCHARSET="utf8"
CONFIG_NTFS_FS=y
CONFIG_NTFS_DEBUG=y
CONFIG_NTFS_RW=y
开始编译
make -j8
把内核烧录挂载个exFAT U盘试试成功没。
NTFS
添加相应配置
cd [linux]
make menuconfig
CONFIG_FAT_DEFAULT_CODEPAGE=437
CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
CONFIG_NTFS_FS=y
CONFIG_NTFS_DEBUG=y
CONFIG_NTFS_RW=y
ntfs-3g
下载源码
配置
./configure CC=交叉编译工具链 -host=arm-linux --prefix=`pwd`/_install --exec-prefix=`pwd`/_install/usr
编译和安装
make -j8 && make install
# _install/usr/bin/下的ntfsinfo和ntfs-3g放到板子里,ntfsinfo判断是否为NTFS文件系统,ntfs-3g用来挂载NTFS
ntfsinfo -m /dev/sdc1
ntfs-3g /dev/sdc1 /mnt
USB自动挂载
挂载脚本
mount-usb.sh
#!/bin/sh
count=$(ls /dev/$1* 2>/dev/null | wc -l)
if [ $count -gt 1 ];then
exit 0;
fi
mkdir /mnt/$1
if ntfsinfo -m /dev/$1 >/dev/null 2>&1; then
ntfs-3g /dev/$1 /mnt/$1
else
mount /dev/$1 /mnt/$1
fi
#killall -SIGUSR1 发送信号给应用程序
sync
fi
卸载脚本
umount-usb.sh
count=$(ls /dev/$1* 2>/dev/null | wc -l)
if [ $count -gt 1 ];then
exit 0;
fi
sync
umount /mnt/$1
#killall -SIGUSR1 发送信号给应用程序
udev规则
/etc/udev/rules.d/12-usbsd-mount.rules
#usb自动挂载
ACTION!="add", GOTO="farsight_mount"
KERNEL=="sd[a-z][0-9]", RUN+="/etc/udev/mount-usb.sh %k"
KERNEL=="sd[a-z]", RUN+="/etc/udev/mount-usb.sh %k"
LABEL="farsight_mount"
#usb卸载
ACTION!="remove", GOTO="farsight_umount"
KERNEL=="sd[a-z][0-9]", RUN+="/etc/udev/umount-usb.sh %k"
KERNEL=="sd[a-z]", RUN+="/etc/udev/umount-usb.sh %k"
LABEL="farsight_umount"