11

I am running Debian. I can plug in and view the contents of my flashdrive using filemanager under X, but how can I do this from the command line, and how can I safely remove it when I am done?

Steve Robillard
  • 34,687
  • 17
  • 103
  • 109
  • Duplicate of a U+L question: http://unix.stackexchange.com/questions/18925/how-to-mount-a-device-in-linux-beginners-confusion – finnw Jun 17 '12 at 12:34
  • Questions like this would be better asked on Unix and Linux. Questions entirely about Linux without clear relevance to the Raspberry Pi are not generally a good fit for this site. – ramblinjan Jul 10 '12 at 18:20

2 Answers2

10

If you're interested in the drives mounting automatically when you plug them in then you can try installing usbmount:

sudo apt-get install usbmount

When you insert a flash drive it will detect and mount it to /media/usb[0-7] and will unmount it when it is removed.

Note:

You will want to edit your /etc/usbmount/usbmount.conf
To configure automounting as writeable for your user.

To do this, edit the FS_MOUNTOPTIONS option to match your UID.
Run id to find your UID. Example:

FS_MOUNTOPTIONS="uid=1000,gid=1000"

source

Jivings
  • 22,538
  • 11
  • 90
  • 139
8

After plugging in your flashdrive. Run the following command:

grep "SCSI removable disk" /var/log/messages

you should see something like the following

Jun 16 23:48:58 raspberrypi kernel: sd 2:0:0:0: [sda] Attached SCSI removable disk

The important part is the bit in the square brackets, in this case "sda"

next enter the following command to create a mount point:

mkdir ~/myflashdrive

then mount the drive by entering the following command (replace the x's with the results of the grep command you ran above e.g. sda):

sudo mount -t vfat -o rw,users /dev/xxx1 ~/myflashdrive

now you can change to the directory where you mounted your flash drive using the following command:

cd ~/myflashdrive

to list the contents of the directory enter the following command:

ls -la

When you are done and want to remove the flashdrive return to your home directory with the follwoing command (you can't unmount the drive if you are currently working in one of its directories.)

cd ~

this will take you back to your home directory. you can then use the following command to unmount the drive (note the spelling of the command):

sudo umount ~/myflashdrive

you can now safely remove your flashdrive.

This applies to fat32 formatted flash drives (nearly all flash drives are fat32 formatted drives).

Steve Robillard
  • 34,687
  • 17
  • 103
  • 109