udev troubles

Recently I bought an USB stick for my laptop that I intend to use to backup my files.

Now the problem with USB sticks is that they get assigned different devices and are mounted in different locations which makes it a little harder to automate a backup script.

But: Linux knows an answer. The udev system allows to define rules that are applied when a new device is recognized. So I defined a new rule in /etc/udev/rules.d/62-backup-usb-stick.rules which creates a symbolic link from the USB stick device to /dev/backup. It works great when I insert the stick.

But today I discovered that it didn’t work when I boot when the stick is already present. /dev/backup ended up pointing to some arbitrary device (most often to /dev/vcsd1 which isn’t even a block device).

Eventually I looked at the existing rules in /etc/udev/rules.d and came up with the following script that now does what it is supposed to do even when I reboot:

SUBSYSTEM!="block", GOTO="backup_usb_stick_end"
# skip rules for innappropriate block devices
KERNEL=="ram*|loop*|fd*|nbd*|gnbd*|dm-*|md*", GOTO="backup_usb_stick_end"
BUS=="usb", SYSFS{idVendor}=="3538", SYSFS{idProduct}=="0054",
    SYSFS{serial}=="000000000009D3", SYMLINK="backup"
LABEL="backup_usb_stick_end"
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: