3

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.

3 Answers 3

3

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 &
1

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.

2
  • 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, 2011 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, 2011 at 20:51
0

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
1
  • 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, 2011 at 20:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .