Tutorial

How To Perform Basic Administration Tasks for Storage Devices in Linux

Updated on October 5, 2022
How To Perform Basic Administration Tasks for Storage Devices in Linux

Introduction

There are many tools available to manage storage in Linux. However, only a handful are used for day-to-day maintenance and administration. In this guide, you will review some of the most commonly used utilities for managing mount points, storage devices, and filesystems.

Other Resources

This guide will not cover how to prepare storage devices for their initial use on a Linux system. This guide on partitioning and formatting block devices in Linux will help you prepare your raw storage device if you have not set up your storage yet.

For more information about some of the terminology used to discuss storage, try reading this article on storage terminology.

Finding Storage Capacity and Usage with df

Often, the most important information you will need about the storage on your system is the capacity and current utilization of the connected storage devices.

To check how much storage space is available in total and to see the current utilization of your drives, use the df utility. By default, this outputs the measurements in 1K blocks, which isn’t always useful. Add the -h flag to output in human-readable units:

  1. df -h
Output
Filesystem Size Used Avail Use% Mounted on udev 238M 0 238M 0% /dev tmpfs 49M 624K 49M 2% /run /dev/vda1 20G 1.1G 18G 6% / tmpfs 245M 0 245M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 245M 0 245M 0% /sys/fs/cgroup tmpfs 49M 0 49M 0% /run/user/1000 /dev/sda1 99G 60M 94G 1% /mnt/data

The /dev/vda1 partition, which is mounted at /, is 6% full and has 18G of available space, while the /dev/sda1 partition, which is mounted at /mnt/data is empty and has 94G of available space. The other entries use tmpfs or devtmpfs filesystems, which is volatile memory used as if it were permanent storage. You can exclude these entries by typing:

  1. df -h -x tmpfs -x devtmpfs
Output
Filesystem Size Used Avail Use% Mounted on /dev/vda1 20G 1.1G 18G 6% / /dev/sda1 99G 60M 94G 1% /mnt/data

This output offers a more focused display of current disk utilization by removing some pseudo-devices and special devices.

Finding Information about Block Devices with lsblk

A block device is a generic term for a storage device that reads or writes in blocks of a specific size. This term applies to almost every type of non-volatile storage, including hard disk drives (HDDs), solid state drives (SSDs), and so on. The block device is the physical device where the filesystem is written. The filesystem, in turn, dictates how data and files are stored.

The lsblk utility can be used to display information about block devices. The specific capabilities of the utility depend on the version installed, but in general, the lsblk command can be used to display information about the drive itself, as well as the partitioning information and the filesystem that has been written to it.

Without any arguments, lsblk will show device names, the major and minor numbers associated with a device (used by the Linux kernel to keep track of drivers and devices), whether the drive is removable, its size, whether it is mounted read-only, its type (disk or partition), and its mount point. Some systems require sudo for this to display correctly:

  1. sudo lsblk
Output
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 100G 0 disk vda 253:0 0 20G 0 disk └─vda1 253:1 0 20G 0 part /

Of the output displayed, the most important parts will usually be the name, which refers to the device name under /dev, the size, the type, and the mountpoint. Here, you can see that you have one disk (/dev/vda) with a single partition (/dev/vda1) being used as the / partition and another disk (/dev/sda) that has not been partitioned.

To get information more relevant to disk and partition management, you can pass the --fs flag on some versions:

  1. sudo lsblk --fs
Output
NAME FSTYPE LABEL UUID MOUNTPOINT sda vda └─vda1 ext4 DOROOT c154916c-06ea-4268-819d-c0e36750c1cd /

If the --fs flag is unavailable on your system, you can manually replicate the output by using the -o flag to request specific output. You can use -o NAME,FSTYPE,LABEL,UUID,MOUNTPOINT to get this same information.

To get information about the disk topology, type:

  1. sudo lsblk -t
Output
NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE RA WSAME sda 0 512 0 512 512 1 deadline 128 128 2G vda 0 512 0 512 512 1 128 128 0B └─vda1 0 512 0 512 512 1 128 128 0B

There are many other shortcuts available to display related traits about your disks and partitions. You can output all available columns with the -O flag or you can customize the fields to display by specifying the column names with the -o flag. The -h flag can be used to list the available columns:

  1. lsblk -h
Output
. . . Available columns (for --output): NAME device name KNAME internal kernel device name . . . SUBSYSTEMS de-duplicated chain of subsystems REV device revision VENDOR device vendor For more details see lsblk(8).

Working with Filesystem Mounts

Before you can use a new disk, you typically have to partition it, format it with a filesystem, and then mount the drive or partitions. Partitioning and formatting are usually one-time procedures. You can find out more information on how to partition and format a drive with Linux in How To Partition and Format Storage Devices in Linux.

Mounting is something you may do more frequently. Mounting the filesystem makes it available to the server at the selected mount point. A mount point is a directory under which the new filesystem can be accessed.

Two complementary commands are primarily used to manage mounting: mount and umount. The mount command is used to attach a filesystem to the current file tree. In a Linux system, a single unified file hierarchy is used for the entire system, regardless of how many physical devices it is composed of. The umount command (Note: this is umount, not unmount) is used to unmount a filesystem. Additionally, the findmnt command is helpful for gathering information about the current state of mounted filesystems.

Using the mount Command

The most straightforward way to use mount is to pass in a formatted device or partition and the mount point where it is to be attached:

  1. sudo mount /dev/sda1 /mnt

The mount point, the final parameter which specifies where in the file hierarchy the new filesystem should be attached, should almost always be an empty directory.

Usually, you will want to select more specific options when mounting. Although mount can attempt to guess the filesystem type, it’s almost always a better idea to pass in the filesystem type with the -t option. For an Ext4 filesystem, this would be:

  1. sudo mount -t ext4 /dev/sda1 /mnt

There are many other options that will impact the way that the filesystem is mounted. There are generic mount options, which can be found in the FILESYSTEM INDEPENDENT MOUNT OPTIONS section of the mount manual.

Pass in other options with the -o flag. For instance, to mount a partition with the default options (which stands for rw,suid,dev,exec,auto,nouser,async), you can pass in -o defaults. If you need to override the read-write permissions and mount as read-only, you can add ro as a later option, which will override the rw from the defaults option:

  1. sudo mount -t ext4 -o defaults,ro /dev/sda1 /mnt

To mount all of the filesystems outlined in the /etc/fstab file, you can pass the -a option:

  1. sudo mount -a

Listing Filesystem Mount Options

To display the mount options used for a specific mount, use the findmnt command. For instance, if you viewed the read-only mount from the example above with findmnt, it would look something like this:

  1. findmnt /mnt
Output
TARGET SOURCE FSTYPE OPTIONS /mnt /dev/sda1 ext4 ro,relatime,data=ordered

This can be useful if you have been experimenting with multiple options and have finally discovered a set that you like. You can find the options it is using with findmnt so that you know what is appropriate to add to the /etc/fstab file for future mounting.

Unmounting a Filesystem

The umount command is used to unmount a given filesystem. Again, this is umount not unmount.

The general form of the command is to name the mount point or device of a currently mounted filesystem. Make sure that you are not using any files on the mount point and that you do not have any applications (including your current shell) operating inside of the mount point:

  1. cd ~
  2. sudo umount /mnt

There are usually no options to add to the default unmounting behavior.

Conclusion

While this list is in no way exhaustive, these utilities should cover most of what you need for daily system administration tasks. By learning a few tools, you can handle storage devices on your server.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.