This is a step-by-step guide on how to add files to a Linux media server, that is headless. Headless means no keyboard, mouse and monitor attached to it. So the only way to administer or control it is through another machine that has a terminal emulator program, installed.
For this guide, we’re going to use PuTTY.exe
(for Windows) or Linux Terminal App (for Linux) to make a remote connection to the headless media server and enter the necessary commands to administer our remote headless server. Keep in mind that, though I mentioned Remote
it doesn’t mean that the server is from somewhere else outside our LAN. The server that we are accessing is our own Linux server within our Local Area Network.
So for this guide, both machines (Server and Client) resides within our Local Area Network (LAN) only.
If you want to move on with this guide, you should already have a working Linux server, installed with Plex Media Server software and another PC to run our choice of terminal emulator that will serve as our SSH client. If you don’t have a working setup yet, and you’re somewhat clueless on how to set things up, then I suggest that you follow the guide on how to setup a headless server with Ubuntu plus Plex Media Server.
You need to get the following things prepared, and make sure that it’s all working, before starting with this guide.
Things Needed:
- A Working LAN connection (GigaLAN is recommended)
- Client PC either installed with Windows or Debian-based Linux (Ubuntu or Linux-Mint)
- Some Media Files to work with
- Extra Hard Drive, to load your media files into
- Putty.exe if you’re on Windows
Whenever you’re ready, just read further below to start-off with the guide.
Steps: Adding Files To Your Headless Linux Media Server
For this part of the guide, I’m going to show you how you would do it on a Windows-based machine and a Debian-based machine (Ubuntu or Linux Mint). So this is going to be a two-version “Howto”, Linux version and Windows version. But both version are similar, this won’t be a headache if whether you’re on Windows or Linux.
Before we start, make sure your Linux media server boots fine and starts all the way until you see the login prompt (black-screen with blinking cursor). If all is fine, you may detach everything (keyboard, mouse and monitor) except the LAN cable. We’re going to configure a headless Linux server via command-line so you won’t be needing those.
Linux Version: Ubuntu-based Machine Running Linux Mint
For this version of the guide, I will use my Linux Mint machine to configure my server. I’ll just use my native terminal app to SSH my way to the remote machine.
For this guide, you need to get the following info from your remote Linux server, In my case:
- IP Address –
192.168.1.99
- Hostname –
ubuntu-plex.chubbable.loc
- Hard Drives – 1 80GB Seagate Linux boot-drive & 1 1TB Seagate empty hard drive (To put files into), 3TB Seagate GoFlex (to copy media files from)
- OS installed in my Linux Media Server –
Ubuntu 14.04.1 LTS Server Edition
- OS installed in my client machine –
Linux Mint 17
There are various ways on how to add files to a headless Linux media server. It depends on certain scenarios, and each scenario should be handled in a different ways. There several methods on how to add files with each scenario, but they all end up using the cp
or `rsync’ command-line, and such scenarios are enumerated below.
You wanted to add files from:
Existing media collection stored in external USB/Sata drives. In this scenario, you either have files stored in an external drive and you want to copy the files to your newly built media server. You may use a keyboard that is directly attached to the server you need to configure and use the command-line to copy files from your external source drive.
Existing media collection stored in a NAS drives. In this scenarios you want to copy your media files from your NAS (Network-attached storage) drives to your media server.
Existing media collection stored in a separate hard drive partition. In this scenario, you want to copy your files from a drive partition stored in the same hard disk your OS is booting from. So this means, the drive is attached to your current client machine that you’re about to use to administer your remote Linux media server.
Server-to-server copy. A situation where you need to duplicate files directly from another media server. Generally, this would be a network-to-network file duplication.
Let me tackle first with the first scenario, where you want to copy files from existing media collection stored in an external drives.
Procedures: Adding Files From External Drives
Step 1: After making sure that your server boots properly, turn it off so you can attached your external drive. To do a graceful shutdown of your media server, you need to login using the command-line. So type in
username
then hit enter, enter your password and hit enter again. Then type this,sudo shutdown -h now
. When prompted to enter a password, type your user password.Let’s say you have an external USB drive (like my 3TB GoFlex by Seagate), plug it in to any available USB-port and turn on your Linux-based media server. You may re-attach your keyboard and monitor if you want to. Supposedly this is a headless Linux media server, but you may attach those for this particular setup guide and then detach it again when you’re done.
Step 2: If your server booted up without issues, switch to your Linux machine and open a terminal (ctrl + t). Then type
ssh [email protected]
. in my case it’sssh [email protected]
.Note: username is the user name you set during the server installation.
You should be prompted to enter your password.
Note: When you type in your password, it will not be printed on your screen.
If your login detail is accepted, you’ll be prompted again, it will ask you to accept the connection or not. Of course you should answer
There are no photos with those IDs or post 1374 does not have any attached images!Yes
to make the server connection.Step3: Now we’ve established a server-client connection via SSH. We could now partition and format our hard-disk using the command-line. We need to do this, before we could transfer files into it. The instruction below shows you how to partition and format a hard-disk using terminal commands.
First of, we need to confirm that our media hard-drive is properly detected in our server. To do that, use the following command-line:
sudo fdisk -l
The output should be similar to the show image below. There are no photos with those IDs or post 1374 does not have any attached images!
or you could do like this,
sudo fdisk -l | grep '^Disk'
Base from the output shown in the image, you could easily determine which one is your target drive. In my case, my target drive is a 1TB hard drive, while my boot drive is an 80GB hard drive (with 3 partitions).
Sample output from my machine:
chubbable@ubuntu-plex:~$ sudo fdisk -l Disk /dev/sda: 1000.2 GB, 1000204886016 bytes 81 heads, 63 sectors/track, 382818 cylinders, total 1953525168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x690d522a Disk /dev/sdb: 80.0 GB, 80025280000 bytes 255 heads, 63 sectors/track, 9729 cylinders, total 156299375 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000127dc
My target drive is identified as
/dev/sda
, so let’s use that info to partition the drive using the command-line. Let’s do the following.Type:
sudo fdisk /dev/sda
Enter your password when prompted, hit enter, and you’ll be prompted to input a command. See image below.
There are no photos with those IDs or post 1374 does not have any attached images!type in
n
to create a new partitionthen, you will be prompted to choose which type of partition to create, since this is going to be a dedicated media file storage, we should select
P
to create a single partition. So that would be one Primary partition and all the drive space should be allocated to it.So let’s move on and enter
p
and hit enter.When asked to select how many partitions you want to create, type in
1
and hit enter.Then hit enter when asked about
First sector
andenter
again when asked aboutLast sector
Finally, type in
w
to commit your configs.At this point, you should have already created a single primary partition. To double check on this, you may type in
There are no photos with those IDs or post 1374 does not have any attached images!sudo fdisk -l
again. You should see a partition number appended to your drive’s device name. In my case my target drive has a device name of/dev/sda
. After creating the partition, it shows my partition like this,/dev/sda1
We’ve created a new partition, so we need to format the drive before mounting it to our headless server. It is recommended to format the drive in a format that Linux supports natively (ext3/ext4). In my case I’ll format my drive in ext4 format.
So I would do it like this:
- Type in
sudo mkfs.ext4 /dev/sda1
and pressenter
. - To create an ext3 partition, use
mkfs.ext3
.
- Type in
Step 4: Let’s mount our newly formatted hard-drive to a specified location. In order for us to access the drive via mount points or folder name, we should mount it first via
fstab
. We need to create a custom folder for this. In my case, I will name my mount point asMyMedia
. And this shall be created inside/mnt
folder. You could also create the folder inside/srv/
folder.Note: You may create the folder in other location like
/srv
or/home/username/your-folder
.To do this, type the following in your command-line:
sudo mkdir /mnt/MyMedia
Note: Substitute MyMedia with your desired folder name.
Mount
/dev/sda1
to/mnt/MyMedia
by typing the following:sudo nano /etc/fstab
Then press enter. You should see a screen similar to the outputs below:
There are no photos with those IDs or post 1374 does not have any attached images!Now we need to put the following configs in our
fstab
file, so our media drive will be auto-mounted each time our server boots up:# My 1TB Hard Drive /dev/sda1 /mnt/MyMedia ext4 defaults 1 2
Note: Substitute
/dev/sda1
with your device name,MyMedia
andext4
with your own configs.After doing the above, press
ctrl
->o
->enter
, to save your configurations. You should be taken back to the command-line.Now, let’s mount the drive via command-line by doing the following, type:
sudo mount -a
The command tells Linux to mount all devices configured in /etc/fstab, this includes mounting your newly configured hard-drive.
To check if the system had mounted your device to your specified mount point, you would type:
du -h
A sample output would be:
chubbable@ubuntu-plex:~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sdb1 72G 1.5G 67G 3% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 864M 12K 864M 1% /dev tmpfs 175M 1.2M 174M 1% /run none 5.0M 0 5.0M 0% /run/lock none 875M 4.0K 875M 1% /run/shm none 100M 0 100M 0% /run/user /dev/sda1 917G 72M 871G 1% /mnt/MyMedia
Now our dedicated media drive is ready. Proceed to the next step below.
Step 5: Copy files from external hard-drive to media server drive. To start with this task, plug in your external USB drive (or SATA Drive) which you would want to copy files from. In my case I’ve already plugged in my 3TB Seagate GoFlex external hard drive, this drive is formatted as
NTFS
, since it was taken from a Windows-based media center. I use this to backup several types of files and it’s my master backup drive.Sample output for
sudo fdisk -l
:Disk /dev/sdc: 3000.6 GB, 3000592977920 bytes 255 heads, 63 sectors/track, 45600 cylinders, total 732566645 sectors Units = sectors of 1 * 4096 = 4096 bytes Sector size (logical/physical): 4096 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk identifier: 0x1bbd4e35 Device Boot Start End Blocks Id System /dev/sdc1 63 732563999 2930255748 7 HPFS/NTFS/exFAT
As you can see from the above outputs, my 3TB hard-drive is detected as
Disk /dev/sdc: 3000.6 GB
in my Ubuntu Linux box. We need to mount (via command-line) this device first before we could copy files from it.To mount this device, we need to repeat the steps we took previously. That is, create a mounting folder for the device, and mount it manually from the command-line. We don’t have to insert the configs in the /etc/fstab file, since we are mounting this drive temporarily. We only do this to mount our external drive so we could copy media files from it and add it to our internal media hard drive.
I’ve moved on and mounted my 3TB hard drive in
/mnt/3TB
. I have a folder calledMyMovies
in my hard-drive’s root. When I mounted my drive, the folder should be accessed from my media server via/mnt/3TB/MyMovies
.To access this folder, I would type
cd /mnt/3TB/MyMovies
.Alright, now that we had mounted both our source-drive and destination-drive, we could copy files from the source and put it to our destination media-drive. In my case, it’s
/mnt/MyMedia
.Keep in mind that for this scenario, we are copying multiple files and probably multiple folders and sub-folders. So the natvie copy
cp
command shipped with Linux would not be the best tool to do this particular job.The tool that I chose to use is
Rsync
. This is readily available in Linux, it’s comes pre-shipped with it and ready to use.So let’s use it now to copy our media files to our Linux-based media server. To start-off with this step, do the following:
While still in the command-prompt, type in:
sudo rsync -avr source-folder destination-folder
In my case:
sudo rsync -avr /mnt/3TB/MyMovies /mnt/MyMedia/
The command tells rsync to copy files and folders recursively from my 3TB MyMovies folder to my 1TB media folder. The whole of
MyMovies
folder will be copied inside the folder/mnt/MyMedia
, so it would look like/mnt/MyMedia/MyMovies
.In case you only need to copy new files from the source-drive or update the existing contents of your destination folder, then you would do like so:
sudo rsync --update -raz --progress --ignore-existing --inplace source-folder destination-folder
Note: An advantage of configuring your server from another machine with a terminal emulator is that, you could easily type a command by copying and pasting snippets into the command-line. Unlike when you’re typing directly from your server’s keyboard. You don’t get the chance to easily copy and paste a snippets. Unlike when you’re using a terminal emulator, you could just copy and paste any text in the command-line with ease, using either your keyboard or mouse.
Step 6: Alright, we’ve added some files to our linux-based media server, it’s time to organize and import the media files to Plex Media Server’s Library. We’ll make use of the Web-GUI this time to add and organized our media collection.
6.1: So let’s fire-up a browser and type-in…
linux-media-server-address:32400/mange
, and hit enter. You should be looking at Plex’ admin GUI right now.6.2: From the top-left corner of the page, click the plus
+
icon beside the gear icon. A new pop-up window labelAdd Library
should appear.
- 6.3 Click one of the icons (Movies, Music, Photos, etc.) you would like to add. Let’s say, you clicked on
Movies
, you need to clickNext
and thenAdd Folder
. You may now add the directory from you linux-based media server by clicking on the righ-pane of the window. You may browse-through the folders or type it’s folder path directly in the input-field. When you have selected your folder, clickADD
button located in the bottom-right of the window, then clickAdd to Library
button to start adding the files.
- 6.4: Done. You have successfully added your media files.
There We Have It
We’ve copied and added our media collection to Plex’s Media Library. That’s how easy it is to organized and add your media collection to a Linux-based media server, thanks to Plex’s awesome features.
If there is something I missed with this guide, or something that you wanna add, just make it so and put your comments below.
In my next post, I’m going to write a guide on how to configure and secure a Linux-based media server. I’ll show you how to enable and configure a simple firewall and a key-based authentication method when logging in to your Linux Media-Server. In addition to this, I will be writing a guide on how to easily manage your media server remotely, with the use of 3rd-party Open-Source tools and applications.
I hope this guide on How To Add Files To A Headless Linux Media Server, helped you out in building your own media-server and potentially you’ve gained some knowledge about Linux command-line syntaxes.