Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I insert an SD card in the reader, slackware creates a mount point and mounts my card volumes. On unmounting the volumes, the mount point vanishes. How do I achieve this manually?

When I attempt to mount a volume using the mount command, the mount point folder must exist and the folder does not vanish on umount. Is there a way to create a mount point if it does not exist? and ensure that the folders vanish on umounting?

Can I do so with some switches and not write a complete script?

Thank you.

share|improve this question
add comment

migrated from stackoverflow.com Jun 19 '11 at 20:04

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 2 down vote accepted

In modern Linux systems the udev subsystem is responsible for sending events to some higher level program or subsystem that does this. Your distro has such a system, probly HAL. You could write a udev rule to do this yourself. For example the following achieves what you want in the context of adding and removing a backup drive:

# Auto mount the USB backup drive we attach. Theoretically should be done from HAL.
ACTION=="add", ENV{ID_FS_LABEL_ENC}=="backups", PROGRAM="user_mount_backup.sh"
ACTION=="remove", ENV{ID_FS_LABEL_ENC}=="backups", PROGRAM="user_umount_backup.sh"

user_mount_backup.sh:

# Auto mount the USB backup drive we attach. Theoretically should be done from HAL.
#!/bin/bash
mnt_pt=/media/backups
[[ -d $mnt_pt ]] || mkdir $mnt_pt && mount -L backups $mnt_pt &

user_umount_backup.sh:

#!/bin/bash
mnt_pt=/media/backups
umount $mnt_pt && rmdir $mnt_pt &
share|improve this answer
add comment

The simple answer is now, you can't. Slackware will be doing that by having higher level software that creates the directory before doing the mount and removes it after doing the unmount.

As there are no switches to the mount or unmount commands to do that for you, the only way to achieve the same thing from the command line would be to write scripts to wrap the commands and create and remove the directories as requires.

share|improve this answer
    
Thanks. I can see the higher level software creating the folder, but the folders vanish on umount which I run manually. So is there a demon checking for unmounts all the time? –  Lord Loh. Jun 19 '11 at 20:40
    
Quite probably, yes. The software that created the folder and did the mount will watch for the unmount and remove the directory again regardless of who did the mount. –  TomH Jun 19 '11 at 20:51
add comment

Create one folder in /media or /mnt or of your choice directories and then give the mount point like:

mount -t typeFilesystem(vfat/NTFS/EXT#) /media/sdcard
share|improve this answer
    
I think that only works if you have the entry in fstab and will it remove the mount point on umount? –  Lord Loh. Jun 19 '11 at 20:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.