Mount Storage Volumes onto Linux Operating Systems

Zachi Nachshon
Level Up Coding
Published in
4 min readDec 31, 2021

--

Learn how to connect an external storage devices onto Linux based operating systems. From partitioning and formatting towards auto mounting.

· External Storage Device
Linux Devices Naming
Partition & Format
Mount Volume
· Advanced Topics
Automatic Mounting
· Summary

External Storage Device

These instructions cover the necessary steps for connecting an external storage device onto a Linux operating system.

Linux Devices Naming

What is /dev/sda1 ?

External volumes in Linux are prefixed with sd which stands for SCSI Disk.
SCSI is the acronym of Small Computer System Interface.

The suffix of sd which is sda, sdb, sdc refers to the 1st / 2nd / 3rd SCSI mounted devices. The numeric value for each mounted device i.e. sda1, sda2 is the partitions within each disk.

Partition & Format

In this example I will use a USB drive as an external volume and connect it to a Raspberry Pi board named kmaster, these instructions are relevant for every Linux distribution, skip the first step if it is irrelevant for you.

  1. (Optional): Connect the external storage device to a Raspberry Pi node and SSH into it
ssh pi@kmaster

2. List all disks partition on the RPi server

sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL

3. List the current devices on the RPi server

sudo fdisk -l

4. Verify the sdX name of the external storage device and create a new partition table

sudo fdisk /dev/sda

# m - print commands menu (for visibility)
# g - create a new empty GPT partition table
# n - add a new partition
# Press enter x3 for defaults (Partition number, First sector, Last sector)
# w - write table to disk and exit

Important: Make sure you are working on the current sdX device, all data on the external storage device is about to wipe, there is no going back after writing table to disk !

5. Check that the external storage device is properly partitioned under a Linux filesystem

fdisk

lsblk

6. Format the external storage device into ext4 file system

sudo mkfs.ext4 /dev/sda1

7. Verify the external storage device is properly formatted into ext4 file system

Mount Volume

  1. Find the UUID of the storage device disk partition
sudo blkid

2. Create a target folder to be the mount point of the storage device (container-registry in this example)

sudo mkdir /mnt/container-registry

3. Mount the storage device partition /dev/sda1 at the mount point /mnt/container-registry

sudo mount /dev/sda1 /mnt/container-registry

4. Verify that the storage device is mounted successfully

ls -lah /mnt/container-registry

5. (Optional): Unmount the storage device

sudo umount /mnt/container-registry

Important: Before unplugging the storage device from the Raspberry Pi board, remember to unmount first !

Advanced Topics

These instructions are relevant to any Linux distributions operating systems. This section orientation is going to be around Debian OS which is the Raspberry Pi OS in use. Please follow the Setting Up a Raspberry Pi Cluster post for additional information.

Automatic Mounting

We will edit the OS file system table fstab to auto-mount the external storage device when the Raspberry Pi server starts up.

  1. Find the UUID and TYPE of the storage device disk partition
sudo blkid

2. Edit the OS file system table fstab

# Open fstab for editing
sudo vi /etc/fstab

3. Append the following line at the end of the file

# Append to end of file
UUID=<value-from-step-1> /mnt/container-registry ext4 defaults,auto,users,rw,nofail,x-systemd.device-timeout=30 0 0

Note: We have set a mount point /mnt/container-registry with ext4 file system and defined a 30 sec timeout for the RPi board if storage disk is disconnected when the RPi starts up.

Summary

Upon completing this post you should be familiar with how external storage devices are identified and connected to a Linux operating system 💾

What now? Partition, format and mount any external storage device you require onto your Linux distro OS directly from the CLI !

Please leave your comment, suggestion or any other input you think is relevant to this post in the discussion below.

Like this post?
You can find more by:

Checking out my blog: https://blog.zachinachshon.com
Following me on Twitter: @zachinachshon

Thanks for reading! ❤️

--

--

Software Architect and DevOps Engineer. Passionate technologist, OSS enthusiast and Raspberry Pi addict — https://zachinachshon.com