How to mount and unmount usb drive or thumb drive in Linux

This is a guide on how to mount and unmount thumb drive or usb drive in Linux operating system. Some Linux distributions such as Ubuntu desktop will automatically mount the usb drive while others like Slackware does not. So here is all information you need about mount and unmount usb drive in Linux.

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.

[email protected]:~# 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:

[email protected]:~# 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
[email protected]:~#

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:

[email protected]:~# 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

[email protected]:~#

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.

Note - Replace sdb1 with your thumb drive name and /mnt/usb with your mount directory.

[email protected]:~$
[email protected]:~$ su -
Password:
[email protected]:~#
[email protected]:~# mount -t vfat /dev/sdb1 /mnt/usb
[email protected]:~# cd /mnt/usb
[email protected]:~# ls
nbtscan-1.5.1a/ snort-2.0.5.tar.gz
nbtscan-1.5.1.tar.gz wintest*
[email protected]:~#

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>:

[email protected]:~# mount /dev/sdb1 /mnt/usb
[email protected]:~# cd /mnt/usb
[email protected]:/mnt/usb# ls ls
nbtscan-1.5.1a / snort-2.0.5.tar.gz
nbtscan-1.5.1.tar.gz wintest *
[email protected]:~#

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:

[email protected]:/mnt/usb# cd
[email protected]:~# umount /mnt/usb/
[email protected]:~#

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:

[email protected]:~# umount /mnt/usb/
[email protected]:~# 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.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.