How to find the filesystem type of an USB key to mount it correctly?
1
vote
3
answers
208
views
I have to mount a old USB key formatted with FAT filesystem. The mount must be executed automatically by a
udev
rule which executes a bash script.
When the USB key is inserted in the USB port, the script, for now, executes the command:
blkid -o udev /dev/sda1
where /dev/sda1
is the partition present inside the USB and formatted with FAT32 (or FAT16) filesystem.
The output of the previous command for the USB key **is empty**.
The output of the same command (blkid
) for other USB keys contains the udev
variable ID_FS_TYPE
; possible values of ID_FS_TYPE
are: vfat
, ntfs
, exfat
.
So an empty output for the execution of blkid
happens only for this old USB and I'm not able to know why it happens only for it.
### Different options for mount
command if the filesystem is vfat
###
If the value of the variable ID_FS_TYPE
is vfat
the script must execute the following mount
command:
> mount -o rw,relatime,users,gid=100,umask=000,shortname=mixed,utf8=1,flush /dev/sda1 /mount/point
While if the filesystem is not vfat
the options for the mount
command can be the following:
mount -o rw,relatime /dev/sda1 /mount/point
With the particular USB key (1 GB and very old) the script by the command blkid
, can't determine that the filesystem type is vfat
so it executes the second mount
command; the result is that the permissions for the mount point directory (called /media/sda1
) are:
> ls -l /media/
total 16
drwxr-xr-x 3 root root 16384 Jan 1 1970 sda1
while I need:
# ls -l /media/
total 16
drwxrwxrwx 3 root root 16384 Jan 1 1970 sda1
I need those permissions because **all users must be able to write on the USB** and not only the proprietary (that is root
in my context).
### Find file system type by other commands ###
[This link](https://unix.stackexchange.com/questions/53313/how-to-show-the-filesystem-type-via-the-terminal) gives other tips to get the filesystem type of this particular USB key. So I have tried other commands:
- lsblk -n -o FSTYPE /dev/sda1
: also in this case, for my specific USB key, the output of the command is empty
- the output of the command file -sL /dev/sda1
instead is very long; I show this output below:
> file -sL /dev/sda1
/dev/sda1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "MSDOS5.0", sectors/cluster 32, reserved sectors 8, root entries 512, Media descriptor 0xf8, sectors/FAT 240, sectors/track 63, heads 255, hidden sectors 2048, sectors 1966080 (volumes > 32 MB), reserved 0x1, serial number 0xa4906b9d, unlabeled, FAT (16 bit)
In this output it is present the info FAT (16 bit)
, but it is not clear that the filesystem of the partition of the USB key is formatted vfat
. If I execute the previous file -sL
command on a USB key formatted by NTFS filesystem the output of the command is:
> file -sL /dev/sda
/dev/sda: DOS/MBR boot sector, code offset 0x52+2, OEM-ID "NTFS ", sectors/cluster 8, Media descriptor 0xf8, sectors/track 63, heads 255, dos < 4.0 BootSector (0x0), FAT (1Y bit by descriptor); NTFS, sectors/track 63, physical drive 0x80, sectors 15654911, $MFT start cluster 786432, $MFTMirror start cluster 2, bytes/RecordSegment 2^(-1*246), clusters/index block 1, serial number 030fcd5a9fcd56a1c; contains bootstrap BOOTMGR
In this output is present the string NTFS
, but is present also the string FAT
, so with this output it is not easy to establish that the filesystem is vfat
and not ntfs
.
### The question ###
Is there a command other than the previous ones that can provide the filesystem of an USB key before mounting it?
Asked by User051209
(498 rep)
Apr 22, 2025, 01:27 PM
Last activity: Apr 29, 2025, 12:22 PM
Last activity: Apr 29, 2025, 12:22 PM