Music on Linux USB hard drives
From SqueezeboxWiki
There are two key issues with storing your music on an external hard drive if you run SlimServer on a Linux machine:
- Path: what file system path SlimServer should use for the Music Directory
- Permissions: making sure that SlimServer can access the music
Typical Automount Path
Many modern Linux operating systems will automatically mount USB hard drives hen you attach them to the computer and are logged in, looking at the normal Linux desktop. Normally the disk will have a filesystem path like "/media/myDisk" if you've named the disk "myDisk".
Typical Automount Permissions
When a Linux system mounts a disk like this – especially if the disk has been formatted as a Windows FAT or FAT32 disk – it will mount the disk such that only the Linux user who's logged in to the desktop can access the drive. The logic is simple – a Linux system is a multi-user computer that may allow external logins by other user accounts. A USB drive plugged into the computer is probably the property of the user who's logged in locally, "on the console", so to speak.
Automount Problem: Permissions
If you've installed SlimServer from an official package – or any easy download method other than the .tar.gz Perl source code or Subversion source code checkout mechanisms – then you should have SlimServer running all the time as a user named "slimserver". This is good. But the automount permissions scheme works against you – if you let Linux automatically mount your USB drive and you're logged in as user "jdoe", then user "jdoe" will typically have full control of the external hard drive, and user "slimserver" won't have any rights to the hard drive at all.
Automount Problem: Availability.
The second major problem with letting Linux automatically mount your USB hard drive is that your USB drive probably won't be available before you log in, or after you log out. So even if you fixed the permissions, you'd risk SlimServer not being able to access your music at all times.
Best Practice Solution
If your USB drive is always attached to your computer and you want SlimServer to have continual access to it, many users feel the best solution is to configure Linux to mount the USB drive when Linux starts up. Before you can do that, you should:
- Determine if SlimServer needs to write to the external disk, or only read from it. Normally SlimServer stores its playlists and database information on your main/internal disk, and only needs read access to your USB drive.
- Decide what local users should have write access to the USB drive.
- Find the UID (user identification number) of the "SlimServer" user and the GID (group identification number) of the "SlimServer" group.
- Find the USB drive's /dev device name.see note
For the last two steps, plug in your USB drive so that Linux mounts it and open a Terminal window. At the command prompt, enter
id slimserver
and you should see a response like
uid=502(slimserver) gid=502(slimserver)
Yes, normally the UID and GID are the same. Normally. Do the same for your personal account, and note its UID and GID. Next, enter
df -k
and look for the line referring to your USB drive, something like
/dev/sdd1 1581232 1275752 225156 85% /media/myDisk
The disk in this example is "/dev/sdd1".
Now right-click on the drive icon on the desktop and Unmount or Eject it – but leave it plugged in.
Now you'll need to edit the /etc/fstab file as the 'root' user. First, back up the existing file
sudo cp /etc/fstab /etc/fstab.SlimServer-backup
The edit the real file with
sudo gedit /etc/fstab
and add a line like the following, substituting your UID where the example has "501", the slimserver GID where you see "502", and your disk's /dev name where you see "/dev/sdd1". If you want SlimServer to have write access to the drive, change the second digit in the umask number to "0" (e.g., umask=007). If you want all local users to be able to read the contents of the hard drive, change the third umask digit to "2"; if you want everyone and everything that has access to your machine having full control of the disk drive, use umask=000:
/dev/sdd1 /musicdrive vfat rw,user,umask=027,uid=501,gid=502 0 0
Save the file. Next, make the /musicdrive directory with
sudo mkdir /musicdrive
Now, use the "df -k" command again to verify that the USB drive is not currently mounted, and mount the disk:
sudo mount /musicdrive
Run
df -k
again and see that you have a /musicdrive entry. If so, you should be set so that only you can modify/delete/write to the drive and SlimServer can read from the drive, and other users cannot access it at all. Use the SlimServer web interface to set the Music Directory to /musicdrive and you should be able to browse the music folder through the web interface or with a Squeezebox.
Notes:
- 1: In most modern versions of Linux, there are more reliable ways to identify a particular drive than a name like /dev/sdd1. Someone should add information about these alternatives.