Saturday, April 09, 2005

Mounting drives in Linux

This is a small tutorial on mouting drives in linux
I had written this document some time back for my linuxuser group
now i am re-writing this document with some changes

There is no substitute to man pages in linux. there is an exhaustive collection of information over there.

To start with, first of all you need to see which partition you want to mount

YOU can see that by running the following command at bash# prompt


#fdisk -l


If your hard disk is use

Primary master hda

Primary slave hdb

Secondary master hdc

Secondary slave hdd


If you use wrong device then you may get error message such as

"Cannot open device hdc"

If command is successful you get


[root@gaurav qmail]# fdisk /dev/hda


The number of cylinders for this disk is set to 4865.

There is nothing wrong with that, but this is larger than 1024,

And could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):


At this prompt run ‘p’ single character to see your partition table


Here is the result of my partition table


Command (m for help): p

Disk /dev/hda: 40.0 GB, 40020664320 bytes

255 heads, 63 sectors/track, 4865 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes


Device Boot Start End Blocks Id System

/dev/hda1 * 1 561 4506201 b Win95 FAT32

/dev/hda2 562 3939 27133785 f Win95 Ext'd (LBA)

/dev/hda3 3940 4385 3582495 a5 FreeBSD

/dev/hda4 4386 4865 3855600 83 Linux

/dev/hda5 562 1096 4297356 7 HPFS/NTFS

/dev/hda6 1097 1606 4096543+ b Win95 FAT32

/dev/hda7 1607 3008 11261533+ b Win95 FAT32

/dev/hda8 3009 3872 6940048+ b Win95 FAT32

/dev/hda9 3873 3939 538146 b Win95 FAT32



You can easily recognize which drive you want to mount

Here I have my windows partitions as

devices Windows Partitions

/dev/hda1 C

/dev/hda5 D

/dev/hda6 E

/dev/hda7 F

/dev/hda8 G

/dev/hda9 H


Do not confuse with /dev/hda2

It is my extended partition you cannot mount that whole partition but you can only mount the logical drives in this partition


Here say if I want mount my E drive in Linux

I need to have an empty folder somewhere to mount.

We can make a folder anywhere but as going by the convention we make all the folders and mount them in

/mnt folder

So, go to the mnt folder under root directory

Make a new folder in mnt directory say win_e


If you want to mount it temporarily (till the system is running)

You can mount it by the following command


#mount /dev/hda6 /mnt/win_e


The syntax of the command is easy to interpret

/dev/hda6 gives the device you want to mount

/mnt/win_e gives the path of folder you want to mount

to mount a device with some other options ,for example i can mount my cdrom in two styles


#mount /dev/cdrom /mnt/cdrom

this will mount the cdrom as a filesystemn as define in /etc/ftab which is generally iso9660
if i want to mount this CDrom with the
cdfs filesystem then i need to do this as

#mount -t cdfs /dev/cdrom /mnt/cdrom


Now if you want to mount your partitions your drives permanently you can do that by making an entry in /etc/fstab file

This file is read each time the system boots.

And so it mounts the partitions listed in this drive

You can add an entry to this file as under corresponding headings


/dev/hda9 /mnt/win_h auto defaults 0 0



the above line refers to

/dev/hda9: gives the device

/mnt/win_h: gives the path of the folder

auto: tells to detect the filesystem automatically

defaults, 0 0 : these two basically deal with the type of mounting we are performing and where we want to dump the partiton


Lines of caution

1. Do not delete any existing entries of /etc/fstab file, it will be good if you take a backup of the fstab file and then

Perform any changes.

If something goes wrong in that file the system may not boot up (in the worst case)


2. While using the fdisk command

Be careful and do not try other options other than the p command


Command (m for help): p


If you r not sure of what you r doing.


3. After updating the fstab file if during startup you get error of some sorts that e.g.

/mnt/win_g not found, mounting failed

Then check if you have made a folder in the given path and no spelling mistakes are there in your fstab file.


Comments are Welcome.


No comments: