User Guides How to build a low cost Linux Home Server

Introduction

Do I need a home server you ask?
Do any of the situations below sound familiar?
  • You have 2 or more computers at home with files fragmented between them and multiple copies of multiple files (music/movies/docs) spread all over the place?
  • You are a compulsive downloader and have accounts to multiple private trackers. Your primary beast machine runs 24X7 guzzling power and dissipating heat only to use like 0.1% of its processing capabilities while downloading
  • You have often felt the need to gain access to some of the files at your home while visiting friends/colleagues. Like, " Oh, I wish I could show you the pics I took in the last office party...If only I had remembered to carry them in my pen-drive"
  • You are at office and someone is raving about a new album and you wish you could hear it the moment you hit home
  • you are stuck in a traffic jam and realize you forgot to start that all important DivX to mp4 conversion for a bunch of videos
If the answers to any of the above is yes, hehe, you need a home server

So what and how is this home server going to run? What else but Linux on some very basic hardware. And best of all, there is no need for even a mouse/Keyboard/monitor

Step 1: Arrange the hardware

The first step would be to rummage through your old parts and try to get hold of :
  • a pair of mobo/cpu..anything over a 300mhz Celeron will do. Having said that, it does not hurt to have a 600mhz + system
  • compatible RAM - 256 MB or more
  • A HDD - The server per-se will work off even a old 8 GB drive, however, you do want storage space too..right?
  • a basic PSU
  • You will also need access to a CD drive/mouse/keyboard/monitor for the one time setup
  • Assemble the setup and hookup your box to your router through an ethernet cable
Step 2: Get the software and kickstart

  • Head to Ubuntu ( Download Ubuntu | Ubuntu) and get hold of Kubuntu
  • This guide talks of Kubuntu though feel free to grab ubuntu (with Gnome) or XUbuntu (with XFCE, meant for very low end setups)
  • In the end, it really does not matter, because once the setup is done, you will be disabling the GUI anyway.
  • The only difference between Ububtu/Kubuntu/Xubuntu is in their desktop environment which you will be disabling once you are through with the setup.

Tip: Download using the torrent option if you don't wand a 700MB download to fail mid-way

Once the download is done, burn the ISO on a CD and boot from the CD.


Your system will boot into a live Kubuntu KDE deskto from where you can choose the install button right from the desktop
Installing KUbuntu is very straightforward, just a couple of options to choose in the nice and intuitive GUI based install.

Tips:
  • - Choose a guided partition and use the entire disk (instead of resizing a partition) to avoid filesystem complexities later
  • - Make sure you use a good and secure password for the root account as well as the user account since your system will be fully accessible from the web and a malicious root login into the box can wreak havoc


Now just sit back and relax while KUbuntu gets installed which should take between 20 mins to 1 hour depending on your rig specs

Once installation is completed, you will get a reboot prompt
Make sure you set the 1st boot device as HDD in the BIOS (or at least remove the CD) else your syatem will boot back in the live environment


Step 2: Time to get Rolling - Installing Packages

Ok, it's finally time to install and setup all the required packages (software) that will enable this box of yours to run as a full fledged server.

Here is one basic Linux rule. You cna use a GUI based interface for nearly any application/task (the way you do in windows), but you can always use the CLI (command line interface) to do the same thing. And often, it's faster and more effective to do things in the CLI.

However, let's use the GUI for adding software to start.

It's called Adept package manager in KDE (Kubuntu) and Synaptics package manager in GNOME (Ubuntu) and would be available under Start>System> in Kubuntu and simlarly in Ubuntu

A big crib that people had against linux earlier was the fact that installing any additional software required the user to install the software and then find out and install alll dependencies too.


Package managers like Adept take care of it automatically by installing the chosen software along with all its dependencies.


A) Upgrade packages

Upgrade all available system packages by upgrading all

B) Setting up the NAS file server (File Sharing on the internal network)

Assuming you are using a big HDD for your server, one of the primary requirements for the setup is to act as the primary media/documents hub for other machines on the network.

Unlike windows NTFS that plays foul with other Operating systems, Linux's ext3 is more than happy to allow easy universal read/write access from any other operating system via a package called Samba file server.

To get started,
  • fire up adept package manager, search for Samba and install the Samba server package.
  • Once the install is done, it is time to do a one time configuration
  • Fire up the CLI (Konsole in Kubuntu, terminal (?) in GNOME)
Basic Tip: In Linux, any modifications outside the user home directory can be done only by the super user (root). Think of it is Vista UAC, but far more effective and powerful. Modifications to Samba will obviusly need root access. Here is how:
  • type sudo su then enter password when prompted (super user do to get temporary super-user privileges)
  • type cd /etc/samba (etc is the config directory for apps) then nano smb.conf (Nano is the CLI text editor, so this command opens the samba config file for editing)
  • Tip - You can always use the GUI editor- Kate...to run Kate as admin, go to start - run command - Kate and choose run as different user option set as root (You need to run Kate as admin because /etc/samba is out of your restriced normal user account. As a normal user, you have access only to directories within /home/user)
  • Use the following config settings..just replace the text in smb.conf with the text in the codebox...feel free toask qstns on any of the options
  • Code:
    [/LIST][code][global]
    panic action = /usr/share/samba/panic-action %d
    workgroup = "workgroup"
    netbios name = "NASbox"
    invalid users = root
    security = user
    wins support = no
    log file = /var/log/samba.log
    log level = 3 
    max log size = 1000
    syslog = 1
    encrypt passwords = true
    passdb backend = smbpasswd
    socket options = TCP_NODELAY
    dns proxy = no
    passwd program = /usr/bin/passwd %u
    passwd chat =*Enter\snew\sUNIX\spassword:* %n\n *Retype\snew\sUNIX\spassword:* %n\n .
    obey pam restrictions = yes
    pam password change = no
    null passwords = no
    
    #Share Definitions
    
    [superczar]
            comment = Home Directories
            browseable = yes
            writable = yes
            security mask = 0700
            create mask = 0700
    • Save and restart Samba by /etc/init.d/samba restart on the CLI (/etc/init.d is te initialization (?) daemon that you can use to stop/start/restart any running process. We are doing it here for samba to reload the config settings
    • Setup a fileserver user name by smbpasswd -a superczar and then add a password when prompted (smpasswd is the samba password set command, -a is operator to add user, use any user name of your choice in place of techenclave...superczar is a good choice though for good luck :p)
    • NAS box is set :D
    Test your NAS box by starting your windows machine and typing in \\machine-alias\superczar

    enter user id/passwd that you set earlier and bingo...you have a 1 TeraByte NAS box at your disposal :)
    It would be a good idea to map this address as a netowork folder so that it is accessible directly from the windows explorer shell as X:\ (or whatever you choose).You can easily do it by Tools>Map Network drive in windows explorer

    B) Setting up SSH (for access from the web or your home network)

    Now that you have got a basic hang of linux, things will be easier.
    • Use Adept to install openssh-server. Even better, use the CLI by doing a sudo su then apt-get install openssh-server (apt-get is advanced package tool)
    • Done
    Test SSH by using putty

    (Wiki says: [SIZE=-1]PuTTY is a terminal emulator application which can act as a client for the SSH, Telnet, rlogin, and raw TCP computing protocols. ) [/SIZE]and
    Also get winSCP (wiki says [SIZE=-1]WinSCP is a SFTP client and FTP client for Windows. Its main function is the secure file transfer between a local and a remote compute)[/SIZE]

    Remember the idea from the beginning of this tut? You have often felt the need to gain access to some of the files at your home while visiting friends/colleagues. Like, " Oh, I wish I could show you the pics I took in the last office party...If only I had remembered to carry them in my pen-drive"

    SSH over winSCP is what will handle this.

    Just WinSCP to your server from your friends' place and pick whatever file(s) you need
    C) Setting up LAMP :S for Torrentflux


    Possibly the most interesting and also the most complex part of this exercise.

    Torrentflux will run 24X7 as your torrent client and will be controlled via a browser based interface to add/edit/run torrent as well as http transfers

    I use a modded version of torrentflux called Torrentflux-b4rt
    Thats what this guide will talk about.

    But before setting up Torrentflux, there are several dependencies you need to take care of.

    Running a full fledged seedbox requires setting up a webserver and a database on your server for which we will use Apache and MySQL respectively (aka LAMP server - Linux-Apache-MySQL-PHP)
    • Fire Adept - Install phpmyadmin, apache2 and mysql-server-5.0 along with their dependencies
    • Test apache is running by pointing your browser to localhost and ensure you see something like this
      Don't worry if you don't see the rest of the folders, you should be able to see apache2-default for now.
      D) Setting up Torrentflux-b4RT

      • Head to BerliOS Developer: Project Filelist
      • Grab the latest tar
      • Untar by double clicking using the ARK (extractor) GUI if you like, or you can always tar -jxvf filename
      • follow the instructions in the INSTALL file.. I used the manual install method quoted below, else you can also use the automatic method given in the INSTALL file
      -----------------------------------------------------------------
      Manual Installation
      -----------------------------------------------------------------

      1. Untar the package into a directory then copy the contents of
      the "html" folder into your web site directory.

      tar -jxvf torrentflux-b4rt_1.0.tar.bz2

      2. Create a database and import the sql-script.
      You may specify the type of the database you want to use in
      the file "config.db.php", but the examples here use MySQL.

      mysqladmin create torrentflux

      "mysql_torrentflux-b4rt-1.0.sql" contains the commands to
      build the table structure and the default data. Import the
      script into your torrentflux database.

      mysql torrentflux < mysql_torrentflux-b4rt-1.0.sql
      Or load the script with PHPMyAdmin (web interface)

      3. rename the file "config.db.php.dist" in the dir "inc/config/"
      to "config.db.php" and set the database-settings to use your
      torrentflux-database.
      You may specify type of database you want to use, but
      the examples here use MySQL.

      4. ensure the files + dirs in the docroot are readable by your
      webserver-user. if it is not the case one possible solution is
      to "chown" the files to your webserver-user. this may be done
      with a line like that :
      chown -R username /path/to/torrentflux-docroot
      change dir + username to fit your system so a possible line
      would be :
      chown -R www-data /var/www

      5. Remove or rename the file /path/to/torrentflux-docroot/setup.php.
      This is a security precaution to ensure a malicious user does not
      attempt to overwrite your torrentflux-b4rt installation. Your
      installation will not run with setup.php in the document root folder.

      6. IMPORTANT: The first time you access the application, you
      will be prompted for a user/password -- this is when you will
      set the SUPER ADMIN user and password by what you enter. For
      example, you pull the site up for the first time, you will
      be prompted to login and if you put in user: 'goombah' and
      password: 'iama' then your super admin user account will
      be set to goombah/iama.

      7. On your first login you should check all the admin settings
      pages and configure your installation.

      Whopppeeee!!!!!!!!! :hap2:

      Nearly done!

      Now there is no point me trying to explain how to configure and use Torrentflux-b4rt. The site forums have a fairly detailed faq.
      If you run into issues, feel free to ask me.


      E) Setting up CGI-Proxy

      Easy stuff now...
      • Head to SourceForge.net: PHProxy
      • Download, copy contents into a new folder called xyz (or whatever) under /var/www/
      • Done
      Now http://localhost/xyz should show you something like this



      This tiny thing will ensure you can enjoy access to all sites channelled via your home server from behind content filtered places (like your office) :devil2:

      F) Gain access from the outside world

      F-i) Opening Ports

      Now that we are more or less done, and most of the required services are up & running on your server, we need to ensure that all of this can be accesses from outside your house too...right?

      TO do that, we need to open the ports that each of these services uses viz:

      • port 80 for http (Apache webserver)
      • port 23 for SSH
      • port 443 for https (optional- we'll come to this later)
      • port 10000 (for webmin- we'll come to this later)
      • port 5900 (for x11VNC - later)
      I really can't describe the port forwarding process for all connection types, but there are enough guide available on the net.

      In my case (Airtel ADSL on a beetel 220bx modem connected to a Linksys WRT 54G router), here is what I did:
      • Open http://192.168.1.1/main.html (for access to modem settings)
      • Added the ports above to be forwarded to 192.168.1.2 (WAN IP of my Linksys router)
      • Opened http://192.168.2.1 (for access to my router) and added the ports above to be forwarded to 192.168.2.120 (IP of my NASSeedbox :p)
      • TIP: Configure a static IP address for your Linux box to ensure your forwarding settings don't get messed up if your linux box gets a different IP from the router DHCP in case of reboot
      F-ii) Configure a URL for yourself

      Since most of us do not have the luxury of a static IP address from our ISP, we need to use a service like dyn-dns or no-ip to map our dynamic IP to a static URL.

      These services place a small client on your machine that transmits your Internet IP address to their server at pre-determined intervals

      The service provider then maps the IP to the URL of your choice

      I use no-ip as you can install the client directly from adept
      • Head to no-ip.com and register on their site
      • choose a domain name like xyz.bounceme.net (or whatever)
      • Install no-IP client via adept (or do a sudo apt-get install no-ip)
      • configure no-IP by running sudo no-ip -C)
      • Add your login ID, password and update interval (I have set it as 15) to the configuration for no-ip
      • Wait a few minutes for the DNS to propagate, then ask a friend sitting ooutside your network to access your webserver by pointing to http://xyz.bounceme.net (or whatever)
      • VOILA!!!!!
      Nearly Done.......

      G) Installing web-admin tools (Optional)

      You can setup Webmin which is a supremely powerful web adminstration utility.

      Download from here: SourceForge.net: Downloading ...
      • Straightforward installation. Setup a userID and password when prompted
      • Use a complex ID/PW since webmin is all powerful with root access and will also be available from the web...not the kind of setup you'll want to leave insecure.
      • Once done, point your local browser to https://localhost:10000 and login with the UID/PW you set earlier
      • Webmin runs on port 10000 which is why the :10000 at the end of the URL
      • If you intend to use webmin from the outside world
      Be careful when fooling around with webmin though and make sure you know what you are doing before applying any changes you make via webmin



      If you intend to use webmin from behind say an office proxy that blocks ports other than http ports, you can set your router to port forward port 443 (https port) to port 10000 of the server.
      After this, a https://xyz.bounceme.net will lead you to webmin while http://
      xyz.bounceme.net will take you to your apache server (for Torrentflux/CGIproxy etc)


      H) Making the server headless

      Now that the server is all setup and done, time to cut off its head.
      But before we remove the monitor kb/mouse, why not disable the GUI? what point wasting CPU cycles on the GUI if there is no monitor?

      But before we do that, a couple of things:

      • Set your user to auto-login through control center>User accounts (so that you don't need to manually login on a resume after power failure..not an easy task to login without a monitor..is it? :p)
      • you may want to install x11VNC so that you can enable and access the GUI from another machine if the need arises. x11VNC installation guides are all over the web, just google (x11VNC is like remote desktop on Windows)
      now from the konsole, do a sudo su
      Then do a /etc/init.d/kdm stop (or gdm stop for ubuntu)
      now your monitor will fall back to the basic commandline

      Take out the monitor, keyboard and you are all set.....whew :beer:

      More Tips
      • Putty through SSH to gain access to the CLI whenever needed
      • If you need access to the gui, connect to the CLI via putty and do a sudo su and then a /etc/init.d/kdm start
      • Here is a tip for making the above easier..use Kate (any text editor) to create a file called gui-on and add
        Code:
        #!/bin/bash
        /etc/init.d/kdm start
        to it...Save it to /usr/bin/ .... nest time you want to enable gui, just type gui-on on the command prompt ;)
      • You can similarly create gui-off
      • Once KDM has started, you can use VNC to view and control your screen
      There are several other uses you can put this box to...all depends on how creative you can get

      meanwhile, here is a picture of my poor box as - is (beautification plans in the works)
 
An excellent excellent guide... I am sure you would follow it up with few more tips and tricks :)

Awesome effort mate as always... I for one was planning to do this @ home but did not do it for n reasons foremost being where to start... Talking a printout of the guide right away :)

P.S. You must spread some Reputation around before giving it to superczar again.
 
czar....awesome ...awesome....
Not tried it...but still awesome....
Il bookmark/print this and try this one day :)
 
Excellent guide czar, Thanks

Btw, what software you use for the mp4 conversion under linux, and does it support batch conversion?
 
Btw, what software you use for the mp4 conversion under linux, and does it support batch conversion?

Here is how I handle batch conversion

(found this script somewhere on the net ..dont rem' where...so cant credit the original author :( )

- Install mplayer/mencoder
- Copy the script below to a file and save it under /usr/local/bin by the name mpg2avi
- Do a sudo su then chmod +rx mpg2avi (settting permissions)

- Now coming to the scenario ;)
you are stuck in a traffic jam and realize you forgot to start that all important DivX to mp4 conversion for a bunch of videos
- Take out your symbian phone, putty to xyz.bounceme.net

- navigate to the folder where the files (to be converted) are
- do mpg2avi

The conversions will be done by the time you reach back home (assuming the traffic jam is real bad, and the server config isnt a celeron 500mhz :p )

Code:
#!/bin/bash

#mpg2avi (Convert mpeg streams into high quality mpeg4 avi with mp3 audio)

#requirements: mplayer

#Begin
clear

# variables
version=0.2b

current_directory=$( pwd )
# video bitrate (1100 = around 500 MB movie size)
vbitrate=1100

echo -e "* mpg2avi v${version}"

# remove spaces
for i in *.[Mm][Pp][Gg]; do mv "$i" `echo $i | tr ' ' '_'`; done > /dev/null 2>&1 &

# remove uppercase
for i in *.[Mm][Pp][Gg]; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done > /dev/null 2>&1 &

# convert mpg movies into avi's with mencoder
for i in *.[Mm][Pp][Gg]; do nice -n 10 mencoder $i -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$vbitrate:vhq:vqmin=2:vlelim=-4:vcelim=9:lumi_mask=0.05:dark_mask=0.01 -vf pp=md  -vop scale=640:480, -oac lavc -lavcopts acodec=mp3:abitrate=128 -o "`basename "$i"`.avi";echo "Conversion done";done

exit;

if you need multiple profiles, you can always edit the params in the last line of the script to your liking ...create multiple versions of this script and save them as e.g. mpg2avi-hi, mpg2avi-mid mpg2avi-low etc.
 
awesome, excellent and to-the-point guide dude! The images aren't visible though.

One suggestion: you haven't mentioned the usage of torrentflux to download torrent files. You can add a small example usage of the actual downloading process. For e.g. suppose i am sitting away from my home and i want to initiate a download, how will i do it? and can i use this to download normal files in addition to torrents.
 
thanks again for the steps for mp4 conversion. Is that the setting you use for converting videos for iphone use (640:480)? would it preserve the orginal aspect ratio ?

Also, how much time it takes to covert a 1GB file on your setup?
 
One suggestion: you haven't mentioned the usage of torrentflux to download torrent files. You can add a small example usage of the actual downloading process. For e.g. suppose i am sitting away from my home and i want to initiate a download, how will i do it? and can i use this to download normal files in addition to torrents.
here you go :p

Now there is no point me trying to explain how to configure and use Torrentflux-b4rt. The site forums have a fairly detailed faq.
  • anyway, here is a basic guide:
  • open xyz.bounceme.net in a browser
  • navigate to the torrentflux link
  • Login
  • Now using the webpage (see screenshot above), either upload a torrentfile from the machine you are sitting on or use the search box to look for torrents via the selected tracker
  • Click start , and you are all set
One basic thing I missed in the guide is to add a port like 10010 to the forwarded ports list and configure torrentflux to use that port for downloading...without that, even though torrents would work but not optimally
 
Back
Top