Donate to us!
Things are more like they are now than they have ever been before. - Dwight D. Eisenhower
Thursday, April 26, 2018
 Need Help?
Members Online
Total Online: 68
Guests Online: 68
Members Online: 0

Registered Members: 104995
Newest Member: SNOWSTORM234
Latest Articles

Automatically Mounting Hard Disk Partitions at Start-Up on Linux

Arrow Image How to mount a partition automatically on Linux.

--- Introduction ---

After recently upgrading my Ubuntu Linux to Ubuntu 8.10, I realised that my Windows partition no longer mounted on start-up and that I had to manually mount it to view its contents. This is just an inconvenience, so I decided to mount it automatically on start-up.

--- Section 1 : What is Mounting? ---

Under Ubuntu and other Linux and Unix-like systems, partitions must be 'mounted' before they can be accessed. Mounting is simply the process of telling the Operating System that a certain partition exists. Mounting also tells the Operating System what the partition is, and where in the file-system it should be placed.

--- Section 2 : The Basics ---

There are a variety of ways to mount a partitions automatically. We are going to be learning how to do this manually. You will need to have a basic understanding of how Linux works.

Firstly, we need to take a look at the system's physical information. To do this, go to terminal and type in:

sudo fdisk -l

You will be asked for the system's root password: type this in and press enter. You should now have a list of all of the hard disks and partitions on your system. So now that we have a list of all of the disks, which one do we need to mount? Most systems will only have /dev/hda (hard disk) and /dev/hdc (CD-ROM). If you have more than one hard drive then you may see /dev/hdb (hard disk 2 0:1) etc.

Note: if you use SCSI and S-ATA disks, you will probably see something like sda and sdb.

To choose a system to mound, look through the list that you have just generated and look at the "System" column in particular. This will give you a clue as to what file system the disk is using, eg:

W95 FAT32 = Microsoft FAT32
(HPFS)/NTFS = Microsoft NTFS (Windows XP+)
Apple_HFS = Apple HFS (Apple OS)

In this article I will be showing how to mount a Windows partition. My fdisk outputted the following:

Device Boot Start End Blocks Id System
/dev/sda1 1 491 3711928+ b W95 FAT32
/dev/sda2 * 492 13610 99179640 7 HPFS/NTFS
/dev/sda3 13611 20673 53396280 5 Extended
/dev/sda5 13611 20499 52080808+ 83 Linux
/dev/sda6 20500 20673 1315408+ 82 Linux swap / Solaris

Look, we can see "HPFS/NTFS" which must be my Windows partition, device is /dev/sda2.

--- Section 3 : Preparation ---

Before we can mount the partition we need to prepare. We want to mount this partition at /media/windows_partition, so first we need to check whether or not it exists. Simply enter the following into the terminal:

ls /media/windows_partition

If it already exists, you will either have nothing returned or a list of files. If an error such as "No such file of directory" is returned, then the directory doesn't exists (yet). If the location already exists modify it to something that doesn't.

Now, we need to created the directory, into terminal type the following:

sudo mkdir /media/windows_partition

Now that we have done this we can move on to added the partition to the filesystem table

--- Section 4 : Editing the Filesystem Table ---

In most Linux systems, the file system table is located in '/etc/fstab'. To edit this type the following into terminal:

sudo gedit /etc/fstab


sudo nano /etc/fstab

Now that we have the table open, we can start editing (note: be careful as you can end up breaking the system if you mess about here). I'm not going to go through all of the sections of fstab here, I will only into the basics. For more detailed instructions type "man mount" into the terminal.

To add my Windows partition, I will have to add the following line to fstab:

/dev/sda2 /media/windows_partition ntfs user,fmask=0111,dmask=0000 0 0

The first part is the device (we found this earlier), the second part is where we mound this to (we created this earlier) and the third part is the file system (we found this earlier). Don't worry about the last part of the line, these are just options, "man mount" for more information.

That's it. All you need to do now is reboot the system, and you will have the device mounted on start-up. I hope you enjoyed the article.


c4p_sl0ckon March 22 2009 - 19:30:24
The article gave what it promised, no grammar errors that I could find and not too much BS. Very good according to me.
fuseron March 23 2009 - 06:41:28
Quite good, imo.
spywareon March 23 2009 - 17:35:01
Meh. Ubuntu + Gedit/nano + didn't cover what could go wrong while doing this. Getting a "very good" from me, cause it's Linux on HBH, and we should cherish that. Could be a little more "complete" though.
mastergameron March 23 2009 - 23:07:45
the file system is located in '/etc/fstab'
Might wanna correct that.
digitalchameleonon March 24 2009 - 10:13:10
"Don't worry about the last part of the line, these are just options," Could have been a little more in depth here, explaining what they were. Nicely done, get's a good from me.
jjbutler88on March 25 2009 - 00:13:55
Nice summary, and indications of where to go for more info. Very good from me
Sabrewulfon March 26 2009 - 19:17:45
Good rating from me.
stealth-on June 30 2009 - 19:53:53
I think it could have been more in depth, such as explaining partitions and how to mount different file system type and what difference the options make, however i'm glad to see linux articles on hbh so I will give it Very good. Keep it up, backslash
Post Comment


You must have completed the challenge Basic 1 and have 100 points or more, to be able to post.