Techknow Study

mount and umount..

9:59:00 PM vikas 0 Comments Category : ,

How to mount and umount usb drive or thumb drive in Linux
This is the guide how to mount and umount the usb drive or thumb drive  in linux operating system.
first of all I give idea about what is mounting it means that to attach a file system in our O.S. to run the external drive or any extra peripheral device. Like in windows when we put a pen drive in the port windows directly accept the device and after the device work properly…..
Same as here {in linux} we need to mount the drive manually in our system. But here also the O.S. Ubuntu   will automatically mount the usb drive.
Like mounting we need umounting manually the usb drive.

Linux mount usb drive
Ø  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 mount a usb drive in linux

v  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.

     root~# 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  

v  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:~# dmesg |grep sd

v  Above  you see the example of  automatic mounting of  usb drive. But if the mounting process in not done automatically. It is necessary to do it manualy in our personal computer so ready for it…….
The standard format of 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/usbdrive /mnt/usb and enter. Change directory into /mnt/usb directory.

Ø  Note - Replace usbdrive  with your thumb drive name and /mnt/usb with your mount directory
     root:~# mount -t vfat /dev/usbdrive /mnt/usb  
     root:~# cd /mnt/usb
     root:~# ls
     nbtscan-1.5.1a/ snort-2.0.5.tar.gz  
     nbtscan-1.5.1.tar.gz wintest

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:~# mount /dev/usbdrive/mnt/usb  
     root:~# cd /mnt/usb
     root:/mnt/usb# ls ls
     nbtscan-1.5.1a / snort-2.0.5.tar.gz   
     nbtscan-1.5.1.tar.gz  wintest

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 umount 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:/mnt/usb# cd
     root:~# umount /mnt/usb/  
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: