Mounting drives under linux. - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Linux and Open Source
Click Here to Login
Thread Tools Display Modes
Old 07-06-2009, 09:03 PM   #1 (permalink)
Wizard Techie
Join Date: Sep 2005
Location: /home/jason
Posts: 3,056
Send a message via AIM to Jayce
Default Re: Switching from XP to Ubuntu, how to?

The reason you got the errors with the mount command is because you didn't complete the command. You told Linux to "Hey! Ubuntu! Mount this!.........."

Ubuntu sat there wondering what "this" was.

A completed mount command looks like this:

sudo mount /dev/sdb1 /media/localbackup

Breaking down the command piece by piece, we have several sections. I'm not sure how much you understand by this command but I figured if thirty seconds of typing helps ya out, awesome. If you already know this, so be it. :P

Sudo - Root user. Superuser priviledges. Think of it as you telling the computer "Just ****ing do what I tell you."

mount - The actual "command" that is issued.

/dev/sdb1 - dev is known as "device" and sdb1 is the hard drive ID. You can see your hard drive ID in GParted (Gnome Partition Editor - weapon of mass destruction, be careful with it) along with the command "sudo fdisk -l" in terminal.

/media/localbackup - the destination. You create this destination with the "sudo mkdir" command (mkdir = make directory). Example - sudo mkdir /media/localbackup. This issues a folder called "localbackup" to be within the "media" directory. Localbackup is simply the name of the mount point. Customize this to what YOU would like. Localbackup is just an example from my system.

[NOTE] - Always remember - source first, destination second. You are mounting /dev/sdb1 (source) to /media/localbackup (destination), that's why they appear /dev/sdb1 /media/localbackup and not the other way around.

So now we've dissected the "sudo mount /dev/sdb1 /media/localbackup" command. You can customize this command to whatever you want to do. Is your drive /dev/sdc1? No problem. Plug that in place of /dev/sdb1. Along with your mount point (/media/localbackup), name it whatever you want when you create it.

So where are we at now? You have the hard drive, you have the mount point, but now you need to tell the system to automatically mount the drive each time you boot up so its always accessible. That's what /etc/fstab is (fstab is file system table, located in the /etc directory).

You need to edit this file, using an editor such as gedit. I use gedit for almost everything.

Command is - sudo gedit /etc/fstab

And presto. Your fstab file shows up. This is where you add the entry for your drive. This is very easy, but make sure you do it accordingly to what the Ubuntu documentation says. Otherwise it won't mount when you boot up.

This is the entry that Ubuntu suggested:

/dev/sdb1 /media/mynewdrive ext3 defaults 0 2

Customize this to YOUR needs. Is /dev/sdb1 your drive? If not, change it. What is your mount point? Is it /media/mystuff? If so, change it here. The section where ext3 is is simply the file system. If you are running Ubuntu ONLY, ext3 should be just fine. ALL of my drives use ext3. If you are running another file system such as fat32, it should be noted here, but I believe fat32 is noted as "vfat", however I'm not positive. ALSO - Please note, there is a newer file system out known as ext4 (newer than ext3). You can use that if you wish. I personally chose not to until the future release of Ubuntu this fall due to the fact ext4 is new and I'd rather wait a bit. Just keep in mind to tag in /etc/fstab whatever file system is on that hard drive.

Personally, what I do is I add a comment tag in there too so I know what I'm doing. This may or may not be something you want to do, but I like doing this with having 4 drives in my PC. The first backup drive in my system shows up as follows in /etc/fstab:

#Local Backup Drive
/dev/sdb1 /media/localbackup ext3 defaults 0 2

Anything before # in that particular line doesn't show up, so I use the #EnterTextHere feature so I can keep organized with my stuff.

Now... where are we at now? You have a mount point. You have the drive. You have /etc/fstab adjusted accordingly. What about permissions? I wouldn't advise messing with permissions on the drive unless you have any issues accessing it locally. However, I adjusted my permissions on my drives in a certain manner since I have network users who attach to some of the drives. The important thing is that you are the owner. If you right click on the mount point (AFTER it is mounted, that is) and hit the permissions tab you can see what's listed there. Are you the owner? If it's root, I suggest changing it.

sudo chown -R jayce /media/localbackup

sudo - root
chown - change ownership
-R - recursively
jayce - whatever user you want to own that folder
/media/localbackup - directory you're applying these changes to

Now... if you followed these steps accordingly... whenever you boot, your drive should be easily accessible in the /media/WhateverYouNamedIt directory. Unlike Windows where it just plops the drive in (which is convenient, but far less customizable) you have more control over what your computer is doing. In my case, I have 3 backup drives. 1 for me, and 2 for network storage for other computers. I need to tell these drives apart, so I mount them to specific shares. With Windows, I suppose I could just have their Local Disk - D or Local Disk - E drives to tell them apart, but it's much easier to look at my disk usage analyzer and see drives labeled "Localbackup" and "Storage" and "Storagebackup".

So overall, this is what you did.

-Create a mount point for your drive.
-Added the hard drive to /etc/fstab to auto-mount upon system bootup.
-Changed ownership if the mount point, though, this may not be needed if you are already the owner.

This is a process that honestly takes about 30 seconds to do if you have done it before. Doing it the first time can seem a little cumbersome and sketchy. Another thing to throw out there is that if your drives are plugged in to your system when you install Ubuntu, this entire process can be automated. When you hit the partitioning section (using the manual partition mode option) you can select each drive accordingly and select its mount point. It'll add all of the nitty gritty details to /etc/fstab automatically for you, as we did manually above. Of course, please note, if you are installing Ubuntu on drive "A" and you don't want drive "B" formatted, which has data on it, make sure you don't check the "format" option for it. But don't worry about that until you get to that point.

For now, this should get you rolling. Post back if you have any issues.

Jayce is offline   Reply With Quote
Old 07-08-2009, 06:11 AM   #2 (permalink)
Lord Techie
Kharn's Avatar
Join Date: Feb 2007
Posts: 7,638
Default Re: Mounting drives under linux.

Jayce - superb I have split this to it's own thread and made it a sticky.

Visit this and do something for the world!

Want to do even more? Take a look here and join the fight on human trafficking.

Hear and you forget, see and you remember, do and you understand.

Kharn is offline   Reply With Quote
Old 03-21-2013, 02:13 PM   #3 (permalink)
Wizard Techie
Join Date: Sep 2005
Location: /home/jason
Posts: 3,056
Send a message via AIM to Jayce
Default Re: Mounting drives under linux.

It's been almost 4 years and only now I realized I didn't include the UUID bits. It's recommended to use UUID when mounting drives automatically via fstab because UUID is like a unique identifier to the disk. This is done by issuing the "blkid" (that's BLKID but in lowercase) in terminal as root. This will fire out the UUID's for each device on your system. Then, instead of /dev/sdb1 being the actual device for fstab, you can use UUID. You can see this with other examples of your fstab already if you take a look: cat /etc/fstab

So instead of doing:

/dev/sdb1 /home ext4 defaults 0 2
You can use the UUID of /dev/sdb1 instead:
UUID=5f01edae-3c60-46bc-ab2f-a4414123fb639 /home ext4 defaults 0 2
Your devices can be changed if the arrangement of your disks inside your system are changed. So if you have 4 drives, meaning sda sdb sdc sdd, and you remove sdc, suddenly sdd is likely to bump up and be seen as sdc. This of course is not good because you could be writing data to the wrong drive. UUID ensures the correct drive will be chosen for the specific mount point.

Moving on to a slightly more complex topic, you can do the same thing with a RAID array in regard to UUID's and automatic mounting with fstab. I run RAID via mdadm, which is a Linux based software RAID package found in the repos. Mdadm is not installed in Ubuntu by default, so installing Ubuntu fresh does not allow me to mount my RAID array as my home directory right there during the installation. In my system I have 3 drives.

64GB SSD for /
2x1TB in RAID 1 for /home

But like I said, if mdadm isn't installed by default, how will Ubuntu know that your /home is really on separate drives? Blunt answer: It won't. Don't worry, easy work around. I install Ubuntu by using the manual partitioning method. That way I can see the table and see my two 1TB HDD's and see that they are not checked to be formatted. Don't even touch them, just work with the drive getting Ubuntu installed on it and move on. I also don't even bother splitting root ( / ) and /home, I just add swap, /, and that's it. When the installation is complete, install mdadm (sudo apt-get install mdadm) and reboot. Once you reboot, your RAID array will be detected. Now that it's detected, you have to set it up in fstab to be automatically mounted to /home on boot.

RAID arrays with mdadm are seen as /dev/md* instead of /dev/sd* in terminal. aka, /dev/sdb1 is a disk, while /dev/md0 or /dev/md127 is clearly a RAID array which can contain any number of disks. Run sudo blkid, find the UUID of your array, and add an entry to fstab just like what was listed above. If your UUID for /dev/md0 or /dev/md127 (whichever you may have) is 5f01edae-3c60-46bc-ab2f-a4414123fb639, then add it like so:

UUID=5f01edae-3c60-46bc-ab2f-a4414123fb639 /home ext4 defaults 0 2

Bottom line is this... the UUID is a unique identifier for the disk. On the other hand, /dev/sdb could easily change to be /dev/sdc, or /dev/sdd, etc. It all depends on how the system arranges the drives upon boot and what drives are available during boot. UUID will be safer to use and quite honestly, I don't know of any reason not to use UUID's since it's just as easy as using /dev/sdb1, etc. But like I said, UUID's come with greater reliability since UUID's don't change randomly.
There's no place like /home.
Jayce is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Useful list of Linux websites. tribalsun Linux and Open Source 39 03-22-2015 03:54 AM
Fundamental Differences Between Linux and Windows Osiris Linux Tips and Tricks 0 12-11-2008 05:13 PM
The five best things in Linux 2.6.27 Osiris Linux Tips and Tricks 2 10-21-2008 08:13 PM
New with Linux MindHacked Linux and Open Source 8 04-16-2008 08:18 PM
Want to make the move to Linux for good...advice? BoysNightOut Linux and Open Source 25 05-16-2007 10:40 AM

Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 06:22 PM.

Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.