700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > arm linux:添加对挂载ntfs和exfat格式u盘的支持(petalinux)

arm linux:添加对挂载ntfs和exfat格式u盘的支持(petalinux)

时间:2019-01-18 21:41:06

相关推荐

arm linux:添加对挂载ntfs和exfat格式u盘的支持(petalinux)

Linux内核(arm64 4.19.0)配置

–>File systems

<*> FUSE (Filesystem in Userspace) support添加exfat支持

因为是用petalinux构建的linux环境,这里也用它添加exfat支持。(也可直接将驱动加到linux源码fs文件夹下,再修改对应目录的Makefile和Kconfig文件即可) 下载exfat驱动源码添加exfat驱动到petalinux工程

petalinux-create -t modules --name exfat --enable

将驱动源码拷贝到添加的驱动文件夹修改exfat.bb文件如下:

SUMMARY = "Recipe for build an external exfat Linux kernel module"SECTION = "PETALINUX/modules"LICENSE = "GPLv2"LIC_FILES_CHKSUM = "file://COPYING;md5=12f884d2ae1ff87c09e5b7ccc2c4ca7e"inherit moduleSRC_URI = "file://Makefile \file://dkms.conf \file://exfat_api.c \file://exfat_api.h \file://exfat_bitmap.c \file://exfat_bitmap.h \file://exfat_blkdev.c \file://exfat_blkdev.h \file://exfat_cache.c \file://exfat_cache.h \file://exfat_config.h \file://exfat_core.c \file://exfat_core.h \file://exfat_data.c \file://exfat_data.h \file://exfat-km.mk \file://exfat_oal.c \file://exfat_oal.h \file://exfat_super.c \file://exfat_super.h \file://exfat_upcase.c \file://exfat_version.h \file://exfat_nls.c \file://exfat_nls.h \file://Kconfig \file://LICENSE \file://COPYING\"S = "${WORKDIR}"# The inherit of module.bbclass will automatically name module packages with# "kernel-module-" prefix as required by the oe-core build environment.

petalinux-buildntfs

因为linux内核源码中对ntfs的挂载是只读的,所以需要下载ntfs-3g工具进行交叉编译,再移植到板子 下载ntfs-3g源码解压后,进入源码文件夹,进行交叉编译

./configure --build=“编译主机,如i386“ --host=“交叉编译工具链” --prefix=“编译生成文件路径” --exec-prefix=“编译执行文件路径”make make install

将编译生成ntfs-3g文件(在执行configure 时,“exec-prefix”/bin 路径下),拷贝到板子的/bin文件夹下。(编译时make成功了,但make install失败,“exec-prefix”/bin 路径下没有ntfs-3g文件,搜索后在 ”‘源码路径’/src/.libs 文件夹下找到)。将生成的库文件(在执行configure 时,“exec-prefix”/lib 路径下),拷贝到板子的/lib文件夹下在板子上测试执行ntfs-3g输出如下,移植成功

root@root:~# ntfs-3gntfs-3g: No device is specified.ntfs-3g .3.23 integrated FUSE 27 - Third Generation NTFS DriverConfiguration type 1, XATTRS are on, POSIX ACLS are offCopyright (C) - Yura PakhuchiyCopyright (C) - Szabolcs SzakacsitsCopyright (C) - Jean-Pierre AndreCopyright (C) Erik LarssonUsage: ntfs-3g [-o option[,...]] <device|image_file> <mount_point>Options: ro (read-only mount), windows_names, uid=, gid=,umask=, fmask=, dmask=, streams_interface=.Please see the details in the manual (type: man ntfs-3g).Example: ntfs-3g /dev/sda1 /mnt/windowsNews, support and information:

自动挂载

exfat加入后会直接自动挂载,不需要再做修改。后面主要是实现ntfs格式u盘的自动挂载。

板子环境:linux kernel 4.19.0,rootfs通过busybox1.29.2创建 当前系统采用udev实现U盘的自动挂载,所以可以通过修改mount.sh来添加ntfs格式u盘的特殊处理搜索找到mount.sh文件路径为/etc/udev/scripts/mount.sh在mount.sh加入ntfs格式判断,判断成功后执行ntfs-3g,而非mount指令。修改后mount.sh如下

#!/bin/sh## Called from udev## Attempt to mount any added block devices and umount any removed devicesBASE_INIT="`readlink -f "/sbin/init"`"INIT_SYSTEMD="/lib/systemd/systemd"NTFS="/bin/ntfs-3g"if [ "x$BASE_INIT" = "x$INIT_SYSTEMD" ];then# systemd as init uses systemd-mount to mount block devicesMOUNT="/usr/bin/systemd-mount"UMOUNT="/usr/bin/systemd-umount"if [ -x $MOUNT ] && [ -x $UMOUNT ];thenlogger "Using systemd-mount to finish mount"elselogger "Linux init is using systemd, so please install systemd-mount to finish mount"exit 1fielseMOUNT="/bin/mount"UMOUNT="/bin/umount"fiPMOUNT="/usr/bin/pmount"for line in `grep -h -v ^# /etc/udev/mount.blacklist /etc/udev/mount.blacklist.d/*`doif [ ` expr match "$DEVNAME" "$line" ` -gt 0 ];thenlogger "udev/mount.sh" "[$DEVNAME] is blacklisted, ignoring"exit 0fidoneautomount_systemd() {name="`basename "$DEVNAME"`"# Skip the partition which are already in /etc/fstabgrep "^[[:space:]]*$DEVNAME" /etc/fstab && returnfor n in LABEL PARTLABEL UUID PARTUUID; dotmp="$(lsblk -o $n $DEVNAME | sed -e '1d')"test -z "$tmp" && continuetmp="$n=$tmp"grep "^[[:space:]]*$tmp" /etc/fstab && returndone[ -d "/run/media/$name" ] || mkdir -p "/run/media/$name"MOUNT="$MOUNT -o silent"# If filesystemtype is vfat, change the ownership group to 'disk', and# grant it with w/r/x permissions.case $ID_FS_TYPE invfat|fat)MOUNT="$MOUNT -o umask=007,gid=`awk -F':' '/^disk/{print $3}' /etc/group`";;ntfs)# 在此处加入对ntfs格式设备的特殊处理,不用系统的mount命令,改为ntfs-3g,完成后,直接退出当前函数MOUNT="$NTFS"if ! $MOUNT $DEVNAME "/run/media/$name"then#logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/run/media/$name\" failed!"rm_dir "/run/media/$name"elselogger "mount.sh/automount" "Auto-mount of [/run/media/$name] successful"touch "/tmp/.automount-$name"fireturn;;# TODO*);;esacif ! $MOUNT --no-block -t auto $DEVNAME "/run/media/$name"then#logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/run/media/$name\" failed!"rm_dir "/run/media/$name"elselogger "mount.sh/automount" "Auto-mount of [/run/media/$name] successful"touch "/tmp/.automount-$name"fi}automount() {name="`basename "$DEVNAME"`"if [ -x "$PMOUNT" ]; then$PMOUNT $DEVNAME 2> /dev/nullelif [ -x $MOUNT ]; then$MOUNT $DEVNAME 2> /dev/nullfi# If the device isn't mounted at this point, it isn't# configured in fstabgrep -q "^$DEVNAME " /proc/mounts && return! test -d "/run/media/$name" && mkdir -p "/run/media/$name"# Silent util-linux's version of mounting autoif [ "x`readlink $MOUNT`" = "x/bin/mount.util-linux" ] ;thenMOUNT="$MOUNT -o silent"fi# If filesystem type is vfat, change the ownership group to 'disk', and# grant it with w/r/x permissions.case $ID_FS_TYPE invfat|fat)MOUNT="$MOUNT -o umask=007,gid=`awk -F':' '/^disk/{print $3}' /etc/group`";;ntfs)# 在此处加入对ntfs格式设备的特殊处理,不用系统的mount命令,改为ntfs-3g,完成后,直接退出当前函数MOUNT="$NTFS"if ! $MOUNT $DEVNAME "/run/media/$name"then#logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/run/media/$name\" failed!"rm_dir "/run/media/$name"elselogger "mount.sh/automount" "Auto-mount of [/run/media/$name] successful"touch "/tmp/.automount-$name"fireturn;;# TODO*);;esacif ! $MOUNT -t auto $DEVNAME "/run/media/$name"then#logger "mount.sh/automount" "$MOUNT -t auto $DEVNAME \"/run/media/$name\" failed!"rm_dir "/run/media/$name"elselogger "mount.sh/automount" "Auto-mount of [/run/media/$name] successful"touch "/tmp/.automount-$name"fi}rm_dir() {# We do not want to rm -r populated directoriesif test "`find "$1" | wc -l | tr -d " "`" -lt 2 -a -d "$1"then! test -z "$1" && rm -r "$1"elselogger "mount.sh/automount" "Not removing non-empty directory [$1]"fi}# No ID_FS_TYPE for cdrom device, yet it should be mountedname="`basename "$DEVNAME"`"[ -e /sys/block/$name/device/media ] && media_type=`cat /sys/block/$name/device/media`if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -n "$ID_FS_TYPE" -o "$media_type" = "cdrom" ]; then# Note the root filesystem can show up as /dev/root in /proc/mounts,# so check the device number tooif expr $MAJOR "*" 256 + $MINOR != `stat -c %d /`; thenif [ "`basename $MOUNT`" = "systemd-mount" ];thenautomount_systemdelseautomountfififiif [ "$ACTION" = "remove" ] || [ "$ACTION" = "change" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; thenfor mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " `do$UMOUNT $mntdone# Remove empty directories from auto-mountername="`basename "$DEVNAME"`"test -e "/tmp/.automount-$name" && rm_dir "/run/media/$name"fi

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。