How to mount a drive from terminal in Ubuntu?
Solution 1:
You can use pmount
, from the manual page:
pmount ("policy mount") is a wrapper around the standard mount program
which permits normal users to mount removable devices without a match-
ing /etc/fstab entry.
pmount is invoked like this:
pmount device [ label ]
This will mount device to a directory below /media if policy is met
(see below). If label is given, the mount point will be /media/label,
otherwise it will be /media/device.
Solution 2:
Remember you've to make a directory first like this:
sudo mkdir /media/Name_of_directory
The above command will create a directory (folder) in media folder by replacing "Name_of_directory" with your providing folder name.
You can see drives numbers or id by:
sudo fdisk -l
Then mount the drive through:
sudo mount /dev/sda# /media/Name_of_directory
Where # must be replaced with legal number associated with your drives in Ubuntu (Linux Distro)
If you see this error:
mount: /media/sci: wrong fs type, bad option, bad superblock on /dev/vdb, missing codepage or helper program, or other error.
It means you still need to create a (new) file system. (Double-check that you really want to overwrite the current content of the specified partition! Replace X#
accordingly, but double check that you are specifying the correct partition, e.g., sda2, sdb1):
sudo mkfs.ext4 /dev/sdX#
Solution 3:
You can run fdisk -l
to show you all the disk devices, or after mounting it in the GUI, drop down to the Terminal and run cat /proc/mounts
and find your device that's mounted. You can then copy/paste that line from cat /proc/mounts
into /etc/fstab
and it'll be mounted at startup.
Solution 4:
This is a summary of the following guide which worked for me.
To automatically mount the drive in Ubuntu (without installing another package) you need to update /etc/fstab
First create a mount point, e.g.
sudo mkdir /data
Then get the Universal Unique ID for the device
sudo blkid
Then update fstab
sudo nano /etc/fstab
Adding a line like this at the bottom of the file
UUID=14D82C19D82BF81E /data auto nosuid,nodev,nofail,x-gvfs-show 0 0
where
-
UUID=14D82C19D82BF81E
is the UUID of the drive. You don't have to use the UUID here. You could just use /dev/sdj, but it's always safer to use the UUID as that will never change (whereas the device name could). -
/data
is the mount point for the device. -
auto
automatically mounts the partition at boot -
nosuid
specifies that the filesystem cannot contain set userid files. This prevents root escalation and other security issues. -
nodev
specifies that the filesystem cannot contain special devices (to prevent access to random device hardware). -
nofail
removes the errorcheck. -
x-gvfs-show
show the mount option in the file manager. If this is on a GUI-less server, this option won't be necessary. -
0
determines which filesystems need to be dumped (0 is the default). -
0
determine the order in which filesystem checks are done at boot time (0 is the default).
Solution 5:
devkit-disks
will let you query and mount devices, with the --enumerate-device-files
and --mount
options respectively.