19 October, 2013

Installing Ubuntu server 12.04 LTS from pendrive on an old PC to create a NAS

I have a pretty old PC from 2003 which I have been using for some time as a NAS. It is a standard desktop PC (self built), but it has 8 IDE hard drives ranging from 200 Gbyte up to 500 Gbyte. The total capacity of the drives is around 2 T and I just decided to give a refresh to the system to back up my digital videos to it.

I have been using FreeNAS 7.2, which is pretty nice, but it is BSD based and as I have more experience with linux and especially with Ubuntu Server so I decided to upgrade to that one.

Here comes a short guide on how to setup Ubuntu Server on a machine to work as a simple NAS.

Installing Ubuntu Server from pendrive (Flash memory)


Today this should be a strait forward thing, you take the installation ISO image, with some tool you copy it to a pendrive you plug it into the machine and install it, but in my case I run into plenty of problems. By the end I have solved all of them, but here is a list of how to solve them one by one.

1) Copy the ISO to a pendrive: I have used Linux Live USB Creator it worked fine without any problem.

2) It boots perfectly, starts the installation, but hangs after some time as it  doesn't recognizes the USB drive as source for packages:

After some goggling I have found the solution. You have to add the following directive when starting up the install system:

cdrom-detect/try-usb=true

You can do this when the system is starting, by manually edit the startup string  or you can add that to the default boot menu in the syslinux directory to the txt.cgf file, then on each start it will work automatically.

3) Now it recognizes the USB as source but after some progress it is complaining about missing packages:

The reason here was a bit less obvious, but it turned out, that somehow when extracting the ISO image to the USB drive - probably because the file length was to long, the extension and the file names were incorrect. In my case all the problems were in the:

/pool/main/l/linux-lts-rating

folder. You can identify them, where the extension is not .deb or .udeb, but you should check also the last part of the file name before the extension, it should be _i386 or _all. I have manually corrected these problems and thus finally managed to install the system.

The installation is strait forward, you should just follow the questions asked by the installer.

When you get to the software selection, choose the following components:

OpenSSH server
LAMP server
Samba file server

LAMP is not needed for the backup purpose, but I thought, that it is always good to have a working web server on the machine just in case it will be needed.

Out of Range on the monitor after booting

After restarting the successfully installed server, I got only an "Out of Range" message on the monitor. Obviously GRUG tried to put the monitor to some nice graphic mode and it failed.
After some research found this article: http://askubuntu.com/questions/54067/how-do-i-safely-change-grub2-screen-resolution and based on it, I opened the /etc/default/grub/ and switched back to text mode by uncommenting GRUB_TERMINAL=console.

Initial setup


Before doing anything run:

sudo apt-get update
sudo apt-get upgrade 

To upgrade the computer to the latest software.

Webmin

The first program I install is always Webmin as it gives me an easy way to set up the rest of the system.

Here is the description on how to install it: http://www.ubuntugeek.com/how-to-install-webmin-on-ubuntu-12-04-precise-server.html, but may be it is better to follow the installation guide on the Webmin web page.

For me this was the following:

wget http://prdownloads.sourceforge.net/webadmin/webmin_1.660_all.deb

sudo dpkg --install webmin_1.660_all.deb

This returned error that 4 packages are missing. Instead of installing the missing packages it is enough to order apt-get to fix the dependencies:

sudo apt-get -f install

This now run successfully and at the end it said, that Webmin is installed. And indeed after this I could log in to webmin. (https://yourserverip:10000)

Network setup

I prefer to use static address for the server like devices, to set it up, in Webmin go to Networking/Network Configuration/Network Interfaces, and set up a static address for the interface in use, then in Routing and Gateways set up the default GW. In the Hostname and DNS client set up the needed settings.
When ready with all the changes then you can apply them all at once by the Apply configuration button.

After this step you have to redirect your browser to the new Webmin address and if you have a terminal session change that as well.

LVM setup

In my practice I use LVM (Logical Volume Manager) to merge the individual disks into a big "virtual" disk, so when I am using it I do not need to care if I have enough space on the individual drives as the data is spanning across them automatically. It would be possible to introduce some kind of RAID here, but as this will be a backup device I do not feel that it is necessary. This approach has the drawback that if one of the disks fails I may loose all the data in all disks, but as I told, this is a backup, a low priority backup, and I hope that with some advanced "bithunting" technology it would be possible to recover the data at least from the remaining disks.

First we need to install LVM from the command line:

sudo apt-get install lvm2

After this press Refresh Modules in Webmin, log out and back in, and the Logical Volume Management will appear under Hardware.

Before creating the volumes, first partitions should be created to be added to the LVM volumes. This can be done from the Partitions on Local Disks Webmin module. Here we need to add one partition to each disk to cover the full disk space. For the full disks, I first Wiped and recreated the partition table, then added a partition of type "none" for the entire disk.

Now go to the LVM manager, first create a Volume Group, add the partition on first disk and name it something meaningful. Next go the the Physical Volumes and add all the remaining disk partitions to the Volume Group. Finally go to the Logical Volumes and allocate all the space in the recently created Volume Group to one logical volume. This logical volume will be accessible in the operating system as a big drive.

Checking drive for errors

The next step is to check for errors in the complete new logical volume. Normally this is not necessary but as I have a very old hardware, with very old HDDs I prefer to run a test, before starting to use it.

As this will run on my computer probably longer than a day, I use the "screen" utility which allows me to disconnect from the command line and reconnect again later.

The command for checking the disk is:

sudo badblocks -vws /dev/mapper/LogicalVolumeName

I was right with the precaution, as during the tests I got some errors, but after rearranging the data cables for the HDDs I managed to fix that. Badblocks isn't fast at all, for my 1,7 T logical volume it too more than 3 days to complete, but finally I got the test passed with 0 errors.

Formatting and mounting the new volume

Next step is to format the volume, it can be done in Webmin, Logical Volume manager. You should select the newly created LV and select create filesystem on the detail view page of the volume. I have selected Ext4 filesystem with default parameters except for the reserved blocks where I specified 2%, to reduce the overhead on this big volume.

Although you can do the mounting also here in Logical Volume Management, the Disks and Network File Systems in the System menu of Webmin provides much more options to do it. So we go there, select to add a new ext4 mount and mount the filesystem to /media/datalv.

Samba Configuration

The last step is to configure this volume for network access from Windows with Samba.

In Webmin we go to Servers/Samba and in the top list we select "Create a new file share". For the backup server I do not need access control and user level permissions so I will setup the share to "guest only" access. When creating the share we give the name of our choice, then we select media/datalv as the Directory to share. If we would not like to see the lost+found directory within the share then we can add a sub directory to it, Webmin will automatically create that directory.  To facilitate the guest access we should change the owner to nobody and the group to nogroup. We can leave the rest on default.
After creating the share we should click on it to get to its settings and select "Security and Access Control". Here we change it to writable and to Guest only access and we are ready.

From here on, the system is ready and you can use it for file storage.

No comments: