When I insert a drive, it automatically mounts to /media/homeuser/drivename.

If I unmount it, I can always remount it by clicking the device again, and it remounts to the exact same spot.

However, once I've unmounted this, I'd like to remount it using a terminal command.

The mount command expects a second parameter.

I try this: sudo mount /dev/sdb1 /media/homeuser/drivename

But it tells me the directory drivename does not exist. If I exclude the directory and only use /media/homeuser/, the drive mounts to that folder instead, obviously.

If I mkdir on drivename before mounting it, then unmount it, that directory remains there - which is not exactly what would happen if I mounted it using the "mount" button - once unmounted, the directory would disappear.

Hopefully this makes sense - all I'm trying to do is programatically mount the drive so that it ends in the exact same state as if I'd pressed the mount button.

  • What OS are you using? – Jan Sep 11 '17 at 21:36
  • I'm not a 100% expert on this but as far as I know a mountpoint i.e. a folder must be there in order for it to work. Presumably, you desktop environment creates a folder with an unique name or something and deletes it on amount. But this has nothing to do with the 'native' mount command. This is done programmatically and there should be tools/programs that do exactly that. I'll have a look into it. – rudib Sep 11 '17 at 21:53
  • And: what do you mean by programmatically? Programmatically i.e. a bash script or similar would be: mkdir /media/homeuser/drivename; mount /dev/sdb1 /media/homeuser/drivename; do things on the drive; umount /dev/sdb1; rm -rf /media/homeuser/drivename – rudib Sep 11 '17 at 21:57
  • You probably want to look at the gvfs-mount command instead of plain old mount. Can’t remember the full details though. – Darren Sep 11 '17 at 22:02
  • That or just have an alias that will mkdir before mounting and rmdir after umounting. – DopeGhoti Sep 11 '17 at 22:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.