Connecting unionfs with udev?

Michael R. Head burner at
Sat Mar 24 14:58:39 UTC 2007

[I sent this several hours ago, but didn't see it hit the list, so I'm resending]

Hi, I'm experimenting with unionfs. Here's the setup I'd like to

I want a virtual directory that combines all the attached USB drives
into one. As the drives are attached and ejected, I'd like them to be
added and removed from the unioned directory dynamically. What's more,
in the ideal situation, I'd like to only add them if they have a certain
subdirectory on them.

I've got this in my /etc/fstab:
none /mnt/union unionfs dirs=/mnt/union=rw 0 1

Basically, when a usb storage device is attached, I'd like something
like this to run:

if [ -d "$USB_MOUNT_POINT/stuff" ]; then
    unionctl /mnt/union --add --mode ro "$USB_MOUNT_POINT/stuff"

And then before the usb drive is removed (presumably when it's ejected
by gnome-volume-maanger), I'd like something like this to happen:

if [ 0 -lt `unionctl /mnt/union --list |grep -c $USB_MOUNT_POINT/stuff` ]; then
    unionctl /mnt/union --remove $USB_MOUNT_POINT/stuff

Any ideas where to fit this stuff in? I was thinking somewhere
in /dev/udev/rules.d, but I wasn't sure where the best place would be.

Michael R. Head <burner at>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3189 bytes
Desc: not available
URL: <>

More information about the ubuntu-users mailing list