Saturday, May 4, 2013

Vortex box add external USB drive in Linux for movies and music.

If you built a Vortexbox for all your music and have been using it for a while, chances are you stumbled across the fact that Vortexbox using Makemkv is also good all by itself for Ripping DVD videos for your archives. But it is not that great at serving them up. This is where Plex comes in as a media server for your videos. The problem you may encounter when you initially build your Vortexbox is that a 250Gb drive by itself will hold a lot of music, but not when there is video involved. Before long you will find yourself with a drive that is almost full. So how do you fix it? Buy a huge drive and completely re-install your system? This is a pain to say the least. My solution involves using external USB drives and adding storage in addition to what you already have.

When I initially built my Vortexbox, I didn't have any decent sized internal hard drives for the box. So I installed an 80Gb drive to install the operating system on, then I installed an external 360Gb USB 2.0 hard drive, and mounted the /storage folder to it. This was great until I started adding MKV videos and filled the drive after about a month. that only took about 50 movies in addition to my 900 or so music albums.

Now I obviously don't want to rip everything again, and I figured if I could get the movies onto another drive I would have room on the main drive for at least another 1000 music albums. I picked up a 1tb External USB 3.0 drive from my local Wally World for $59 and proceeded to figure out how to do this. There were no good tutorials on this subject so I decided to write my own.

My goal in the future is to have an external hard disk for each type of media served by the VB machine. The OS will run on an internal drive, then have separate drives for Music, Video, Pictures and possibly TV Shows. This way if I have a crash it only affects one media, and with good backups this won't matter much. (Follow Up: I did indeed have a crash of the very drive about a year after I installed  it using this tutorial. I guess I see now why it was on clearance. Luckily I had backed everything up to another server.)

Install the USB Hard Drive
Your first step is to get the VB to recognize your USB hard drive. This is not that hard and is basic Linux commands and editing. so let's get started.

  1. Plug in the USB drive. I prefer using USB drives that have their own power supplies, as these do not draw down on the PC's power supply. This can cause issues in the future.
  2. Log in to your VB machine. Either locally or as I do using an SSH console from a Windows laptop. 
  3. Use the following command to find the device name of the new USB drive.
    cat /etc/vortexbox/CurrentUsbDrive.txt  should be something like /dev/sdb depending on your setup.fdisk -l  will also give you the info you need.
  4. You need to create a folder to mount your new drive to. If your adding this for the main storage a newly built vb machine then your going to mount the drive to /storage. Or if like me your planning on this being your drive for movies, and leaving the rest of the file system intact and your planning to move the movies to this drive then for now you will mount them to /storage/movies2. To do this type mkdir /storage/movies2. 
  5. Next we need to mount the drive. If your mounting it to replace /storage completely then use step #1. If like me your using the new drive for the /storage/movies folder then use #2
    1. First un-mount the current storage using umount /storage Next manually mount using
      mount /dev/sdb1 /storage, 
      1. sdb is to be changed to the device name you found in step3 
      2. Note the 1 added after the device name, this tells it to use the first partition of that device.
    2. If using the drive for a folder inside of storage and moving files to this drive use this mount procedure.
      1. Create a folder with the same name as the one your replacing, but add a 2 after it. Such as mkdir /storage/movies2 or mkdir /storage/music2  
      2. Manually mount the folder using mount /dev/sdb1 storage/movies2
        1. sdb is to be changed to the device name you found in step3 
        2. Note the 1 added after the device name, this tells it to use the first partition of that device.
  6. If manually mounting works ok then we need to set your machine to auto-mount the drive after a reboot. Before we start we need to make a copy of the files we are going to edit. Do this by running these commands.
    1. cp /etc/fstab /etc/fstab-old
    2. cp /etc/samba/smb.conf /etc/samba/smb.conf.old
  7. We need to edit the fstab file to mount the drive at boot. Use step one if your replacing /storage or step #2 if your replacing /storage/movie only.
    1. /storage Replacement - Type nano /etc/fstab to start editing the fstab file. You can use your favorite editor if you don't like nano.
      1. Remove the line that currently mounts /storage.
      2. Add the line /dev/sdb1 /storage ntfs defaults 0 0
      3. If you want it mounted regardless of device ID, say if you plug it into another USB port or add another drive while this one is disconnected then do the following.
        1. blkid /dev/<DEVICE NAME FROM ABOVE> (Example: "blkid /dev/sdb1")
        2. Add this to the fstab (instead of the /dev/.... above)
          UUID="XXXXXXXXXXXXXXXX" /storage ntfs auto,noatime,user 0 0 
        3. replace the X's with your UUID from the command above.
        4. Save and Exit
    2. /storage/movies replacement - Type nano /etc/fstab to start editing the fstab file. You can use your favorite editor if you don't like nano.
      1. Add the line /dev/sdb1 /storage/movies2 ntfs defaults 0 0
      2. If you want it mounted regardless of device ID, say if you plug it into another USB port or add another drive while this one is disconnected then do the following.
        1. blkid /dev/<DEVICE NAME FROM ABOVE> (Example: "blkid /dev/sdb1")
        2. Add this to the fstab (instead of the /dev/.... above)
          UUID="XXXXXXXXXXXXXXXX" /storage/movies2 ntfs auto,noatime,user 0 0 
        3. replace the X's with your UUID from the command above.
        4. Save and Exit
    3. This assumes your using an NTFS formatted drive. if you change the formatting to say EXT4 then you will have to research how to modify the commands to work for them.
  8. Next we need to share the folder using Samba. this way we can see the folder on other machines.
    1. Type nano /etc/samba/smb.conf
    2. Add the following code to the bottom of the file.
    3. [Movies]
      path = /storage/movies2
      guest ok = yes
      writeable = no
      create mask = 0777
  9. Test the Automount by typing the following
    1. umount /storage or umount /storage/movies2
    2. mount -a will remount the entire fstab.
Copy Files to New Drive
Whether your replacing the whole /storage or just one folder. One thing you will not want to do is re-rip all your files. Well you don't have to. I constantly read where people say do a backup, then restore it when the new drive is in place. That works when you replacing the entire storage folder but is overkill for the single folder. But for the single folder I prefer just to copy the files over from one drive to another. There are several ways to do this but I prefer the Rsync command. CP will do it as well but Rsync will retain your times and permissions on the files for you. It is also restart-able at a later time if something goes wrong.

    • rsync -rtvu --progress /storage/movies/ /storage/movies2
    for the movie folder replacement
    • Go get some coffee, eat dinner, go to bed, check back tomorrow. 
Change mount point
So no we have the new drive installed, it is mounted automatically at boot and all our files are copied or restored from a backup to the new drive. If your doing the /storage replacement your done. For the movie change we need to remount the /storage/movies2 to the original /storage/movies. I would recomend a backup in addition to the copy to the movies 2 folder. I also tested the movies2 files by adding the folder to my plex server and playing the movies from them to ensure they were going to work.
  1. First delete all the files in the original movies folder. rm -rfv /storage/movies/* This can take a while.
  2. Change the line you added to the fstab from /storage/movies2 to /storage/movies.
    UUID="F87C1A927C1A4C2E" /storage/movies ntfs auto,noatime,user 0 0save and exit.
  3. Type nano /etc/samba/smb.conf and change the line in the samba config from
    path = /storage/movies2 to path = /storage/movies save and exit.
  4. Reboot your server. I have tried un-mounting the drive etc., but a reboot just seems to work best.
Verify all your movies are now available in the /storage/movies folder. If they are then, and ONLY THEN, delete the /storage/movies2 folder.
You should now be in business with your new USB drive in full operation. 

All information here is provided without warranty of any kind expressed or implied. User performs this procedure at their own risk.

Post a Comment