4

If I mount a drive using the file manager (I'm using PCManFM), the mount point is automatically removed when I run the umount command. However, if I mount by running mkdir and then mount, I have to manually remove the mount point after I have run umount.

Why does this happen? Is there a way to mount the drive using the mount command that will make the mount point be automatically removed?

Update: Is it similar to the reason for this?

0

2 Answers 2

1

It is not up to umount to delete a directory so from command line you need to do it yourself.

You can use a script for that:

#!/bin/bash
mount_point=/media/directory
umount $mount_point && rmdir $mount_point &

and save it as umount.sh.

The mount_point might be better off as a variable so you could so

./umount.sh /media/dir

Something like this

#!/bin/bash
mount_point=$1
umount $mount_point && rmdir $mount_point &

So why is it automatically removed when I run umount on a drive that has been mounted with a GUI file manager?

The answer to this is more likely a design decision. I have not found any documentation on this (maybe someone else can provide a link ;) )

2
  • 2
    So why is it automatically removed when I run umount on a drive that has been mounted with a GUI file manager? Apr 8, 2013 at 17:22
  • still looking for that but it might be a design decision :P
    – Rinzwind
    Apr 8, 2013 at 17:34
0

Ubuntu 20.10.

The problem of Rinzwind's script it that if it is interrupted then the directory will not be removed and this may cause problems later.

The mount point will be automatically removed if mounted by:

udisksctl mount --block-device /dev/sdb1

I think this is what the Ubuntu Disks graphical user interface does. I don't know how and when the mount point is removed or not removed.

Looking at mount point created by udisksctl or Disks:

% stat /media/alba/EFI
  File: /media/alba/EFI
  Size: 512         Blocks: 1          IO Block: 512    directory
Device: 811h/2065d  Inode: 1           Links: 3
Access: (0755/drwxr-xr-x)  Uid: ( 1000/    alba)   Gid: ( 1000/    alba)
Access: 1970-01-01 01:00:00.000000000 +0100
Modify: 1970-01-01 01:00:00.000000000 +0100
Change: 1970-01-01 01:00:00.000000000 +0100
 Birth: -

It has three links but sudo find / -samefile /media/alba/EFI only returns itself.

You must log in to answer this question.

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