Udev, cannot create name for USB drive

I’m not very familiar with udev so it is possible that I am doing something wrong. But I am looking for some help getting my usb stick renamed so that it has a static name when I mount it or when I try to navigate it. Here are the steps that I am doing:

  1. Get device info by running df:
Filesystem      Size  Used Avail Use% Mounted on
dev             7.7G     0  7.7G   0% /dev
run             7.7G  1.7M  7.7G   1% /run
/dev/dm-0       109G   42G   61G  41% /
tmpfs           7.7G   17M  7.7G   1% /dev/shm
tmpfs           7.7G   51M  7.7G   1% /tmp
tmpfs           1.6G   68K  1.6G   1% /run/user/1000
/dev/sdc1        58G  160K   58G   1% /run/media/mycomp/41C5-8509

  1. I notice that my usb stick is currently named /dev/sdc1, and run
udevadm info --name=/dev/sdc1 --attribute-walk
  1. I get the vendor (0781) and product id (5581)

4… create the following rule in /etc/udev/rules.d

ACTION=="add", ATTRS{idVendor}=="0781", ATTRS{idProduct}=="5581", SYMLINK+="usb1"

I restarted my computer and then added the usb drive, it is still mounting in the typical way without the name usb1

Something like this should do the trick (avoid spaces in label - you will thank me later)

sudo e2label /dev/sdc1 "usb1"

systemd always mount in the volatile /run tree → /run/media/$USER/${<label> | <UUID>}

If you need something more specific like /data/backup you will would have to use an automount unit.

2 Likes

no idea what you want make (for mount label is very good)

rule:

ACTION=="add|change", KERNEL=="sdg", SYMLINK+="usbkey"

only result is :

ls -ld /dev/usb*
lrwxrwxrwx 1 root root  3 22 août  09:15 /dev/usbkey -> sdg

now , is more safe to use dd of=/dev/usbkey ...

1 Like

when I do the following:

ls -ld /dev/usb*
drwxr-xr-x 2 root root 60 Aug 22 09:32 /dev/usb
lrwxrwxrwx 1 root root  3 Aug 22 09:32 /dev/usb1 -> sdb

Does this mean my udev rule worked? If so, why is it when I do df I don’t see “usb1” anywhere? I thought the point of this is so when I mount my device I can just call it usb1 instead of trying to figure out what the other name is

df shows mounted partitions you confuse with devices (/dev/*)
manjaro auto-mount partition with name label partition

for show device and label(if exists)

 lsblk -o "NAME,LABEL,SIZE,FSTYPE,PARTTYPE,MOUNTPOINT"

your key as some devices symlink

udisksctl info -b /dev/usb1 | grep /dev/

https://unix.stackexchange.com/questions/87300/differences-between-volume-partition-and-drive

1 Like

yes

As @papajoke told you, df works on mounted file systems.

You can, but you didn’t issue a mount command (where /dev/usb1 would be “usable”) but a whole other command which only works on already mounted filesystems.

1 Like

so how do I do this part then?

https://man.archlinux.org/man/mount.8.en

$ sudo mount /dev/usb1 /path/where/you/want/to/mount/the/device

/path/where/you/want/to/mount/the/device is any directory in your drectory tree and has to exist obviously.

1 Like

That works. But will this automatically mount to that location now?

edit: a better way to ask the question is will this mount location always be the same now?

No, but for automatic mounting one wouldn’t have adjusted the device name. That’s only needed for us humans…
Anyways, see this for automatic mounting:

and of course there is the arch wiki with its /etc/fstab article (which nowadays gets parsed and translated to those mount units mentioned above):
https://wiki.archlinux.org/title/fstab

1 Like

yes can use fstab , but not always good

  • ext4 or win ?
  • mont only first partition ?

you use kde, so you mount with dolphin ?
if usb is ext4 and you want mount first partition in home, you can add in /etc/fstab

/dev/sdc1 /home/LOGIN_TO_CHANGE/usb1 ext4 defaults,nofail,noauto 0 0
1 Like