# How to 'mount' additional drives in linux



## massahwahl

I thought I would share this little 'how to' because its something I struggled to understand when I first started into the world of linux. So lets get started!

First, we need to understand how linux addresses new drives and how it differs from the way windows does. Plugging in a device to a windows computer will create a directory for it in 'My Computer' so that going to 'My Computer' will display a listing of all available drives separated into their own individual devices by a drive letter. 

Linux on the other hand uses a process called 'mounting' that lets the user specify a unique place for the drive to appear at. Linux does not have a 'My Computer' section that lists available drives so we have to tell the OS where we want these drives to go in the file tree. The advantage to this is that you can specify several drives going to the same place so they act as one essentially. In the case of my HTPC running MythBuntu I have DVD movies ripped on my main hard drive and on two external hard drives. Instead of telling Myth to search three separate folders to find the movies, I mounted all three to one central location so that all the movies show up there together even though they are physically located on three different hard drives. Theres about a million other uses for this neat function, but lets learn how to do it first!

Before we begin, make sure you have a device ready that you want to mount. This can be an external hard drive, a USB drive, etc. and go ahead and plug into your computer.

Hey wait! It just appeared on the desktop! WTF?? 

Dont worry its supposed to! It may even let you open it and pull files off of it. Although if you try to write any files to it you will be met with the unpleasant message warning you that you need read/write permission.  I cant lie and say I understand why linux sometimes allows you to open these drives without mounting them first, but I do know its only a brief miracle. If you restart the computer with the drive plugged in it will be rendered unopenable by the OS the next time. Therefore, regardless of whether you can currently open the drive we need to make it permanently mountable.

Go ahead and open your terminal (In ubuntu its located under Applications>Accessories>Terminal)

Im going to be mounting an external 80gig hard drive in this demonstration.

With all your drives plugged in that you want to mount, go ahead and type:

sudo fdisk -l

This will create a list of all drives currently attached to your computer that can be mounted so heres mine:

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000e6837

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1459    11719386   83  Linux
/dev/sda2            1460       60801   476664615    5  Extended
/dev/sda5            1460        1583      995998+  82  Linux swap / Solaris
/dev/sda6            1584       60801   475668553+  83  Linux

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x27dae78d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       60801   488384001   83  Linux

Disk /dev/sdc: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xbd49c832

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        9729    78148161   83  Linux

You will notice that al ltheir extensions begin with /dev which points to the 'devices' directory which is the closest thing to a 'My Computer' that linux has. after /dev you see that each drive has its own 'listing' which separates the physical drives apart. If you look under my 'sda' listing you will notice that it gets split up even further into 'sda1'-'sda6' each of these numbered listings have to do with the OS and where it creates mount points for different sections of the drive. In theory we can do this with any mountable drive but it gets a little complicating so for now were just going to mount the entire drive to one place instead of breaking it apart. As I said before, I want to mount my 80 gig hard drive defined by this listing:

Disk /dev/sdc: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xbd49c832

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        9729    78148161   83  Linux

I previously had this drive on another linux computer and had it formatted to the XFS file system so yours will likely say something different under 'system' If your coming from windows, most likely it will say 'NTFS' since that is the standard windows format. 'NTFS' tends to not always play very nice with linux, but with this guide you should not have any issues getting it to boot properly.

For now, take note of the drives 'sd' listing, in my case it is 'sdc1'

Now were ready to mount this bad boy! Our next step is to edit our 'fstab' which will let us define where we want our Mount Point to be.

Type this into your console:

sudo mousepad /etc/fstab

This will open a text document and display a bunch of information about different drives on our system. For example, heres mine:

# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
# /dev/sda1
UUID=a6c7459d-5273-4f0a-8da5-d83fb212e1e8 /               ext3    errors=remount-ro 0       1
# /dev/sda6
UUID=791a376f-c97a-4147-936a-b4292ec5aaf7 /var/lib        xfs     defaults        0       2
# /dev/sda5
UUID=b839a63b-b101-4875-994d-f2403bd165f5 none            swap    sw              0       0
/dev/scd0       /media/cdrom0   udf,iso9660 user,noauto,exec,utf8 0       0
/dev/sdb1 /media/EXT_HD xfs defaults 0 2


What we need to do is create a new listing for the drive we are adding. Earlier I found out that my drives name is /dev/sdc1 so that is what I need to put into the first part of my addition directly under the last drive listed:

/dev/sdc1

Then Im going to spacebar once and tell the fstab where I want this drive to be mounted to. This drive holds all of my music, so Im going to put it in /media/music. In your case, you can create any directory that you want regardless of whether it exists yet or not. If you create one that does not exist on your system yet we will be adding in a step to come.

So heres what I have so far:

/dev/sdc1 /media/music

The next part of the listing tells the fstab what file system is used on the drive. In my case, 'xfs' yours most likely will be 'ntfs' refer to the information we found earlier when we ran sudo fdisk -l. Which ever system your using, spacebar once and add it.

/dev/sdc1 /media/music xfs

Almost done with the fstab! You dont need to worry about the last two sections of your entry, just copy them verbatim from here to make your entry look like mine:

/dev/sdc1 /media/music xfs defaults 0 2

the defaults and numbers do have a purpose, but for the sake of this guide just ignore them. That is exactly how your entry should look only replaced with 'sd' information that we found earlier for your drive, where you want it mounted and finally what file system yours is using. 

One more example: Lets say I had an ntfs drive that I wanted mounted as a 'documents' listing to my desktop, my entry would look like this:

/dev/sdc1 /home/[your username]/desktop/documents ntfs defaults 0 2

(I hope your understanding this, if not message me and i will help you out)

Now that our drive has an fstab listing, its time to create a listing for the mount point we specified. Again, change this information to reflect the mount point we specified for your drive in the fstab listing

Type this in console:

sudo mkdir /media/music

replacing /media/music for whatever YOU put for the second part of your fstab listing. If you had /home/[username]/desktop/documents put that or whatever listing you specified. IT MUST BE THE SAME AS THE FSTAB LISTING! and it is case sensitive. 

next, type this in console:

sudo chmod 777 /media/music

replacing /media/music for whatever YOU put for the second part of your fstab listing. If you had /home/[username]/desktop/documents put that or whatever listing you specified. IT MUST BE THE SAME AS THE FSTAB LISTING! and it is case sensitive. 

The 'chmod 777' gives us full read/write access to this directory which is crucial to doing anything with it. 

With that, were done! You should have no problems opening and editing files off the disk and it should stay in place after a reboot or unplug as well. If you have any questions or comments, let me know!


----------



## massahwahl

In a future update ill explain mounting by UUID


----------

