Automatically Mounting Hard Disk Partitions at Start-Up on Linux

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 &#39;mounted&#39; 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&#39;s physical information. To do this, go to terminal and type in:

sudo fdisk -l

You will be asked for the system&#39;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 &quot;System&quot; column in particular. This will give you a clue as to what file system the disk is using, eg:

Look, we can see &quot;HPFS/NTFS&quot; 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 &quot;No such file of directory&quot; is returned, then the directory doesn&#39;t exists (yet). If the location already exists modify it to something that doesn&#39;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 &#39;/etc/fstab&#39;. To edit this type the following into terminal:

sudo gedit /etc/fstab

or

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&#39;m not going to go through all of the sections of fstab here, I will only into the basics. For more detailed instructions type &quot;man mount&quot; into the terminal.

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

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&#39;t worry about the last part of the line, these are just options, &quot;man mount&quot; for more information.

That&#39;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.

Posted by on March 22 2009 - 12:50:11 | 8 Comments | 9564 Reads

Comments

c4p_sl0ckon March 22 2009 - 19:30:24The article gave what it promised, no grammar errors that I could find and not too much BS. Very good according to me.

spywareon March 23 2009 - 17:35:01Meh. 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.

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:55Nice summary, and indications of where to go for more info. Very good from me

stealth-on June 30 2009 - 19:53:53I 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

Sorry.

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

Hellbound Hackers is the collective work of the staff and the community and is therefore licensed under the CC BY-NC-SA license.