How to mount a removable USB drive from a script

Jonathan Ryshpan jonrysh at pacbell.net
Sun Nov 26 10:22:54 UTC 2006


> On 11/25/06, Jonathan Ryshpan <jonrysh at pacbell.net> wrote:
> > I have a removable USB drive on my system.  When KDE starts an icon
> > appears on the desktop that allows the drive to be mounted in the /media
> > directory; as a side effect the directory /media/usb-disk/ is created on
> > which to mount the drive.  This is done by right clicking the icon and
> > clicking on the desired action in the popup menu.
> >
> > There must be some way to have a shell script perform the same operation
> > that clicking on the icon/popup line mount makes happen.  What is it?
> >
> > If I create the directory /media/usb-disk and then "$
> > mount /dev/sda1 /media/usb-disk", everything works fine till I unmount
> > the disk, as can be done using the icon; but then an attempt to remount
> > the drive by clicking on the "Open" line in the popup fails with the
> > message:
> >         The mount point '/media/usb-disk' is already occupied
> >
> > which is, of course, not correct.  I think I've filed a bug on this, but
> > I have so many bugs outstanding that I'm not sure.

On Sat, 2006-11-25 at 21:29 -0500, Jacques B. wrote:
> If I understand correctly, you mounted the USB device via command line
> but unmounted it via the GUI?  Unless I am mistaken that is not
> permitted in gnome.  I believe the last time I tried that it gave an
> error saying it was mounted via command line therefore must be
> unmounted the same way.  Perhaps the same applies with KDE but KDE is
> failing to give that message  and thinks that it unmounted it.  Check
> your mount command after unmounting via KDE to see if it really is
> unmounted or if KDE mistakenly believes it to be.  Because that would
> certainly cause the error you noted.  The bug would be with KDE not
> properly detecting that it was mounted via the command line and
> therefore must be unmounted the same way (unless KDE upon detecting
> that can unmounted it appropriately.
> 
> I'm not clear what you want the script to do.  If it's simply to mount
> via the command line, then you simply put what you typed at the
> command line into a script (you can technically omit the #!/bin/bash
> for that case).

To answer your first point, KDE does actually unmount a drive mounted by
a mount command from the command line.  However it does not remove the
mount point, and the icon will not permit a drive to be mounted if the
mount point already exists, whether or not something is mounted on it.

You are correct that I want to mount the drive from the command line,
but I want the command to do is to mount the drive *as*if* the drive had
been mounted by using the icon.

Once I know how to do this, I can put the command into a script to do
what's wanted, which has to do with backing up my system.

BTW: Although the icon appears on the desktop, there is no corresponding
file in ~/Desktop.  Does anyone know what's going on here?

Thanks - jon





More information about the users mailing list