Sunday, December 20, 2009

How to mount external media in Linux via Console

Most of the modern Linux distros can easily detect & mount external drives automatically. In extremely rare case they may fail to mount. At such times, knowing how to manually mount the external drives will come handy. This simple guide will show you to mount external drives like pendrive, external hard-disks, card reader etc in Linux.
First insert the drive in the USB port & then issue the following command as root;
fdisk –l (That’s an ‘L’ not an ‘i’)
This will list all the storage devices attached to your computer including your internal hard-disk. Now look for an entry below your hard-disk & make a note of the device address. It would most probably be /dev/sdb1if you just have a single hard-disk installed in your computer.
In Linux, each device has is represented by a file. So before we can mount anything we need to create a location also known as mount point. So to mount the pendrive create a new folder “pendrive” under /media. You can give any name to the folder it doesn’t matter. This can be done by issuing,
mkdir /media/pendrive
Now that our mount point is created, we need to mount the pendrive at this point to make it accessible. So issue the following command;
mount “media address” “mount point”
In our example the media address is “/dev/sdb1″ & mount point is “/media/pendrive”. So the command to mount the pendrive in our case will be;
mount /dev/sdb1 /media/pendrive
After that your pendrive should be mounted at /media/pendrive & you can view its content by navigating through file manager or via issuing;
ls /media/pendrive
After your are done working with the external drive, it needs to be unmounted before you can unplug it from the USB. To unmount the pendrive issue;
umount /media/pendrive
Do remember to close all the active applications running from the external drive or the unmount will fail.
Source: linux.gauravlive.com