当前位置:u赢电竞手机版 > 操作系统 > linux下给SD或者USB驱动设置新的标签的脚本操作系

linux下给SD或者USB驱动设置新的标签的脚本操作系

文章作者:操作系统 上传时间:2019-05-14
#!/bin/sh -e
# Label a vfat device, such as an SD card or USB stick.
# It uses mlabel, from mtools.
# Another way, undocumented, of which I did not know:
#   mlabel -i /dev/sdf1 ::DEVICENAME
#   mlabel -i /dev/sdf1 -s ::
# fattag may work slightly better, it also:
#   - sets mtools_skip_check=1, in case of weird device size
#   - does a sync

device="$1"
label="$2"

if [ -z "$device" -o "${device#-}" != "$device" ]; then
        prog=`basename "$0"`
        echo >&2 "usage: $prog device [label]"
        echo >&2 "fat devices:"
        blkid | sed -n '/fat/{ s/^/  /; p; }'
        exit 2
fi
bak=0
trap '
        status=$?
        if [ $bak = 1 ]; then
                mv ~/.mtoolsrc.bak.$$ ~/.mtoolsrc
        else
                rm -f ~/.mtoolsrc
        fi
        exit $status
' INT QUIT TERM PIPE EXIT
if [ -e ~/.mtoolsrc ]; then
        bak=1
        mv ~/.mtoolsrc ~/.mtoolsrc.bak.$$
fi
echo "mtools_skip_check=1
drive p: file="$device"" >~/.mtoolsrc
if [ -z "$label" ]; then
        mlabel -s p: | sed 's/^ Volume label is //; s/ *$//;'
else
        mlabel p:"$label"
        sync
fi

本文由u赢电竞手机版发布于操作系统,转载请注明出处:linux下给SD或者USB驱动设置新的标签的脚本操作系

关键词: linux 驱动器标签 USB