Zachi Nachshon
Zachi Nachshon Software Architect and DevOps Engineer. Passionate technologist, OSS enthusiast and Raspberry Pi addict.

Mount Storage Volumes onto Linux Distro Operating Systems

Mount Storage Volumes onto Linux Distro Operating Systems

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


Migrate from here… categories: [ Storage ] tags: [volume, storage, linux, mount]

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 distro, 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

    1
    
    ssh pi@kmaster
    
  2. List all disks partition on the RPi server

    1
    
    sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL
    
    lsblk-rpi-list
     
  3. List the current devices on the RPi server

    1
    
    sudo fdisk -l
    
    fdisk-rpi-list-full
     
  4. Verify the sdX name of the external storage device and create a new partition table

    1
    2
    3
    4
    5
    6
    7
    
    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 
    
  5. Check that the external storage device is properly partitioned under a Linux filesystem

    fdisk fdisk-rpi-list-full-linux
     
    lsblk lsblk-rpi-list-linux
     
  6. Format the external storage device into ext4 file system

    1
    
    sudo mkfs.ext4 /dev/sda1
    
  7. Verify the external storage device is properly formatted into ext4 file system

    lsblk-rpi-list-linux-ext4

Mount Volume

  1. Find the UUID of the storage device disk partition

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

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

    1
    
    sudo mount /dev/sda1 /mnt/container-registry
    
  4. Verify that the storage device is mounted successfully

    1
    
    ls -lah /mnt/container-registry
    
  5. (Optional): Unmount the storage device

    1
    
    sudo umount /mnt/container-registry
    


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

    1
    
    sudo blkid
    
    blkid-list
     
  2. Edit the OS file system table fstab

    1
    2
    
    # Open fstab for editing
    sudo vi /etc/fstab
    
  3. Append the following line at the end of the file

    1
    2
    
    # 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
    


Summary

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

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.

Thanks !


comments powered by Disqus