Sunday, January 5, 2014

Learning Linux: How I Turned My Old PC Into a Linux Server

INTRODUCTION

I do a lot of computational microbiological research, so having a basic understanding of how computers work is essential.  Because computers play such an important role in my research, and because I am just genuinely interested in them, I decided to dive further into the linux world by setting up and maintaining my own personal linux "server".  I always find this kind of thing is a great way for me to learn because it gives me the chance to immerse myself in the environment and forces me to keep learning about how the systems work.  So far this has been a pretty cool experience.  In this post I am going to outline my process of setting up my own linux "server" using an old PC, and go over the pitfalls & decisions I encountered through the process.  I hope this will be an enjoyable little story of my short linux adventure so far, and also hope it will provide you with helpful resources in case you want to try the same thing (and if you do try this on your own, ALWAYS backup your hard drive before you start).  And let's be honest, I will forget how I did it if I don't record it somewhere, and blogs are great places for recording these kinds of outlines.


INSTALLING LINUX

This whole thing started when I saw some friends were going to get rid of an old PC (WindowsXP; 2005) which, while it was on the slow side, was still very usable, especially as a learning tool (I figured it will be like having a Raspberry Pi).  I asked them if I could take it, they said sure, and before I knew it I had my own old computer.  After getting the computer itself, the next step, and honestly the one that took the most thought and time, was getting linux on the thing.  I had to figure out which kind of linux I wanted to use.

Our lab uses a remote Red Hat Enterprise Linux (RHEL) server to perform its analyses, so I already have some experience using this.  Because I wanted to use a different linux system (because why use the same thing?) I decided to go with Ubuntu.  Ubuntu is a very popular, relatively easy-to-use, and open source (legally free) linux operating system, making it a great choice for my purposes. Now that I knew what linux operating system I wanted to use (Ubuntu), I had to figure out how to get it on my new old computer.

Although Ubuntu is one operating system, there are a lot of different desktop environments which all come with different accompanying programs (like different text editors and word processors) and provide different graphic user interfaces (GUIs), or even a command line interface (CLI) if you would prefer to not use a mouse.  The first one I went with was Ubuntu Desktop, which is straight from the Ubuntu website and is widely used.  Because I was not sure how it was going to work, I setup a USB flash drive which could boot Ubuntu, which allowed me to try out Ubuntu Desktop without committing to a full install, which is extremely helpful because installing-then-uninstalling an operating system can get complicated and screw things up easier.

To set up a USB flash drive to run Ubuntu Desktop, I just used the software instructions provided on the Ubuntu desktop website.  All I had to do was download the Ubuntu Desktop 12.04 iso file (basically the file that contains the operating system installation files) and use this with the Ubuntu recommended USB formatting software.  I then plugged the USB drive into the computer (which was turned off), started up the computer, chose to boot from my USB drive (to bring up the boot device selection menu on this old PC, I had to press F12 after I pressed the 'on' button, but the exact button can differ between manufacturers), and waited for Ubuntu Desktop to run.  Unfortunately I got the following error instead:

This kernel requires an x86-64 CPU, but only detected an i686 CPU. Unable to boot - please use a kernel appropriate for your CPU.

Shoot!  This meant that I had used the 64-bit Ubuntu desktop instead of the 32-bit version.  A silly mistake that was easily remedied by reformatting my USB booting drive using the 32-bit iso file instead of the 64-bit version.  I rebooted using this system and it worked!  Or at least it worked for a little while, until it froze up.  I restarted the computer using the REISUB (see tip 1) and tried it again... and again.  It froze everytime, for what I think was just the lack of resources my old computer could offer (in retrospect, Ubuntu desktop was worth a try but a long shot for an old computer).  This meant I needed to find a different desktop environment to use.  I next tried Ubuntu Server since it is only has a command line interface, and is more resource friendly than Ubuntu desktop.  Unfortunately I got hung up on trying to install the system.  As a complete novice in setting up a server, I found this option difficult and confusing when I got into some of the technical parts, so I decided to try something I would be able to hadle better.

Tip 1: Use REISUB for "Reboot Even If System Utterly Broken".  Hold down alt and print-screen, and while holding these type the letters R-E-I-S-U-B.  This is a gentle reboot if the system freezes.

When trying to find a low resource and tractable Ubuntu desktop environment, I came across multiple helpful websites, with the most helpful being the "Linuxed" blog post comparing the different programs.  After some more research, I decided my two best options were either Lubuntu (a VERY low resource, bare bones system) or Xubuntu (still low resource, but has a bit more to offer compared to Lubuntu).  Because it offered the most of the two low-resource options, I tried out Xubuntu through my formatted bootable USB flash drive.  It worked great, stayed stable, and provided a great environment so I went ahead and installed it.  If you are doing this with an old PC and want to keep the windows operating system (your other option is removing windows completely), you will have to partition your hard drive, which means you are going to dedicate part of the hard drive specifically to Xubuntu, and the other part to Windows.  I split the hard drive in half, giving each operating system access to half of the hard drive, but you can choose exactly how much space you want to give to each partition.

Tip 2: Use SD reformatter to get your USB device working like its old self again.

SETTING UP REMOTE ACCESS

Now I have Xubuntu running on this old computer, and it's actually running pretty well.  The only issue is that I want to use this more as a "server" than a desktop computer, and want to be able to access it remotely using a command line interface (CLI).  Compared to the informed decision to use Xubuntu, and getting it installed, the remote access part was actually pretty easy.  I did this using "OpenSSH", which is a program that lets you access other computers remotely, as well as lets you access this computer remotely, using a secure shell (SSH).

Click on this link for instructions to install the program "OpenSSH", which is the set of instructions I found to be the most useful (it is easy to follow and hits the main points).  All I had to do is use the command sudo (to allow me to do things as a super user or root users) to install the program, copy a backup of the ssh configuration file, and modify the configuration file for better security.  For security, I made modifications (which I suggest for you too if you try it out) including the prevention of remote root access (because if the root user is hacked, we would be in trouble), and a different ssh port number (because 22 is the default and used by hackers).  If you want to use the "vi" text editor but need some help, check out this link for vi text editor instructions.

To access the computer remotely using SSH, I was able to get the host name which is linked to the IP address.  I did this by typing 'host <ip address>' to get the host name, and more info can be found here.  Now I am able to access my Ubuntu computer remotely by typing the following into the terminal of a different computer (on PC you can use Putty):

ssh -p <your_port_number> user_name@remote_hostname

And that is it.  Now I have this computer up and running, and am working on a few things with it so stay tuned.  Additionally, let me know what you think in the comments below.  Did you give this a try and want to share some more tips?  Are you running into your own issues when getting your own system setup?  Did I get something wrong in my post above?  Let me know, I would love to hear from you.


Works Cited

Code formatting by: http://formatmysourcecode.blogspot.com/
Ubuntu Logo
Keyboard Logo
SSH Logo

No comments:

Post a Comment