Get started Bring yourself up to speed with our introductory content.

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.

  [root@server2 ~]# 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

This was last published in October 2015

Dig Deeper on Linux servers

PRO+

Content

Find more PRO+ content and other member only offers, here.

Join the conversation

4 comments

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

What areas have you struggled with as a new Linux server administrator?
Cancel
It's better to use ls commandcommand to get the reverse chronological list of devices inserted. "ls -let sd*". Pick the last entry and mount it using helper script or invoke from udev rules for usb or storage disk.
Cancel
"ls -lrt sd*"
Cancel
I don't actually understand whether this article is for showing how to mount a device or to shout that windows is easy. Even the title of this article looks like a security issue with linux when it is not. I seriously think that this is something aimed at discredit linux for windows.

The author says that mounting a device is a manual process. Most of the linux servers have auto mounting and the device will be available the moment you plug it in. Yes, the author has said that where there is no GUI, but those servers where the GUI is not installed never need to be connected to a storage device, we usually copy the data from other systems to there and not by going into the server room and connecting a device to it physically.

Please don't write articles like this which are obviously aimed at scaring people (even with the title) and telling windows is easy. Linux is much much easier.

Cancel

-ADS BY GOOGLE

SearchWindowsServer

SearchEnterpriseLinux

SearchServerVirtualization

SearchCloudComputing

Close