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 in ls /media.
How can I mount that drive from the terminal without having to go to Computer? Something like
mount VMOr how can find the path of VM like /dev/sda or something?
6 Answers
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. Remember you've to make a directory first like this:
sudo mkdir /media/Name_of_directoryThe 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 -lThen mount the drive through:
sudo mount /dev/sda# /media/Name_of_directoryWhere # 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# 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.
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 /dataThen get the Universal Unique ID for the device
sudo blkidThen update fstab
sudo nano /etc/fstabAdding a line like this at the bottom of the file
UUID=14D82C19D82BF81E /data auto nosuid,nodev,nofail,x-gvfs-show 0 0where
UUID=14D82C19D82BF81Eis 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)./datais the mount point for the device.autoautomatically mounts the partition at bootnosuidspecifies that the filesystem cannot contain set userid files. This prevents root escalation and other security issues.nodevspecifies that the filesystem cannot contain special devices (to prevent access to random device hardware).nofailremoves the errorcheck.x-gvfs-showshow the mount option in the file manager. If this is on a GUI-less server, this option won't be necessary.0determines which filesystems need to be dumped (0 is the default).0determine the order in which filesystem checks are done at boot time (0 is the default).
devkit-disks will let you query and mount devices, with the --enumerate-device-files and --mount options respectively.
If you don't bother to install pmount you could first check the name of your partition with
lsblkThen, assuming you find it on /dev/sdb1 you could do
sudo mount /dev/sdb1 /mnt/ -o uid=1000,gid=1000,rwassuming 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 YourUserNameCheers, hope this helps.