openwrt固件使用blkid命令获取硬盘U盘文件系统UUID格式

2022-10-23
0评论
/
733阅读
爱搜啊

今天才知道这个命令,正愁着怎么在openwrt中U盘的自动挂载,而且要对不同的文件系统区分不同的挂载命令。

那么第一步就是如何知道当前插入的U盘的文件系统格式呢?VFAT?FAT32?NTFS?EXT4?

openwrt固件使用blkid命令

blkid(blockid)

blkid命令 获取文件系统类型、UUID 

在Linux下可以使用blkid命令对查询设备上所采用文件系统类型进行查询。blkid主要用来对系统的块设备(包括交换分区)所使用的文件系统类型、LABEL、UUID等信息进行查询。要使用这个命令必须安装e2fsprogs软件包。

直接使用blkid可列出当前系统中所以已挂载文件系统的类型

注意此命令需要用root用户运行!

sudo blkid

/dev/sda1: LABEL=”win7″ UUID=”40305E93305E9030″ TYPE=”ntfs”

/dev/sda5: LABEL=”software” UUID=”823E2D6213AF89BD” TYPE=”ntfs”

/dev/sda6: LABEL=”learning” UUID=”CCBC9A082598C349″ TYPE=”ntfs”

/dev/sda7: LABEL=”entertainment” UUID=”0979A05BD10F9410″ TYPE=”ntfs”

/dev/sda8: UUID=”7350922f-c69c-4f33-84e0-befd8b42d2f6″ TYPE=”swap”

/dev/sda9: UUID=”3002feb1-dceb-441d-bfd2-31243e336d39″ TYPE=”ext4″

blkid的help

-c <file>   指定cache文件(default: /etc/blkid.tab, /dev/null = none)

-d          don’t encode non-printing characters

-h          显示帮助信息

-g          garbage collect the blkid cache

-o <format> 指定输出格式

-k          list all known filesystems/RAIDs and exit

-s <tag>    显示指定信息,默认显示所有信息

-t <token>  find device with a specific token (NAME=value pair)

-l          look up only first device with token specified by -t

-L <label>  convert LABEL to device name

-U <UUID>   convert UUID to device name

-v          显示版本信息

-w <file>   write cache to different file (/dev/null = no write)

<dev>       specify device(s) to probe (default: all devices)

Low-level probing options:

-p          low-level superblocks probing (bypass cache)

-i          gather information about I/O limits

-S <size>   overwrite device size

-O <offset> probe at the given offset

-u <list>   filter by “usage” (e.g. -u filesystem,raid)

-n <list>   filter by filesystem type (e.g. -n vfat,ext3)

我的使用实例

for find in ls /dev/sd[a-z][1-9] 2&amp;gt;/dev/null ;do
echo "find=$find,index=$index"
my_fstype="blkid | grep "/dev/$find" | awk -F 'TYPE="' '{print $2}' | sed 's/" //'"
mkdir -p /mnt/usbstorage
if [ "$my_fstype" = "NTFS" ];then #有可能是小写
ntfs-3g -o iocharset=utf8,rw /dev/$find /mnt/usbstorage
if [ "$?" -ne 0 ];then
ntfs-3g -o rw /dev/$find /mnt/usbstorage
fi
mount_ok=1
elif [ "$my_fstype" = "VFAT" ];then #有可能是小写
mount_ok=1
mount -o iocharset=utf8,rw /dev/$find /mnt/usbstorage
else
echo "unsupport disk fstype!"
fi
if [ "$mount_ok" = "1" ];then

if [ -d "/mnt/usbstorage/php-home" ];then
ln -s /mnt/usbstorage/php-home /php-home
fi
/etc/init.d/uhttpd restart
fi
index=$((index+1))
done

相关推荐

openwrt固件ipk文件结构分析ipk文件本质是什么?

openwrt固件后台LUCI页面报错查看错误debug调试代码

openwrt固件生成ipk的过程ipk文件到底是什么?


本站附件分享,如果附件失效,可以去找找看

诚通网盘附件百度网盘附件


标签: blkid openwrt UUID
于2022-10-23发布