Skip to main content

Mount a Drive using Command Line

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, '_translation_tab_access' was given in /home1/seonetas/public_html/neohide/includes/menu.inc on line 454.
Posted in

Mounting a drive using a command line can be really useful. Perhaps it might be even better than trying to search for specific utility tool that exists in KDE or Gnome desktop. Basically, mounting a drive is relatively simple (the same procedure can be performed on mounting a Windows Shared drive, i.e. Samba but which will be discussed later).

First of all, to understand more about drive mounting, you can type "man mount" or "mount --help" from the text console. To make life easier, I will give an example so as to simplify all these hassle, but reading up is still highly recommended.

(find out how to do it....)

It makes a lot of difference to know what drive you are mounting, and in what format the drive is. To find out what partition you have, you can use "fdisk" command to check (but use with extra care). Run the following command under root privilege.

fdisk -l

You will notice a list of devices, e.g. /dev/hdc1 and so on. From there you can double check the format of that partition.

For example, to mount a FAT32 partition that exists on /dev/hdc5 on a folder, say /mnt/fatdrive/, simply type in the following command line (with root privilege):

mount -t vfat /dev/hdc5 /mnt/fatdrive/

Brilliant! You have managed to mount the drive, but as normal user in Linux, you may not have permission to write (or even read) the partition. So, what you're going to do?

Okay, you have to give permission to yourself to write to that partition. First check your ID on your linux system by typing in:

id

From here, you will be able to find out what your user id, group id and even the various groups that you belong to.

For instance, if your uid=1000, then mount the drive with permission given to you to write on that FAT partition:

mount -t vfat -o uid=1000 /dev/hdc5 /mnt/fatdrive/

So, that's it! You can do so with other file formats, e.g. ext2, ext3,...etc, as well.

Note that, you are unable to write to NTFS partition, although recently there has been a release of ntfs-3g driver that allow linux operating systems to write on NTFS partitions. However, if you are running Ubuntu Feisty Fawn, you might be glad that this driver is part of the package for ease of installation. More instruction is available here.

To add on, mounting a Windows shared drive (Samba) requires you to install samba package. The following package is required to be installed: smbmount. Henceforth, mounting the samba drive is slightly different, but relatively easy too. For example,

mount -t smbfs -o username=myusername,uid=1000 //HOST_PC/HOST_FOLDER /mnt/drive

The above command indicates that the file system to be mounted belongs to a samba file system. The login username to the remote host system is first required to be specified, e.g. myusername. The host system is HOST_PC on folder HOST_FOLDER. That will be mounted on /mnt/drive folder.

As of the moment, I am writing this post from the Airport in Zurich catching the next flight to Singapore.