107

I read some resources about the mount command for mounting devices on Linux, but none of them is clear enough (at least for me).

On the whole this what most guides state:

$ mount
(lists all currently mounted devices)

$ mount -t type device directory
(mounts that device)

for example (to mount a USB drive):
$ mount -t vfat /dev/sdb1 /media/disk

What's not clear to me:

  • How do I know what to use for "device" as in $ mount -t type device directory? That is, how do I know that I should use "/dev/sdb1" in this command $ mount -t vfat /dev/sdb1 /media/disk to mount my USB drive?

  • what does the "-t" parameter define here? type?

I read the man page ($ man mount) a couple of times, but I am still probably missing something. Please clarify.

4
  • @rozcietrzewiacz I must admit that my mind didn't work properly. When @Let_Me_Be was referring to /dev/disk/by-id I thought "by-id" was to be replaced by something and should be issued as a command. It didn't strike my mind that it could actually be a directory. This probably happens to Windows -> Linux users in their initial phase! (or it's only me :))
    – its_me
    Commented Aug 17, 2011 at 22:20
  • @rozcietrzewiacz That's not very fair. Commented Oct 10, 2012 at 9:05
  • 6
    Drop the -t type. mount will normally figure it out and generally if it can't, it's a reasonable indication you are doing something wrong. Commented Oct 10, 2012 at 9:06
  • 3
    @AlexChamberlain I can see I got carried. My apologies to @its_me. I should have written "If you'd really read the manual, you wouldn't ask about the -t option". The other part of the question (how to determine, which device is represented by a /dev/ entry) is very reasonable. Commented Oct 18, 2012 at 12:59

10 Answers 10

117

You can use fdisk to have an idea of what kind of partitions you have, for example:

fdisk -l

Shows:

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63   204796619   102398278+   7  HPFS/NTFS
/dev/sda2       204797952   205821951      512000   83  Linux
/dev/sda3       205821952   976773119   385475584   8e  Linux LVM

That way you know that you have sda1,2 and 3 partitions. The -t option is the filesystem type; it can be NTFS, FAT, EXT. In my example, sda1 is ntfs, so it should be something like:

mount -t ntfs /dev/sda1  /mnt/

USB devices are usually vfat and Linux are usually ext.

9
  • I am on a fedora VM (Windows 7 host). I just plugged in a usd drive (Windows doesn't recognize it because the VM is running) and issued the command $ fdisk -l. But it only lists Linux and Linux LVM file systems (only two). Not vfat, ntfs, hpfs or ext etc.
    – its_me
    Commented Aug 17, 2011 at 20:49
  • Maybe this is not a mount issue, but a device recognition problem. Take a look at /var/log/message file, it should show if there is any problem with the USB device.
    – ghm1014
    Commented Aug 17, 2011 at 20:56
  • So, normally is this how I should find it on a running linux system: plugin a pen drive (example), issue the command # fdisk -l and find the device (/dev/*) & its filesystem (vfat, ntfs, hpfs, ext etc). Right?
    – its_me
    Commented Aug 17, 2011 at 21:02
  • Usually, yes. If you're running gnome, it mount usb and external hard drives but itself without manually mount. It shows a popup window just like Windows does.
    – ghm1014
    Commented Aug 17, 2011 at 21:55
  • One last doubt. Are these the only common filesystem device files: /dev/sd* or /dev/hd* are for hard disks, /dev/cdrom for CD-ROMs and /dev/fd* for floppies. Anything else?
    – its_me
    Commented Aug 17, 2011 at 22:00
30

I was really rusty on this, and then it started coming back.. if this doesn't answer your question, maybe I misread it...

Alibi: this is on an Ubuntu 14 release. Your mileage may vary.

I use lsblk to get my mount points, which is different from mount For me lsblk is easier to read than mount

Make sure that you have a directory created before you go to mount your device.

sudo mkdir /{your directory name here}
sudo mount /dev/{specific device id} /{your directory name here that is already created}

You should be good to go, however check security permissions on that new directory to make sure it's what you want.

13

These days, you can use the verbose paths to mount a specific device.

For example:

mount /dev/disk/by-id/ata-ST31500341AS_9VS2AM04-part1 /some/dir
mount /dev/disk/by-id/usb-HTC_Android_Phone_SH0BTRX01208-0\:0 /some/dir

Run the ls -l /dev/disk/by-id/ command to see the possibilities.

10
  • Where can I find more information about this? I am not yet into this "verbose thing" on Linux, so it's confusing.
    – its_me
    Commented Aug 17, 2011 at 21:21
  • 1
    @Aahan Well, these are just symlinks to /dev/sd*. There are /dev/disk/by-id (device/partition ID), /dev/disk/by-uuid (device/partition UUID - not very useful for manual use), /dev/disk/by-path (depends on how the device is connected), /dev/disk/by-label (partition label if present) Commented Aug 17, 2011 at 21:27
  • where do I get these details (partition ID, device path, label etc) from?
    – its_me
    Commented Aug 17, 2011 at 21:36
  • 1
    @Aahan Well, that is what the device reports. Id will be the device name or model or serial number, or a combination. Path will be the same, but reported for the way the disk is connected, so it will be for example pci-0000:00:1f.2-scsi-3:0:0:0-part3 (pci device 0000:00:1f.2, third port, third partition), label will be label, uuid is computer generated unique id (you will use that if you will want a form of identification that won't change). Commented Aug 17, 2011 at 21:42
  • 1
    When you were referring to /dev/disk/by-id I thought "by-id" was to be replaced by something and should be issued as a command. It didn't strike my mind that it could actually be a directory. Thanks for being patient with me. LOL, I was ridiculous :)
    – its_me
    Commented Aug 17, 2011 at 22:22
6

How come we have many ways to do this but as always we also take into consideration and do not know where the file system used in the device may hinder a little, but we can use the "auto" option to give a little help.

mount -t auto /dev/sdb1 /media/pendrv

and ready our device will be mounted: at /media/pendrv ready to use, then simply use:

umount /media/pendrv

... to release the device.

1
  • 5
    Note for the idiots such as myself: It's umount NOT unmount! Commented Jan 6, 2020 at 16:05
4

mount (the command) usually figures out the "type" of the file system on the device. I think the hard part if figuring out the device file name. You almost have to know the disk drive naming conventions to figure it out.

On an up-to-date Arch linux box:

133 % ls /dev/sd??
/dev/sda1  /dev/sda2  /dev/sda3  /dev/sda4  /dev/sdb1  /dev/sdb2

But that doesn't work on a mature (2.6.20.9) Slackware box:

1 % ls /dev/sd??
zsh: no matches found: /dev/sd??
2 % ls /dev/hd??
/dev/hda1  /dev/hda2

Without knowing in advance that /dev/sd* or /dev/hd* are hard disk device files, you have to use lspci or lsusb or something to figure out the device file name. USB devices often leave information in /var/log/messages to help you figure out what device file udev assigned to them.

1
  • 1
    How about using fdisk -l like the other answer mentioned? (also please see my latest comment on that answer.)
    – its_me
    Commented Aug 17, 2011 at 21:10
1

On Ubuntu 14, you can also use Disks app:

enter image description here

First click on the disk on the left panel and then click on the partition on the right panel. The bottom of right panel shows format, current mounting status etc. You can also use this GUI to create/delete/format partitions.

1
  • Why two 4GB identical? And OQ is having hard time finding correct device. And then also format?
    – user373503
    Commented Oct 21, 2019 at 11:57
0

ThoerX Forum Check the device withfdisk -l

Partition the device as following :-
fdisk /dev/sda
d - Delete old partitions
n - New partition
select partition number
select start block
select end block
v - verify the new partition
w - write through

now fdisk - l should show /dev/sda1 with proper filesystem type (say ext4)
mount -t ext4 /dev/sda1 /myMountPoint
0

I use the following commands in the following order:

 # identify desired partition by name, size and mount point
lsblk

# some disposable directory, mind the permissions if you will
mkdir /tmp/disk

# NO -t: it's auto detected
mount /dev/X /tmp/disk

# equivalent to umount /dev/X; or to "Safely Remove" in Windows
umount /tmp/disk
0

1. Find what the drive is called
You'll need to know what the drive is called to mount it. To do that enter the command below

lsblk

You're looking for a partition that should look something like: /dev/sda1 or /dev/sdb1. The more disks you have the higher the letter this is likely to be. Anyway, find it and remember what it's called.

2. Mount using udisksctl

udisksctl mount -b /dev/sda1

Sample Output:

Mounted /dev/sda1 at /media/myusername/usb_stick_name.

3. Unmount the disk

Similarly, you can unmount the USB drive using command:

udisksctl unmount -b /dev/sda1

The Above approach saves you from,

  • figuring out your disk filesystem type ;)
  • creating a mount point directory using root privilege ;)
  • mounting the disk using sudo ;)

For more details check this question

0
lsblk
mount /dev/somedevice /mnt
umount /mnt

On Arch. Else create a directory and mount there. -t is redundant. su/do is needed as this is a system operation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .