77

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.

  • @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 9:05
  • 4
    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 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. – rozcietrzewiacz Oct 18 '12 at 12:59
84

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.

  • 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
19

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.

7

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
  • 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) – Let_Me_Be 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). – Let_Me_Be Aug 17 '11 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 Aug 17 '11 at 22:22
3

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
2

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.

  • Note for the idiots such as myself: It's umount NOT unmount! – Phill Healey Jan 6 at 16:05
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? – rastafile 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
0

The "device" man mount speaks of is a logical block device with a filesystem on it.

A "device" can also mean a product (SSD is a drive, HDD is disk drive, DVD is disk, ODD is disk drive.

Often it does not matter which exactly. But when it comes to mounting (or formatting, or partitioning), it does matter, because it matters logically.

As you can see, sda is right beside sda1, 2, 3 ...And also sdb, sdc, each with their partitions. So you can go wrong both ways.

When you mount /dev/sdb1 /media/disk/, you are choosing partition 1 from sata disk "b". If that sdb1 is a USB pen partition, then your mountpoint's name is not very speaking.

You can even mount a piece of RAM to make a ramdisk, or a file ("loop device"). Or a all-virtual "device" like sysfs, which populates /sys directory (mountpoint).

The idea of mounting, and thus the command mount, rely on a concept (VFS etc.) with three main elements:

  1. Partition/block device: compare fdisk -l, lsblk and cat /proc/partitions. It is tricky, but 80% is just different points of view.
  2. File System: Formatting turns a 20GB partition into a empty directory with 18GB free space to fill with files. See man mkfs and man mkfs.ext2 (mkfs.FSTYPE).
  3. Mountpoint: This is just a "hook", a (empty) directory to which the new branch is attached to top directory "/". By binding and overlaying you can create complicated FS trees. But any ad hoc mkdir xyz is fine, technically.

All this mounting was once configured by the sysadmin in /etc/fstab, centrally. With today's hot-plugging of mass storage, things get a bit complicated.

In the case of a USB pen it is a kernel module that pops up /dev/sdb and its partitions in a split second.

All further automation in hot-plugging, simple as it is, has to be coordinated by udev, and sometimes perfected by additional tools. Udev can handle ALL devices, not just storage.

We are caught between the comfort of having a new icon (or even just a "device" with a decent name) pop up automatically, and the way the kernel with the (virtual) file system systematically has to prepare the parts. But with RAID and encryption and all the different storage "devices" Linux has to add some layers.

In the end, you want that contents at your fingertips.

Normally, you only have to identify the correct...DEVICE ;). You can ls /dev/sd* to see what is there: which letters, which numbers, identify your DEVICE...

And then type

mkdir mydev
mount /dev/DEVICE mydev

(You can leave out the -t type part)

  • This is easy to read and systematic at the same time. "mount" is a very important concept. All these answers show the "problem", especially for debutants. "mount" is THE unix command. Multidimensional. Only fork() more complex. – rastafile Oct 21 '19 at 12:41
  • wikipedia linux criticism: At one time, Linux systems required removable media, such as floppy discs and CD-ROMs, to be manually mounted before they could be accessed. Mounting media is now automatic in nearly all distributions, with the development of the udev. – rastafile Oct 21 '19 at 15:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.