Mounting Usb drive in Linux


To use thumb drive in Linux, the device must first be mounted into the system. In older days, you must specify the file system type so Linux can mount it to he system. Today, Linux is clever enough to recognise it and manually mounting the file system is much easier. Here is what the mount command means:

mount – The mount command serves to attach the file system found on some device to the big file tree. Conversely, the umount(8) command will detach it again.

This is an example on how to mount a USB drive (thumb drive) in Linux:

1. Plug in the usb drive into the usb port on your computer. Wait a few seconds until your Linux system detect it. If not, pull the usb drive and plug in again. If you are using Ubuntu desktop, the usb drive will be detected and mounted automatically. In Ubuntu server command line terminal, a message will appear to notice you that some information about the usb drive that has been plug in.

If nothing happens, you can check the information in the /proc directory. From the command prompt, type ‘cat /proc/scsi/scsi‘ to read the scsi file.

     root@slackware:~# cat /proc/scsi/scsi  
     Attached devices:
     Host: scsi0 Channel: 00 Id: 00 Lun: 00 
     Vendor: ATA Model: WDC WD800JD-75JN Rev: 05.0 
     Type: Direct-Access ANSI SCSI revision: 05 
     Host: scsi2 Channel: 00 Id: 00 Lun: 00 
     Vendor: Kingston Model: DataTraveler 2.0 Rev: 1.02 
     Type: Direct-Access ANSI SCSI revision: 02

The highlighted text in red shows that the usb drive (thumb drive) is detected. Note that in real situation, the text is in white colour (default) not red. It’s highlighted for the sake of learning. You can see the detail in Host, Vendor and Type. If Linux can’t detect the usb drive and the usb drive data cannot be found in /proc/scsi/scsi, run rescan-scsi-bus -l from Slackware command line terminal. Below is the example:

root@slackware:~# rescan-scsi-bus -l
Host adapter 2 (ata_piix) found.
Host adapter 3 (ata_piix) found.
Host adapter 4 (ata_piix) found.
Host adapter 5 (ata_piix) found.
Host adapter 6 (pata_marvell) found.
Host adapter 7 (pata_marvell) found.
cat: /sys/class/scsi_host/host8/proc_name: No such file or directory
Host adapter 8 () found.
cat: /sys/class/scsi_host/host9/proc_name: No such file or directory
Host adapter 9 () found.
Scanning SCSI subsystem for new devices
Scanning host 2 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning for device 2 0 0 0 ...
OLD: Host: scsi2 Channel: 00 Id: 00 Lun: 00
      Vendor: ATA      Model: WDC WD1600AAJS-0 Rev: 05.0
      Type:   Direct-Access                    ANSI SCSI revision: 05
Scanning host 3 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning for device 3 0 0 0 ...
OLD: Host: scsi3 Channel: 00 Id: 00 Lun: 00
      Vendor: HL-DT-ST Model: DVDRAM GSA-H62N  Rev: CL00
      Type:   CD-ROM                           ANSI SCSI revision: 05
Scanning host 4 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning for device 4 0 0 0 ...
OLD: Host: scsi4 Channel: 00 Id: 00 Lun: 00
      Vendor: ATA      Model: ST3250820SV      Rev: 3.AC
      Type:   Direct-Access                    ANSI SCSI revision: 05
Scanning host 5 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning host 6 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning host 7 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning host 8 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning for device 8 0 0 0 ...
NEW: Segmentation fault
root@slackware:~#

2. The next step is to check with dmesg command to see what drive your thumb drive is. From the command line, type dmesg | grep sd (dmesg pipe grep sd). See example below:

     root@slackware:~# dmesg |grep sd 
     SCSI device sda: 156250000 512-byte hdwr sectors (80000 MB) 
     SCSI device sda: drive cache: write back 
     SCSI device sda: 156250000 512-byte hdwr sectors (80000 MB) 
     SCSI device sda: drive cache: write back 
     sda: sda1 sda2 < sda5 sda6 sda7 > 
     Attached scsi disk sda at scsi0, channel 0, id 0, lun 0 
     SCSI device sdb: 1007616 512-byte hdwr sectors (516 MB) 
     sdb: Write Protect is off 
     sdb: Mode Sense: 23 00 00 00 
     sdb: assuming drive cache: write through 
     SCSI device sdb: 1007616 512-byte hdwr sectors (516 MB) 
     sdb: Write Protect is off 
     sdb: Mode Sense: 23 00 00 00 
     sdb: assuming drive cache: write through
     sdb: sdb1 
     Attached scsi removable disk sdb at scsi2, channel 0, id 0, lun 0 
     root@slackware:~#

If you installed KDE, thumb drive or usb drive will be detected automatically when you plug it in. You can check what drive your thumb drive represents by looking at the device property. Here are steps on how you can check your thumb drive name from x-window kde or gnome:

Step 1 – Open System from kde desktop.

Open system image

Step 2 – Open Storage media.

Open storage media image

Step 3 – Right-click thumb drive icon and choose Properties. The thumb drive name displays at the top of the newly open pane (Properties title).

Thumb drive properties image

3. Now you can ‘su’ and create a proper directory to mount your thumb drive in /mnt directory. The standard form of the mount command, is mount -t type device dir. This tells the kernel to attach file system found on device (-t option for file system type) at the directory dir. The file system types which are currently supported include: adfs, affs, autofs, cifs, coda, coherent, cramfs, ebugfs, devpts, efs, ext, ext2, ext3, hfs, hfsplus, hpfs, iso9660, jfs, minix, msdos, ncpfs, nfs, nfs4, ntfs, proc, qnx4, ramfs, reiserfs, romfs, smbfs, sysv, tmpfs, udf, ufs, umsdos, usbfs, vfat, xenix, xfs, xiafs.

From the command line, type mount -t vfat /dev/sdb1 /mnt/usb and enter. Change directory into /mnt/usb directory.

NoteReplace sdb1 with your thumb drive name and /mnt/usb with your mount directory.

     bill@slackware:~$  
     bill@slackware:~$ su -  
     Password:  
     root@slackware:~#  
     root@slackware:~# mount -t vfat /dev/sdb1 /mnt/usb  
     root@slackware:~# cd /mnt/usb 
     root@slackware:~# ls 
     nbtscan-1.5.1a/ snort-2.0.5.tar.gz  
     nbtscan-1.5.1.tar.gz wintest*  
     root@slackware:~#

If it’s not working, or you are not sure of file system type, just ignore the -t option. Try this instead: mount <device> <destination>:

     root@slackware:~# mount /dev/sdb1 /mnt/usb  
     root@slackware:~# cd /mnt/usb 
     root@slackware:/mnt/usb# ls ls 
     nbtscan-1.5.1a / snort-2.0.5.tar.gz   
     nbtscan-1.5.1.tar.gz  wintest *  
     root@slackware:~#

If you want to access usb drive in Ubuntu using terminal, Ubuntu desktop automatically mount usb drive in /media/disk. So what you have to do is just cd into /media/disk directory.

Linux unmount usb drive

umount – The umount command detaches the file system(s) mentioned from the file hierarchy. A file system is specified by giving the directory where it has been mounted. Giving the special device on which the file system lives may also work, but is obsolete, mainly because it will fail in case this device was mounted on more than one directory.

Note that a file system cannot be unmounted when it is `busy’ – for example, when there are open files on it, or when some process has its working directory there, or when a swap file on it is in use. The offending process could even be umount itself – it opens libc, and libc in its turn may open for example locale files. A lazy unmount avoids this problem.

To unmount file system or devices, you must be out of the directory you want to unmount. Type cd and enter to go to the user’s home directory. Then perform this command:

     root@slackware:/mnt/usb# cd
     root@slackware:~# umount /mnt/usb/  
     root@slackware:~#

Replace the target directory with the location where you mounted your usb device or thumb drive directory. If there is no error, your device should be unmounted now. you can try listing the directory again to be sure:

root@slackware:~# umount /mnt/usb/
root@slackware:~# ls /mnt/usb/

You can check Cannot unmount dvd – Device is busy for more information about umount problem. It is a tutorial about unmonting cdrom/dvd device.

 

OR
USB storage devices are shown as SCSI drives in Linux, so if you have more than a SCSI device you can find different device names (/dev/sdXX where XX depends on your hardware). In this example I’ve chosen the first device in the SCSI chain (/dev/sda1)

  1. Open a console window (under KDE is called konsole)
  2. Login as root: type su and enter the password
  3. Change directory: cd /mnt
  4. Create a new directory: mkdir usbkey (if not exists)
  5. Try to mount your USB-key: mount /dev/sda1 /mnt/usbkey
  6. If it doesn’t works you may try another device (e.g. /dev/sda2)
  7. If it works you can list the files in the key: ls /mnt/usbkey
  8. Unmount the device: umount /mnt/usbkey
  9. Open for edit the file /etc/fstab with a text-editor
  10. Add this line: /dev/sda1 /mnt/usbkey vfat noauto,users,rw,umask=0 0 0
  11. Save and close the file
  12. Leave the root user: press CTRL+D or enter the command exit
  13. Now you can mount the key from your account: mount /mnt/usbkey
  14. For unmounting the key: umount /mnt/usbkey

Thank  you for reading

Linux mount usb drive

To use thumb drive in Linux, the device must first be mounted into the system. In older days, you must specify the file system type so Linux can mount it to he system. Today, Linux is clever enough to recognise it and manually mounting the file system is much easier. Here is what the mount command means:

mount – The mount command serves to attach the file system found on some device to the big file tree. Conversely, the umount(8) command will detach it again.

This is an example on how to mount a USB drive (thumb drive) in Linux:

1. Plug in the usb drive into the usb port on your computer. Wait a few seconds until your Linux system detect it. If not, pull the usb drive and plug in again. If you are using Ubuntu desktop, the usb drive will be detected and mounted automatically. In Ubuntu server command line terminal, a message will appear to notice you that some information about the usb drive that has been plug in.

If nothing happens, you can check the information in the /proc directory. From the command prompt, type ‘cat /proc/scsi/scsi‘ to read the scsi file.

     root@slackware:~# cat /proc/scsi/scsi  
     Attached devices:
     Host: scsi0 Channel: 00 Id: 00 Lun: 00 
     Vendor: ATA Model: WDC WD800JD-75JN Rev: 05.0 
     Type: Direct-Access ANSI SCSI revision: 05 
     Host: scsi2 Channel: 00 Id: 00 Lun: 00 
     Vendor: Kingston Model: DataTraveler 2.0 Rev: 1.02 
     Type: Direct-Access ANSI SCSI revision: 02

The highlighted text in red shows that the usb drive (thumb drive) is detected. Note that in real situation, the text is in white colour (default) not red. It’s highlighted for the sake of learning. You can see the detail in Host, Vendor and Type. If Linux can’t detect the usb drive and the usb drive data cannot be found in /proc/scsi/scsi, run rescan-scsi-bus -l from Slackware command line terminal. Below is the example:

root@slackware:~# rescan-scsi-bus -l
Host adapter 2 (ata_piix) found.
Host adapter 3 (ata_piix) found.
Host adapter 4 (ata_piix) found.
Host adapter 5 (ata_piix) found.
Host adapter 6 (pata_marvell) found.
Host adapter 7 (pata_marvell) found.
cat: /sys/class/scsi_host/host8/proc_name: No such file or directory
Host adapter 8 () found.
cat: /sys/class/scsi_host/host9/proc_name: No such file or directory
Host adapter 9 () found.
Scanning SCSI subsystem for new devices
Scanning host 2 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning for device 2 0 0 0 ...
OLD: Host: scsi2 Channel: 00 Id: 00 Lun: 00
      Vendor: ATA      Model: WDC WD1600AAJS-0 Rev: 05.0
      Type:   Direct-Access                    ANSI SCSI revision: 05
Scanning host 3 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning for device 3 0 0 0 ...
OLD: Host: scsi3 Channel: 00 Id: 00 Lun: 00
      Vendor: HL-DT-ST Model: DVDRAM GSA-H62N  Rev: CL00
      Type:   CD-ROM                           ANSI SCSI revision: 05
Scanning host 4 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning for device 4 0 0 0 ...
OLD: Host: scsi4 Channel: 00 Id: 00 Lun: 00
      Vendor: ATA      Model: ST3250820SV      Rev: 3.AC
      Type:   Direct-Access                    ANSI SCSI revision: 05
Scanning host 5 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning host 6 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning host 7 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning host 8 channels 0 for  SCSI target IDs  0 1 2 3 4 5 6 7, LUNs  0 1 2 3 4 5 6 7
Scanning for device 8 0 0 0 ...
NEW: Segmentation fault
root@slackware:~#

2. The next step is to check with dmesg command to see what drive your thumb drive is. From the command line, type dmesg | grep sd (dmesg pipe grep sd). See example below:

     root@slackware:~# dmesg |grep sd 
     SCSI device sda: 156250000 512-byte hdwr sectors (80000 MB) 
     SCSI device sda: drive cache: write back 
     SCSI device sda: 156250000 512-byte hdwr sectors (80000 MB) 
     SCSI device sda: drive cache: write back 
     sda: sda1 sda2 < sda5 sda6 sda7 > 
     Attached scsi disk sda at scsi0, channel 0, id 0, lun 0 
     SCSI device sdb: 1007616 512-byte hdwr sectors (516 MB) 
     sdb: Write Protect is off 
     sdb: Mode Sense: 23 00 00 00 
     sdb: assuming drive cache: write through 
     SCSI device sdb: 1007616 512-byte hdwr sectors (516 MB) 
     sdb: Write Protect is off 
     sdb: Mode Sense: 23 00 00 00 
     sdb: assuming drive cache: write through
     sdb: sdb1 
     Attached scsi removable disk sdb at scsi2, channel 0, id 0, lun 0 
     root@slackware:~#

If you installed KDE, thumb drive or usb drive will be detected automatically when you plug it in. You can check what drive your thumb drive represents by looking at the device property. Here are steps on how you can check your thumb drive name from x-window kde or gnome:

Step 1 – Open System from kde desktop.

Open system image

Step 2 – Open Storage media.

Open storage media image

Step 3 – Right-click thumb drive icon and choose Properties. The thumb drive name displays at the top of the newly open pane (Properties title).

Thumb drive properties image

3. Now you can ‘su’ and create a proper directory to mount your thumb drive in /mnt directory. The standard form of the mount command, is mount -t type device dir. This tells the kernel to attach file system found on device (-t option for file system type) at the directory dir. The file system types which are currently supported include: adfs, affs, autofs, cifs, coda, coherent, cramfs, ebugfs, devpts, efs, ext, ext2, ext3, hfs, hfsplus, hpfs, iso9660, jfs, minix, msdos, ncpfs, nfs, nfs4, ntfs, proc, qnx4, ramfs, reiserfs, romfs, smbfs, sysv, tmpfs, udf, ufs, umsdos, usbfs, vfat, xenix, xfs, xiafs.

From the command line, type mount -t vfat /dev/sdb1 /mnt/usb and enter. Change directory into /mnt/usb directory.

NoteReplace sdb1 with your thumb drive name and /mnt/usb with your mount directory.

     bill@slackware:~$  
     bill@slackware:~$ su -  
     Password:  
     root@slackware:~#  
     root@slackware:~# mount -t vfat /dev/sdb1 /mnt/usb  
     root@slackware:~# cd /mnt/usb 
     root@slackware:~# ls 
     nbtscan-1.5.1a/ snort-2.0.5.tar.gz  
     nbtscan-1.5.1.tar.gz wintest*  
     root@slackware:~#

If it’s not working, or you are not sure of file system type, just ignore the -t option. Try this instead: mount <device> <destination>:

     root@slackware:~# mount /dev/sdb1 /mnt/usb  
     root@slackware:~# cd /mnt/usb 
     root@slackware:/mnt/usb# ls ls 
     nbtscan-1.5.1a / snort-2.0.5.tar.gz   
     nbtscan-1.5.1.tar.gz  wintest *  
     root@slackware:~#

If you want to access usb drive in Ubuntu using terminal, Ubuntu desktop automatically mount usb drive in /media/disk. So what you have to do is just cd into /media/disk directory.

Linux unmount usb drive

umount – The umount command detaches the file system(s) mentioned from the file hierarchy. A file system is specified by giving the directory where it has been mounted. Giving the special device on which the file system lives may also work, but is obsolete, mainly because it will fail in case this device was mounted on more than one directory.

Note that a file system cannot be unmounted when it is `busy’ – for example, when there are open files on it, or when some process has its working directory there, or when a swap file on it is in use. The offending process could even be umount itself – it opens libc, and libc in its turn may open for example locale files. A lazy unmount avoids this problem.

To unmount file system or devices, you must be out of the directory you want to unmount. Type cd and enter to go to the user’s home directory. Then perform this command:

     root@slackware:/mnt/usb# cd
     root@slackware:~# umount /mnt/usb/  
     root@slackware:~#

Replace the target directory with the location where you mounted your usb device or thumb drive directory. If there is no error, your device should be unmounted now. you can try listing the directory again to be sure:

root@slackware:~# umount /mnt/usb/
root@slackware:~# ls /mnt/usb/

You can check Cannot unmount dvd – Device is busy for more information about umount problem. It is a tutorial about unmonting cdrom/dvd device.

 

OR
USB storage devices are shown as SCSI drives in Linux, so if you have more than a SCSI device you can find different device names (/dev/sdXX where XX depends on your hardware). In this example I’ve chosen the first device in the SCSI chain (/dev/sda1)

  1. Open a console window (under KDE is called konsole)
  2. Login as root: type su and enter the password
  3. Change directory: cd /mnt
  4. Create a new directory: mkdir usbkey (if not exists)
  5. Try to mount your USB-key: mount /dev/sda1 /mnt/usbkey
  6. If it doesn’t works you may try another device (e.g. /dev/sda2)
  7. If it works you can list the files in the key: ls /mnt/usbkey
  8. Unmount the device: umount /mnt/usbkey
  9. Open for edit the file /etc/fstab with a text-editor
  10. Add this line: /dev/sda1 /mnt/usbkey vfat noauto,users,rw,umask=0 0 0
  11. Save and close the file
  12. Leave the root user: press CTRL+D or enter the command exit
  13. Now you can mount the key from your account: mount /mnt/usbkey
  14. For unmounting the key: umount /mnt/usbkey

Thank  you for reading

About pacesettergraam

A good and realistic person

Posted on February 16, 2013, in linux and tagged , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: