Hardcore Linux

Anything about Ubuntu, Centos, openSuSe and Fedora

UDEV: Mount and Unmount External Drive

I got three sets of USB External Hard Drive I’m using for my system backup. Need it to have a hotplug capability to have multiple copies of backup. The backup operations are done midnight of the schedule date.

Here’s my list:

  1. Daily Backup – two (2) sets of hard drive of 500GB
  2. Weekly Backup – two (2) sets of hard drive with capacity of 1TB
  3. Monthly  Backup one (1) set capacity of 1TB

The previous problem I’ve encoutered is that I need to manually mount them as:

/backup/daily
/backup/weekly
/backup/monthly

My backup script tend to use them on that location. So I made this udev script that will fix them and automatically mount and umount them. Though the umount should be safely done, but in case you forgot to umount the drive, the script will umount them for you.

Here’s my /etc/udev/rules.d/10-backupdrives.rules

ACTION=="add",KERNEL=="sd[b-z][1-9]", PROGRAM="/sbin/blkid -s LABEL /dev/%k",RESULT=="*BACKUPD*", RUN+="/bin/mount /dev/%k /backup/daily",OPTIONS="last_rule"
ACTION=="add",KERNEL=="sd[b-z][1-9]", PROGRAM="/sbin/blkid -s LABEL /dev/%k",RESULT=="*BACKUPW*", RUN+="/bin/mount /dev/%k /backup/weekly",OPTIONS="last_rule"
ACTION=="add",KERNEL=="sd[b-z][1-9]", PROGRAM="/sbin/blkid -s LABEL /dev/%k",RESULT=="*BACKUPM*", RUN+="/bin/mount /dev/%k /backup/monthly",OPTIONS="last_rule"
ACTION=="remove",KERNEL=="sd[b-z][1-9]",RUN+="/bin/umount /dev/%k",OPTIONS="last_rule"


One response to “UDEV: Mount and Unmount External Drive

  1. Fabian June 28, 2013 at 3:35 pm

    Thank! This helped me a lot🙂 Switched Labels for UUIDs, but exactly the thing I was looking for.

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: