Mount Disk Drives in Ubuntu & Raspbian
Linux, Raspberry Pi, Sysadmin
Automatically mount disk drives on boot.
We recently set up a Raspberrry pi as a local fileserver. The Pi is connected to a powered USB hub and a number of hard drives. We use this to backup our systems overnight - the Pi is not the fastest, but the entire system draws less power than a lightbulb.
To work properly, the connected drives need to be mounted at boot, and this guide outlines how to achieve this.
You could follow the same procedure for adding drives to any Debian based distro.
Set Up Drives
Use the Disks utility to format and label drives.
Ext4 is a good choice for a filesystem format if the disk is intended for Linux use only.
Mount Points
To mount disk drives, first create a mount point(s) and set permissions:
sudo mkdir /mnt/disk-1
sudo mkdir /mnt/disk-2
# set permissions:
sudo chmod -R 755 /mnt
Find Drives
There are many ways to determine the drives available to the system:
# Get name, size & model, but no UUID
lsblk -ido KNAME,TYPE,SIZE,MODEL
# Output:
david@raspberrypi:~ $ lsblk -ido KNAME,TYPE,SIZE,MODEL
KNAME TYPE SIZE MODEL
sda disk 931.5G External USB-3.0
sdb disk 931.5G TOURO Mobile
mmcblk0 disk 7.3G
# Get disk name and partition data
sudo fdisk -l
# Get UUID
ls -l /dev/disk/by-uuid/
# Output:
david@raspberrypi:~ $ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 15 May 10 10:36 04FE-51E9 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 10 May 10 10:36 76ef1fc2-1bc5-4a2c-950f-43e99c975da8 -> ../../sdb1
lrwxrwxrwx 1 root root 15 May 10 10:36 e6e7f776-11a4-4cd7-b4fd-c44ecdbfcf90 -> ../../mmcblk0p2
lrwxrwxrwx 1 root root 10 May 10 10:36 fba9c513-2117-4245-a41c-f813497b0826 -> ../../sda1
# RECOMMENDED - show UUID & disk label for connected drives
# ------------------------------------------------------------------------------
sudo blkid
# Typical output:
david@raspberrypi:~ $ sudo blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="04FE-51E9" TYPE="vfat" PARTUUID="8f1eafaf-01"
/dev/mmcblk0p2: UUID="e6e7f776-11a4-4cd7-b4fd-c44ecdbfcf90" TYPE="ext4" PARTUUID="8f1eafaf-02"
/dev/sda1: LABEL="intenso-backup-1" UUID="fba9c513-2117-4245-a41c-f813497b0826" TYPE="ext4" PARTUUID="972d07b8-01"
/dev/sdb1: LABEL="Backup Data" UUID="76ef1fc2-1bc5-4a2c-950f-43e99c975da8" TYPE="ext4" PARTUUID="ef9e4c2c-01"
/dev/mmcblk0: PTUUID="8f1eafaf" PTTYPE="dos"
Disk drives are distinguished by a UUID(universally unique identifier) - we’ll use this number to mount the disks rather than the assigned device name (e.g. /dev/sda1
), since the latter might change and the UUID will not.
Manual Mount
To mount a drive manually:
sudo mount /dev/sda1 /mnt/disk-1
This won’t be persistent - when the system reboots, the drive will no longer be available.
Auto Mount on Boot
Amend /etc/fstab
by adding a line for each required disk. For example:
proc /proc proc defaults 0 0
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1
# additional lines follow - referencing the correct UUID,
# mount point and format for the required disks
UUID="76ef1fc2-1bc5-4a2c-950f-43e99c975da8" /mnt/disk-1 ext4 defaults 0 0
UUID="fba9c513-2117-4245-a41c-f813497b0826" /mnt/disk-2 ext4 defaults 0 0
Save, reboot and disks will be mounted automatically on the defined mount points.
comments powered by Disqus