You are not logged in.

#1 2010-08-23 21:50:40

iamsmrt
Member
Registered: 2009-08-12
Posts: 138

HAL, udev and unmounting hard drives

Hi,

I just added a udev rule to automount my devices at /media/$DEVICE and everything's going swimmingly. However, when I unmount the device, I'd like /media/$DEVICE to be deleted. This can't be done with udev since the only actions it recognizes are add/remove, right? Is there any way to get HAL or something else to handle it?

Cheers,
SMRT

Offline

#2 2010-08-23 21:59:44

ilusi0n
Member
Registered: 2010-06-09
Posts: 187

Re: HAL, udev and unmounting hard drives

I made a similiar question here, At the moment I let udev mount all my stuff. When I want to umount, I do always sudo umount /media/label and the udev rule delete that folder that is created on media folder.

Offline

#3 2010-08-23 22:09:35

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: HAL, udev and unmounting hard drives

http://wiki.archlinux.org/index.php/Ude … r_.2Fmedia

# Clean up after removal
ACTION=="remove", RUN+="/bin/rm -f /media/usbhd-%k", RUN+="/bin/umount -l /mnt/usbhd-%k", RUN+="/bin/rmdir /mnt/usbhd-%k"

Offline

#4 2010-08-23 22:19:50

iamsmrt
Member
Registered: 2009-08-12
Posts: 138

Re: HAL, udev and unmounting hard drives

ilusi0n wrote:

I made a similiar question here, At the moment I let udev mount all my stuff. When I want to umount, I do always sudo umount /media/label and the udev rule delete that folder that is created on media folder.

Wait, so you have a udev rule that automatically deletes your folder in /media? May I ask what that rule is?

karol wrote:

http://wiki.archlinux.org/index.php/Ude … r_.2Fmedia

# Clean up after removal
ACTION=="remove", RUN+="/bin/rm -f /media/usbhd-%k", RUN+="/bin/umount -l /mnt/usbhd-%k", RUN+="/bin/rmdir /mnt/usbhd-%k"

Doesn't that only remove symlinks, unmount, remove the actual folder when the device is PHYSICALLY removed?

Last edited by iamsmrt (2010-08-23 22:20:50)

Offline

#5 2010-08-23 22:24:13

ilusi0n
Member
Registered: 2010-06-09
Posts: 187

Re: HAL, udev and unmounting hard drives

yes it deletes. I use this rule on archwiki http://wiki.archlinux.org/index.php/Ude … if_present

Offline

#6 2010-08-23 22:30:05

iamsmrt
Member
Registered: 2009-08-12
Posts: 138

Re: HAL, udev and unmounting hard drives

ilusi0n wrote:

yes it deletes. I use this rule on archwiki http://wiki.archlinux.org/index.php/Ude … if_present

I'm using the same rule but it only deletes when I actually unplug the device rather than just unmounting it.

Offline

#7 2010-08-23 22:33:29

ilusi0n
Member
Registered: 2010-06-09
Posts: 187

Re: HAL, udev and unmounting hard drives

Yes willl only delete the folder when you remove it. You must umount first though or you will have corrupt files.

Offline

#8 2010-08-27 13:16:31

iamsmrt
Member
Registered: 2009-08-12
Posts: 138

Re: HAL, udev and unmounting hard drives

I couldn't figure out a way to clean when simply just unmounting and I noticed that if you unmounted something and turned off the computer, the folder created in /media would still remain. So I added a cleanup script to /etc/rc.local:

Use your own discretion when using this as it could potentially erase your external media.

for i in $(mount | awk 'match($0,"/media/[^ ]*") {print substr($0,RSTART,RLENGTH)}'); do
    for j in $(ls /media | egrep "[^cd|dvd|fl]"); do
        if [ "/media/$j" !=  $i ]; then
            rm -r /media/$j
        fi
    done
done

Offline

Board footer

Powered by FluxBB