How to configure LMDS with external USB drive?

At some point, you may want to use LMDS with external storage to keep downloads away from the SD card or allow access to an existing media library.

In case you intend to utilize an external USB drive or network share with LMDS, make sure to mount it and have it available in Linux before deploying any container. If you have any existing containers running, that's okay but you must move current /download and /media folders from the SD card to the USB drive before creating symbolic links to them later.

How to permanently map USB drive to the LMDS?

  • Connect your USB drive to the Pi
  • Find your USB drive in the system

sudo su
fdisk -l

Your USB drive will be listed somewhere in this long list of available storage devices.
Try to look for manufacturer name or identify the drive by its capacity.
My USB drive happened to be /dev/sda and it has NTFS partition created initially in Windows called /dev/sda1

Disk /dev/sda: 37.3 GiB, 40007761920 bytes, 78140160 sectors
Disk model: MHT2040AH
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5c87c2b7

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048 78137343 78135296 37.3G  7 HPFS/NTFS/exFAT
  • Install NTFS access module, necessary to access any NTFS filesystem.
sudo apt-get install ntfs-3g
  • Create a directory that you will use as a mount point for your USB drive, this directory can be placed anywhere and can be called anything you wish. I created hhd directory inside /mnt/ directory.
sudo mkdir /mnt/hdd
  • Mount NTFS partition that we found on USB drive to the folder we just created.
mount -t ntfs /dev/sda1 /mnt/hdd/
sudo umount /boot
sudo mount /dev/mmcblk0p1 /boot
sudo apt install --reinstall raspberrypi-bootloader raspberrypi-kernel
sudo reboot
  • Modify fstab file so your USB drive is always mounted when your system boots.

Identifying the UUID of your USB drive is necessary for it to be mounted automatically. Replace the identifier with the one you saw earlier while executing sudo fdisk -l, which could be /dev/sda1 as well.

sudo blkid /dev/sda1
/dev/sda1: LABEL="ExternakDisk" UUID="F23C6A253C69E4D7" TYPE="ntfs" PARTUUID="5c87c2b7-01"
  • Copy the UUID and edit your /etc/fstab file.
sudo nano /etc/fstab
  • Create record that reflect your situation.
UUID="YOUR-UUID-HERE" "mount point" ntfs-3g auto,rw,noatime 0 2
  • In my case it will be like this:
UUID="F23C6A253C69E4D7" /mnt/hdd/ ntfs-3g auto,rw,noatime 0 2
  • Save and exit Ctrl + O and Ctrl + X
  • Mount what you just added to fstab, if you see no errors after below command, you should see what you had on your USB drive under /mnt/hdd
sudo mount -a
  • Check if you see anything of your USB drive, if your USB drive was empty you wont see anything obviously
sudo ls -l /mnt/hdd/
  • create some test file just to see if you can.
sudo touch /mnt/hdd/test.txt
  • Reboot the Pi and check if after reboot hdd is mounted back and you still see your test file.
sudo reboot
sudo ls -l /mnt/hdd/
sudo df -h
  • In my case, I see /dev/sda1 mounted to /mnt/hdd
pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        30G  2.0G   26G   8% /
devtmpfs        430M     0  430M   0% /dev
tmpfs           463M     0  463M   0% /dev/shm
tmpfs           463M  6.3M  457M   2% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           463M     0  463M   0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   54M  199M  22% /boot
/dev/sda1        38G  2.0G   36G   6% /mnt/hdd
tmpfs            93M     0   93M   0% /run/user/1000

How to configure LMDS to work with external HDD

  • Change permissions to /mnt/hdd so anyone can access it (you can be more specific with permissions if you like)
sudo chmod 775 -R /mnt/hdd
  • Stop all containers
docker stop $(docker ps -aq)

After you deploy some of the containers, you might have couple of folders under LMDS directory, but we are only interested in two of them for now:

  • downloads
  • media
  • Each container that downloads anything will be doing so into ~/LMDS/downloads/ directory - we want this directory to be pointing into external HDD so we do not waste SD card for it.
    "media" folder should have some or all of the subfolders below:

  • tvshows
  • movies
  • music
  • As these folders will contain all "media files" relevant container should be able to access them also, this structure might be quite big, again we do not want this to be stored on the SD card.

    We will create a symbolic links (something like shortcut in Windows) between i.e. downloads folder under ~/LMDS/downloads and downloads folder in /mnt/hdd/downloads

    • Create downloads folder under /mnt/hdd/
    sudo mkdir /mnt/hdd/downloads
    • If you already have existing downloads folder under /LMDS, you should delete it before creating a symbolic link. If folder already exists and have some data you cam move it to /mnt/hdd/ and then create symlink - easy.
    • Create symlink to link /LMDS/downloads with folder on USB drive /mnt/hdd/downloads (we could bind them in fstab but I wont be going to that in here)
    sudo ln -s /mnt/hdd/downloads /home/pi/LMDS/downloads
    • Repeat above to each folder under ~/LMDS/media/
    • or any you want to move and keep on external HDD.
    • Start back all container.
    docker start $(docker ps -aq)

    Help me make LMDS better

    With your support anything is possible