Mounting an External USB Drive in Linux
Our previous two articles discussed why you need to have a backup plan in place, and how to setup a simple SHELL script to run your backup daily. Now I’ll explain how to mount your external hard drive from the Linux terminal.
After purchasing your external hard drive you need to plug it in to your server. If you have some sort of desktop installed like GNOME or KDE, they will typically detect your external drive and it will popup automatically on your desktop. However, this won’t happen from the command line, and you may have the auto-mount option turned off.
Finding Your External Hard Drive
Linux gives all external devices a name in the /dev folder and it can be tricky to determine exactly which device your external drive will mount to, however /dev/sda1 is pretty common for external hard drives. If you are unsure, simply type df into your terminal, it will list the amount of disk space available on your server and where it is located. It will list /dev/hda1, /dev/hda2 (if you have a second hard drive), and in our case, it also listed /dev/sda1 which was our external hard drive.
Mounting the External File System (Hard Drive)
To mount your hard drive you need to use the mount command. (To unmount the drive when you are ready to unplug it and take it home, use the umount command.) Here’s an example:
mkdir /mnt/usbdrive
mount /dev/sda1 /mnt/usbdrive
The above command first creates a directory in your /mnt folder, typically the folder will be descriptive of the device, so we use /mnt/usbdrive. This only has to be done once, as you won’t be deleting this folder. This folder will be your mount point for the external hard drive.
The second line mounts the device at the /dev/sda1 location to the /mnt/usbdrive directory.
Now you can reference your hard drive from the command line using the folder /mnt/usbdrive.
Automount In the Terminal
To have your hard drive mount each time your server is restarted, you must edit your /etc/fstab file. Simply add at the bottom of your /etc/fstab file:
/dev/sda1 /mnt/usbdrive ext3 defaults 0 0
The first argument (/dev/sda1) tells the system what device to mount, and the second argument (/mnt/usbdrive) tells the system where to mount it. The third argument is the filesystem type (ext3). The fourth argument (defaults) tells the system what options to apply to the device, so in this case we’ll just use the defaults. The fifth and sixth arguments (both zeros) tell the system if the filesystem should be backed up using the dump utility, and the second zero tells the system whether to process the device when fsck is run. We can leave them both to zero for now.
Now you have a mounted hard drive that you can use for all your company backups, and by reading our previous two articles you can setup a script to automate your backup.




September 25th, 2008 at 7:57 am
Goood work.This was excellent.
November 8th, 2008 at 2:41 pm
hi i am a student and am working with fedora core 4, i am trying to mount my external haqrdrive and its telling me that its unable to mount the device and when i click on show more details it says mount: unknown filesystem type ‘ntfs’
December 2nd, 2008 at 12:08 pm
Miguel, you’ve walked into a hornet’s nest. The ‘ntfs’ filetype means a Windows-formatted file system. Unfortunately, our friends at Red Hat do not compile their kernels with ntfs capability, in order not to annoy our good friends at Microsoft. It is possible to re-compile the kernel with the correct libraries in place, or actually find a kernel that’s already been updated at Dag Weers or another repository (Google it if the name is unfamiliar). Of course, Debian-based Linux distros already have the ntfs code in place, so a Live Disk like Knoppix or an easy-to-use distro like Ubuntu might help. Best of luck, and let us know how you do.
January 7th, 2009 at 2:36 pm
There is no need to recompile the kernel for adding support for ntfs. Follow the steps below.
Issue “uname -rp” to find out the exact version number, including smp if present (like 2.6.9-78.0.8.ELsmp), and the processor type (e.g. x86_64).
Find (say, search the http://rpm.pbone.net/) and download the rpm named “kernel-module-ntfs-.rpm”.
Run “rpm -ihv ”
Issue “ls /lib/modules/`uname -r`/kernel/fs/ntfs/ntfs.ko” - to make sure you have the module now.
Issue “insmod /lib/modules/`uname -r`/kernel/fs/ntfs/ntfs.ko”
Issue “lsmod | grep ntfs” to make sure the module is now in kernel and “cat /proc/filesystems | grep ntfs” to see the ntfs is now supported by kernel.
Now you can mount it like “mount -o ro umask=0002 /dev/sdd1 /mnt/ntfs”, provided you know the device name and the mount point exists.
Good luck!
January 7th, 2009 at 3:04 pm
In my previous message, parts in angle brackets just disappeared, so I’m repeating the same steps, with angle brackets replaced by braces, {}.
Issue “uname -rp” to find out the exact version number, including smp if present (like 2.6.9-78.0.8.ELsmp), and the processor type (e.g. x86_64).
Find (say, search the http://rpm.pbone.net/) and download the rpm named “kernel-module-ntfs-{version&proc_info}.rpm”.
Run “rpm -ihv {downloaded_file_name}”
Issue “ls /lib/modules/`uname -r`/kernel/fs/ntfs/ntfs.ko” - to make sure you have the module now.
Issue “insmod /lib/modules/`uname -r`/kernel/fs/ntfs/ntfs.ko”
Issue “lsmod | grep ntfs” to make sure the module is now in kernel and “cat /proc/filesystems | grep ntfs” to see the ntfs is now supported by kernel.
Now you can mount it like “mount -o ro umask=0002 /dev/sdd1 /mnt/ntfs”, provided you know the device name, and the mount point exists.
February 5th, 2009 at 8:20 pm
Can you advise how in command line entry do i
“…Simply add at the bottom of your /etc/fstab file:
/dev/sda1 /mnt/usbdrive ext3 defaults 0 0 …”
sorry I am very new to linux command lines. I would like to mount a USB drive and be able to use it for backup of my accounts data which is kept on the server, in case of hardware failure.
thanks
February 6th, 2009 at 12:43 pm
Hi John H,
You’ll have to be the root user, and then edit your /etc/fstab file. Make sure you make a backup as you might screw something up if you don’t the file properly. So you might want to just remember to mount it after you reboot your computer. Using this command:
mount /dev/sda1 /mnt/usbdrive
February 18th, 2009 at 6:49 pm
i just installed Kubuntu 8.10 and I am having trouble accessing my external hard drive. I go to open it in dolphin and i get this error message:
An error occurred while accessing ‘Garretts Dr’, the system responded: org.freedesktop.Hal.Device.Volume.UnknownFailure: $LogFile indicates unclean shutdown (0, 0) failed to mount ‘/dev/sdb1′: Operation not supported Mount is denied because NFTS is marked to be in use.
I am very new to linux and dont quite understand it all and i would apreciate it if someone could help me out with this
March 17th, 2009 at 7:39 am
I just received a USB hard drive and plugged it into my Linux server. Since I have another USB hard drive already installed, I do not know how to find out what the device name is when I plug it in. I need to know it in order to mount.
Advise is appreciated as I’m not very good at administration.
Chris
May 3rd, 2009 at 6:18 am
But I get:
special device /dev/sda1 does not exist
May 13th, 2009 at 12:40 pm
Garret:
I realize this may be a bit late, but just for reference of any having the same problem: That means that windows did not ‘release’ the filesystem properly.
What you can do is open up a terminal window, then type:
’sudo mkdir /media/mydisk’
’sudo mount -t ntfs-3g /dev/sdb1 /media/mydisk -o force’
HTH
May 21st, 2009 at 2:28 pm
Garrett,
Kubuntu doesn’t recognize the disk drive, because it uses the NTFS filesystem, made by Microsoft and not readable by other OS other than Windows.
There is an NTFS driver for linux called NTFS-3g; it is a driver that puts the link in the kubuntu so it can understand the NTFS format and access it. you can search in your package manager to install it, and follow the instructions. It worked for me in the past, so I think now it should be better. Best regards.
July 7th, 2009 at 4:57 pm
[...] the net and doing the whole mount thing, and I pretty much gave up after looking at this guide on mounting a USB drive in Linux and having zero luck. I tried getting the data through “Windows Networking” on my [...]
July 23rd, 2009 at 6:49 am
I note the above comments with interest.
I have a sick XP machine from which i am attempting to rescue data. I have never used Linux before but have managed to get Knoppix 6.0.1 to boot on the above machine.
However, I am getting the “org.freedesktop.Hal.Device.Volume.UnknownFailure” error message when I click on what appears to be the hard drive volume in the “explorer” window.
I apologise for being a complete ignoramus about Linux and Knoppix and for not understanding the correct terminnology: I am doing a lot of research but a little success here and there is a big motivator. if any one could provide some help I’d be much obliged. Is Prinz’s message above going to be enough?
Many thanks in advance.
CC