Gajus - Fotolia


Linux mount command reveals storage device access path

New Linux server administrators will find mounting storage devices very different than they have seen on Windows servers.

On a Windows server, you can plug in any storage device and it will be ready for use through any application that...

browses the file system, typically Explorer. That's not always the case with Linux.

Linux file and directory access works through one large file system that starts on the top with the root directory. This file system tree does not necessarily reside on a single storage device. Administrators use the Linux mount command to integrate multiple storage devices into the directory structure.

In Windows, storage device access is oriented to the device. You'll see optical drives, USB keys and hard drives as separate devices in the Windows Explorer overview, making it easy to access a new device.

To access a device on Linux, it must be mounted by connecting it to a directory. Mounting a device typically is a manual procedure, because only the administrator decides to which directory the device connects. And before you disconnect the device, it must be unmounted. Linux servers rarely use graphical interfaces. If you insert a storage device in a server USB port, nothing will happen.

To mount storage onto Linux servers, first decide which directory should access the device. Then use the Linux mount command to activate it. The mount command typically looks like mount /dev/sdb1 /mnt, where /dev/sdb1 is the device and /mnt is the directory where you want to mount it.

You have to know the exact name of the device to use the Linux mount command. It usually starts with /dev/sd, in which sd can be interpreted as storage device. After sd, you'll see another letter, which is assigned when the device is connected: /dev/sda is the first disk, then /dev/sdb is the second disk. The number following the letter denotes the partition. As devices often, but not always, only have one partition, you'll normally only see the number 1 assigned to it.

Based on the previously mentioned information, you should be able to find the name of the device that you want to mount onto the Linux server. But if you don't, use the Linux prompt  to find the information. Right after you have connected the device to your computer, use the dmesg command. This command shows recent kernel activity, including newly detected devices (see listing 1).

Listing 1: Use dmesg to find out device information.

[18435.325715] usb 1-1: new high-speed USB device number 2 using ehci-pci
[18435.504105] usb 1-1: New USB device found, idVendor=abcd, idProduct=1234
[18435.504109] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[18435.504110] usb 1-1: Product: UDisk      
[18435.504115] usb 1-1: Manufacturer: General
[18435.504116] usb 1-1: SerialNumber: Љ
[18435.687375] usb-storage 1-1:1.0: USB Mass Storage device detected
[18435.688710] scsi33 : usb-storage 1-1:1.0
[18435.689819] usbcore: registered new interface driver usb-storage
[18436.692763] scsi 33:0:0:0: Direct-Access   General UDisk      5.00 PQ: 0 ANSI: 2
[18436.702381] sd 33:0:0:0: Attached scsi generic sg2 type 0
[18436.728121] sd 33:0:0:0: [sdb] 15616000 512-byte logical blocks: (7.99 GB/7.44 GiB)
[18436.730316] sd 33:0:0:0: [sdb] Write Protect is off
[18436.730319] sd 33:0:0:0: [sdb] Mode Sense: 0b 00 00 08
[18436.732437] sd 33:0:0:0: [sdb] No Caching mode page found
[18436.872492] sd 33:0:0:0: [sdb] Assuming drive cache: write through
[18436.902023] sd 33:0:0:0: [sdb] No Caching mode page found
[18436.917099] sd 33:0:0:0: [sdb] Assuming drive cache: write through
[18436.979578] sdb: sdb1
[18436.997664] sd 33:0:0:0: [sdb] No Caching mode page found
[18437.002400] sd 33:0:0:0: [sdb] Assuming drive cache: write through
[18437.009989] sd 33:0:0:0: [sdb] Attached SCSI removable disk

After dmesg has shown the name of the device, find out how many partitions are available on the device by using cat /proc/partitions. This command shows all partitions that are commonly known to the Linux kernel (see listing 2). This information means you can use the mount command for the correct device. The dmesg command also shows a lot of information about devices that you probably don't really want to know about, which you can ignore.

Linux servers vs. desktops

If you're working on a graphical Linux desktop, you probably connect your USB thumb drive to the computer and start working with the files on it. Nautilus, the default Windows Explorer alternative on Linux, integrates the device for you. Servers aren't as easy, because they rarely use a GUI.

Listing 2. Use cat /proc/partitions to see how many partitions exist on a device.

  [[email protected] ~]# cat /proc/partitions
  major minor #blocks name
  2    0     4 fd0
  8    0  8388608 sda
  8    1   512000 sda1
  8    2  7875584 sda2
  11    0  1048575 sr0
  253    0   839680 dm-0
  253    1  7032832 dm-1
  8    16  7808000 sdb
  8    17  2318236 sdb1

Linux servers require you to dismount devices before removing them from the system. The umount command dismounts devices, and only works if no files on the device are in use. Use the umount /dev/sdb1 command to disconnect the /dev/sdb1 device that was mounted in the preceding command.

About the author:
Sander van Vugt is an independent trainer and consultant based in the Netherlands. He is an expert in Linux high availability, virtualization and performance. He has authored many books on Linux topics, including Beginning the Linux Command Line, Beginning Ubuntu LTS Server Administration and Pro Ubuntu Server Administration.

Next Steps

Starting out on Linux server administration

Basic Linux commands for new admins

Learn how to kill processes

Service management tips for Linux servers

Mount file systems with systemd

Dig Deeper on Linux servers