105

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.

jasonwryan
  • 73,126
its_me
  • 13,959
  • @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 Aug 17 '11 at 22:20
  • @rozcietrzewiacz That's not very fair. – Alex Chamberlain Oct 10 '12 at 09: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. – Alex Chamberlain Oct 10 '12 at 09: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. – rozcietrzewiacz Oct 18 '12 at 12:59

10 Answers10

115

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.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
ghm1014
  • 1,527
  • 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 Aug 17 '11 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 Aug 17 '11 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 Aug 17 '11 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 Aug 17 '11 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 Aug 17 '11 at 22:00
  • /dev/cdr* it's common to be used too – ghm1014 Aug 18 '11 at 14:00
  • @ghm1014 What if System is W95 FAT32 (LBA) here it gives no indication that it is vfat. Can you point me any resource that list system and it's corresponding filesystem. – Cody Sep 29 '15 at 11:20
  • @Cody, I don't understand the question, the "System" column indicates the filesystem, if it is fat32, then you just mount it. No need to specify the filesystem on the mount command – ghm1014 Oct 02 '15 at 15:58
  • Fdisk shows my 2 partitions on a USB MicroSD card, but I can not mount these: sudo mount -t vfat /dev/sdc /media/microsd/ mount: /dev/sdc: can't read superblock sudo mount -t vfat /dev/sdc1 /media/microsd/ mount: special device /dev/sdc1 does not exist. lsblk only shows the root node sdc, not the partitions that fdisk shows. Ideas? – appas Aug 16 '17 at 11:03
29

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.

Anthon
  • 79,293
12

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.

Jeremy Boden
  • 1,320
Šimon Tóth
  • 8,238
  • Where can I find more information about this? I am not yet into this "verbose thing" on Linux, so it's confusing. – its_me Aug 17 '11 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) – Šimon Tóth Aug 17 '11 at 21:27
  • where do I get these details (partition ID, device path, label etc) from? – its_me Aug 17 '11 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). – Šimon Tóth Aug 17 '11 at 21:42
  • I guess this is tougher for me as I am a beginner. Where do I find more information about common device files i.e., that /dev/sd* or /dev/hd* are for hard disks, /dev/cdrom for CD-ROMs, /dev/fd* for floppies etc? Kindly direct me (I don't know what to search for - - search term). – its_me Aug 17 '11 at 21:53
  • @Aahan Well that's all. What I'm telling you is that there are now verbose paths, that link back to /dev/sd*, /dev/fd*, /dev/cdrom. These paths are generated using four different approaches. The /dev/disk/by-id and /dev/disk/by-label are for us humans, since they describe the device in human readable format (unlike /dev/sd*). /dev/disk/by-path is mostly for debugging I guess, or when you know how a device is connected. /dev/disk/by-uuid is for unique identification. – Šimon Tóth Aug 17 '11 at 22:00
  • yes I understand that. What I really, really don't get even now is how you are able to find the verbose paths for a device? Where are you looking for it. Are you looking inside in /etc/fstab? Maybe a real example will help. Thanks for your time. – its_me Aug 17 '11 at 22:05
  • ok, ok. I get it now. Thanks. Reading what you said again and again made some sense. Thanks again! – its_me Aug 17 '11 at 22:09
  • @Aahan Uhm? As I said. They are just links. So for me the /dev/disk/by-id/usb-HTC_Android_Phone_SH0BTRX01208-0\:0 is obviously my phone, /dev/disk/by-id/ata-ST31500341AS_9VS2AM04-part1 is not that obvious, but ST31500341AS is a model number, so after googling I know that it is the Seagate Baracuda 1,5TB disk. Of course it's not always so clear. For example if you have several disks of the same model in your PC, they will only differ by the serial number. – Šimon Tóth Aug 17 '11 at 22:11
  • 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 Aug 17 '11 at 22:22
5

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.

Joke Sr. OK
  • 903
  • 1
  • 8
  • 11
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
    How about using fdisk -l like the other answer mentioned? (also please see my latest comment on that answer.) – its_me Aug 17 '11 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.

  • Why two 4GB identical? And OQ is having hard time finding correct device. And then also format? –  Oct 21 '19 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
Gaurab
  • 1
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

Vorac
  • 3,077
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.

Vorac
  • 3,077