1. Get device info:
$ sudo fdisk -l
2. Create the Mount Point
In the example below, the mount point name is “external”. You can name it anything you want.
$ sudo mkdir /media/external
for devices formatted in FAT16 or FAT32:
$ sudo mount /dev/sdb1 /media/external
for devices formatted in ntfs:
$ sudo mount -t ntfs-3g /dev/sdb1 /media/external
3. Unmounting the Drive
When you are finished with the device, don't forget to unmount the drive before disconnecting it. Assuming /dev/sdb1 is mounted at /media/external, you can either unmount using the device or the mount point:
$ sudo umount /dev/sdb1
$ sudo umount /media/external
Automount a Drive
First get device info:
Note the device id of the disk to be mounted, for example ‘sda1'. Then we need the UUID of the disk to be mounted, find it with the code below replacing sdXX with the correct device id from the previous step:
$ blkid /dev/sdXX
The UUID looks like this:
Now open this file:
$ sudo nano /etc/fstab
Now add this line to the end, changning the UUID for yours and /mnt/Disk should be changed to where you want to mount the disk:
UUID=40e554eb-6421-4813-88ea-3882a3a7a153 /mnt/Disk auto nosuid,nodev,nofail,x-gvfs-show 0 0
Ctrl+X, then ‘Y' to save and exit.
To mount a usb drive
To get the device info:
Locate the drive info(e.g. sdc2, sdb1, etc) and substitute this into ‘sdXN' below
$ cd /media $ sudo mkdir newdrive $ sudo mount -t ntfs-3g /dev/sdXN /media/newdrive
The last line above is for an ntfs formatted drive. For any other drive, try:
$ mount /dev/sdXN /media/newdrive
if you try the code below on an ntfs formatted drive, you will get the error:
ntfs-3g-mount: bad mount point media/reddrive: No such file or directory
The Importance of Unmounting
Before disconnecting devices, you must unmount them first. This is similar to “Safely Remove” in Windows in that the device won't unmount until data is finished being written to the device, or until other programs are finished using it. This applies to all types of storage devices, including flash drives, flash cards, external hard drives, ipods and other media players, and even remote storage like Samba or NFS shares.
Failure to unmount before disconnecting the device can result in loss of data and/or a corrupted file system. There are no exceptions to this rule. Be safe – unmount your drives before disconnecting them!
ERRORS & SOLUTIONS
If you are trying to unmount a drive ( or USB drive) and are seeing the error:
$ sudo umount /media/yourdrive umount: /media/thedrive: target is busy (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1).)
Do this to kill the busy processes and unmount the drive (substitute sdXN with the correct drive info:
$ sudo fuser -kim /dev/sdXN
The output will show runing processes, example:
/dev/sdXN: 8933 9628c Kill process 8933 ? (y/N) y
Press ‘y' to kill the process and do the same for the next prompt, then:
$ sudo umount dev/sdXN
$ sudo /media/yourdrivename
The code below is for mounting a device using a GUI.
The link below is used for the guide below, although it does not work when using ‘gksudo gedit …' (presumably do to no display)
More info on fstab and mounting
First, you need to find the device locations of the partition(s) you wish to mount. Open a terminal and run:
$ sudo blkid
For illustration purposes, an example output from a computer setup with a Vista/Ubuntu dual-boot and shared NTFS data partition is shown here:
/dev/sda1: LABEL="Recovery" UUID="B23613F43613B875" TYPE="ntfs" /dev/sda2: LABEL="Windows" UUID="38CE9483CE943AD8" TYPE="ntfs" /dev/sda3: LABEL="Data" UUID="519CB82E5888AD0F" TYPE="ntfs" /dev/sda5: UUID="00d7d951-2a35-40fd-8e5d-411bb824ff3b" TYPE="swap" /dev/sda6: LABEL="Ubuntu" UUID="6044b1d0-208e-4ab3-850d-03a92e1516fc" TYPE="ext4"
The first three partitions, all NTFS, are the ones that concern us here. There are no FAT32 partitions. In this instance, all three NTFS partitions have partition labels, which makes it easier to identify the purpose of each. If your blkid output does not include partition labels, this means that the partitions do not have labels and you will have to determine which partition you wish to mount by another means. Of the three NTFS partitions, we are going to configure /etc/fstab with only the third, the Data partition. Partition /dev/sda1 is the OEM manufacturer's recovery partition and should be left unmounted, or as described below. Partition /dev/sda2 is the Windows C:\ partition and is best not included in /etc/fstab for the reasons described above, or mounted read-only – see below.
You will now need to create a mountpoint for each NTFS partition that you wish to mount by means of /etc/fstab. In our illustration we are going to add one entry only for /dev/sda3. From a terminal:
$ sudo mkdir /media/Data
In this case we have created a mountpoint with the same name – Data – as the partition label. You may use (almost) any string you wish. Also note that in the example below ‘sda3' is the
$ sudo mount -t ntfs-3g /dev/sda3 /media/Data
Below is the rest of the code used in the first link above that should only be used with a GUI:
Before editing /etc/fstab directly, it is a good idea to make a backup. From a terminal:
$ sudo cp /etc/fstab /etc/fstab.orig
Now open /etc/fstab in a text editor with root privileges:
$ gksudo gedit /etc/fstab
If you see the output below,
The program 'gksudo' is currently not installed. You can install it by typing: sudo apt install gksu
$ sudo apt install gksu
$ gksudo gedit /etc/fstab
$ (gksudo:4578): Gtk-WARNING **: cannot open display:
Will need to find a solution before continuing. Seems that this process for mounting is for use with gui.
GKSu is a library that provides a Gtk+ frontend to su and sudo. It supports login shells and preserving environment when acting as a su frontend. It is useful to menu items or other graphical programs that need to ask a user's password to run another program as another user.
$ sudo apt-get remove gksu $ sudo apt-get remove --auto-remove gksu $ sudo apt-get purge gksu
For a general-purpose read-write mount, add this line to the end of /etc/fstab:
UUID=519CB82E5888AD0F /media/Data ntfs-3g defaults,windows_names,locale=en_US.utf8 0 0
Replace the UUID with the one relevant for your partition as shown in your blkid output. “519CB82E5888AD0F” will not work for you.
Also, substitute your mountpoint for “/media/Data”. In case you have a blank space in the name of the mountpoint you want to use like “New Volume” instead of “Data” located in “/media” use “/media/New\040Volume”. The space character is created by using “\040” in the fstab.
You will also need to change the “locale=en_US.utf8” option to one suitable for your location and language if you are not in the USA. You can determine your locale with this terminal command:
Or for a list of all locales available on your system:
Now save your edited /etc/fstab and close the text editor. The partition(s) you have configured will be mounted the next time you reboot, but to mount them now:
$ sudo mount -a
Two special cases
Sample /etc/fstab lines are suggested for two special cases.
Option 1 – for mounting read-only access. For example, this would be suitable for mounting your Windows C:\ partition if you need to access it. Modify the line below with your UUID and mountpoint:
UUID=519CB82E5888AD0F /media/Data ntfs defaults,umask=222 0 0
Option 2 – to ensure that Ubuntu does not mount the partition and also disables graphical mounting from the file manager. For example, you may wish to ensure that recovery and system partitions are never inadvertently mounted and do not appear in the file manager. In this case you need to create a mountpoint in /mnt, not /media. Modify the line below with your UUID and mountpoint:
UUID=519CB82E5888AD0F /mnt/Data ntfs noauto,umask=222 0 0
Note: with these mount options, the partition does not appear in the Devices list in the left pane of Nautilus (the Ubuntu file manager), but it still appears in Dolphin, the Kubuntu File Manager. Clicking on the partition in Dolphin causes the display of an error message. This solution is less elegant in Dolphin than with Nautilus, but the desired effect is achieved – the partition cannot be mounted.
If you need to revert to the original configuration:
$ sudo mv /etc/fstab.orig /etc/fstab $ sudo umount /media/<mountpoint>
Substitute your mountpoint in the second line.