Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Automatically Mounting Hard Disk Partitions at Start-Up on Linux


Automatically Mounting Hard Disk Partitions at Start-Up on Linux

By ghostghost | 11797 Reads |
0     0

— 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

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'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.

Comments
ghost's avatar
ghost 15 years ago

The article gave what it promised, no grammar errors that I could find and not too much BS. Very good according to me.

fuser's avatar
fuser 15 years ago

Quite good, imo.

spyware's avatar
spyware 15 years ago

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.

ghost's avatar
ghost 15 years ago

the file system is located in '/etc/fstab' Might wanna correct that.

ghost's avatar
ghost 15 years ago

"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.

ghost's avatar
ghost 15 years ago

Nice summary, and indications of where to go for more info. Very good from me

ghost's avatar
ghost 15 years ago

Good rating from me.

stealth-'s avatar
stealth- 15 years ago

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