Learn how to connect an external storage devices onto Linux based operating systems. From partitioning and formatting towards auto mounting.
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.
-
(Optional): Connect the external storage device to a Raspberry Pi node and SSH into it
1
ssh pi@kmaster
-
List all disks partition on the RPi server
1
sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL
-
List the current devices on the RPi server
1
sudo fdisk -l
-
Verify the
sdXname of the external storage device and create a new partition table1 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
Important: Make sure you are working on the currentsdXdevice, all data on the external storage device is about to wipe, there is no going back after writing table to disk ! -
Check that the external storage device is properly partitioned under a Linux filesystem
fdisk
lsblk
-
Format the external storage device into
ext4file system1
sudo mkfs.ext4 /dev/sda1 -
Verify the external storage device is properly formatted into
ext4file system
Mount Volume
-
Find the
UUIDof the storage device disk partition1
sudo blkid
-
Create a target folder to be the mount point of the storage device (
container-registryin this example)1
sudo mkdir /mnt/container-registry -
Mount the storage device partition
/dev/sda1at the mount point/mnt/container-registry1
sudo mount /dev/sda1 /mnt/container-registry -
Verify that the storage device is mounted successfully
1
ls -lah /mnt/container-registry
-
(Optional): Unmount the storage device
1
sudo umount /mnt/container-registryImportant: 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.
-
Find the
UUIDandTYPEof the storage device disk partition1
sudo blkid
-
Edit the OS file system table
fstab1 2
# Open fstab for editing sudo vi /etc/fstab
-
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
Note: We have set a mount point/mnt/container-registrywithext4file system and defined a30 sectimeout 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 :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 !
Discussion