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
If you don't bother to install pmount you could first check the name of your partition with
lsblk
Then, assuming you find it on /dev/sdb1 you could do
sudo mount /dev/sdb1 /mnt/ -o uid=1000,gid=1000,rw
assuming that you are user 1000. The uid and gid gives you permission to read and write (rw) on the mount, otherwise only root will have read and write access. Obviously you can add more options in -o (see man mount).
You can check your uid and gid with
cat /etc/passwd | grep YourUserName
Cheers, hope this helps.
Related videos on Youtube
cctt
Updated on September 17, 2022Comments
-
cctt over 1 year
I want to mount a drive from terminal at startup. At startup if I use
ls /media
, I notice that it is empty. If I go to Computer and click on VM drive there, I can then see the VM driver inls /media
.How can I mount that drive from the terminal without having to go to Computer? Something like
mount VM
Or how can find the path of VM like
/dev/sda
or something?