1

Today I almost erased my system with dd because I was going to write on my internal HDD (/dev/sdb*) instead of the removable usb (/dev/sdc*). I want to make a udev rule to set any block usb under a completely different name, like /dev/remX*

Where X is the device number and * the partition number Of course the normal /dev/sd* should not be created.

I tried to a add a new rule but it creating the old /dev/sd*, so maybe I need a way to "override" the old rule?

What is the cleanest way to proceed?

Lesto
  • 111
  • 4
  • 3
    Don't use `/dev/sd*` for destructive things, use `/dev/disk/by-id/*` instead. It's much more difficult to mistake one drive for another this way. – Michael Hampton Nov 04 '18 at 18:53

1 Answers1

2

As say in comments better use devices by id.

But you can define own udev rule, as example you can set prefix which based on driver which used device:

The four main match keys introduced so far (KERNEL/SUBSYSTEM/DRIVER/ATTR) only match against values corresponding to the device in question, and do not match values from parent devices. udev provides variants of the match keys that will search upwards through the tree:

KERNELS - match against the kernel name for the device, or the kernel name for any of the parent devices
SUBSYSTEMS - match against the subsystem of the device, or the subsystem of any of the parent devices
DRIVERS - match against the name of the driver backing the device, or the name of the driver backing any of the parent devices
ATTRS - match a sysfs attribute of the device, or a sysfs attribute of any of the parent devices

So you can do nextsteps

With this command:udevadm info -a -p /sys/block/sdX you got output where you can see which DRIVERS used for removable disk

and create rule like this:

DRIVERS=="sata_nv", NAME="my_hard_disk"

Good described there

Ivan Gurzhiy
  • 306
  • 1
  • 1