Tuesday, May 12, 2009

How To Mount an USB Flash Drive in Linux

Before you begin trying to do this manually, make sure Linux has not all ready mounted your drive to your Desktop automatically. This is the way you should mount your drive if you plan on using it often.

1. Plug in the flash drive into one of the USB ports on your computer. These usually are found on the back-side of your computer. Some newer models also have some ports on the front panel.

2. After you've plugged it in, you'll want to open a terminal window and become the root user. This user is the only one which can access the commands to manually mount your drive.

To become the root user, type in the following commands.

[helpero@linux:~> su
Password:
linux:/home/helpero #

When it asks for your password, enter the root password. After you've become root, enter the following command into the same terminal window to see if your computer has recognized the flash drive you plugged in.

linux:/home/helpero # lsusb
Bus 002 Device 003: ID 08ec:0010 M-Systems Flash Disk Pioneers DiskOnKey
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000
linux:/home/helpero #

This information shows that the system recognized one USB device named M-Systems Flash Disk Pioneers DiskOnKey. Yours will most likely have a different name, so look for the name of your flash disk's manufacturer or name in the output. If your output doesn't list anything that looks like your flash drive, we recommend trying different USB ports on your computer to see if it can get listed. You must get your computer to recognize your flash drive in order to continue with this tutorial.

3. After successful recognition of your USB drive, you'll want to create a directory where your USB drive will be mounted. Enter the following commands into the same terminal window to do this:

linux:/home/helpero # cd Desktop/
linux:/home/helpero/Desktop # mkdir flash
linux:/home/helpero/Desktop #

* The cd Desktop command tells the computer to go into the Desktop directory.
* The mkdir flash command makes a directory named flash which we're going to use to mount the flash drive.

4. Now simply issue the following command in the same terminal window to get the appropriate device which is attached to your flash drive:

dmesg | grep -i "SCSI device"

linux:/home/helpero/Desktop # dmesg | grep -i "SCSI device"
SCSI device sda: 31520 512-byte hdwr sectors (16 MB)
SCSI device sda: 31520 512-byte hdwr sectors (16 MB)
SCSI device sda: 31520 512-byte hdwr sectors (16 MB)
linux:/home/helpero/Desktop #

The information you are interested in is the output immediately after SCSI device. On this machine it's sda. This is the device you are looking for. If you've got a newer machine with an SATA drive or a SCSI drive in it, the output will most likely be quite different. The words you'll be looking for will probably be sdb or sdc. To make sure you select the correct device, simply look for some information that describes your flash drive.

5. Now, enter the simple command as follows:

linux:/home/helpero/Desktop # pwd
/home/helpero/Desktop
linux:/home/helpero/Desktop #

6. After that is done, the first thing to do is make a backup of a very important file named /etc/fstab by issuing the following command:

linux:/home/helpero # cp /etc/fstab /etc/fstab.bak
linux:/home/helpero #

7. Now, you are going to need to tell your computer to set itself up to mount your flash drive every time your computer is turned on. To do this you'll need to add something like the following line to the /etc/fstab file:

/dev/sda /home/helpero/Desktop/flash vfat users,noauto,uid=helpero,gid=users 0 0

Some of the information might be different for you. If you didn't find sda for your device before, you'll have to enter the appropriate device. Example: If you found sdc for your device, you would change the /dev/sda line to /dev/sdc. You will also change the /home/helpero/Desktop/flash line to the appropriate directory.

Example: If the line after the pwd command was /home/example/Desktop you'd use /home/example/Desktop/flash instead of /home/helpero/Desktop/flash. Also, you'll need to change the uid=helpero line to reflect the username you enter when you start Linux.

8. At this step you are gonna enter the command to alter the /etc/fstab file. To do this issue the following command in your terminal window:

linux:/home/helpero/Desktop # echo "/dev/sda /home/helpero/Desktop/flash vfat users,noauto,uid=helpero,gid=users 0 0" >> /etc/fstab
linux:/home/helpero/Desktop #

Now your /etc/fstab file has been altered, and you're ready to mount your flash drive.

9. To do so, simply enter the following commands:

linux:/home/helpero/Desktop # exit
linux:/home/helpero/Desktop # mount flash
linux:/home/helpero/Desktop #

And your flash drive should be mounted! You can now drag 'n' drop things into your flash folder on your Desktop!

10. When you turn your computer off, in order to mount it again, simply go to your Desktop directory in a new terminal by typing cd Desktop and then type in mount flash and it'll be mounted again.

No comments:

Post a Comment