Monthly Archives: August 2010

Hard Drive Diagnostics in Linux

So this morning I had to deal with a server which has been consistently crashing once every week. Each crash indicated that there is something wrong with the file system – no I am not a programmer and nor am I about to spend a ton of time looking into the crash, for reasons I don’t want to get into here.

Anyway the OS that is being used is Fedora Core 2, which is no longer supported.  Now even though I think the OS is the problem I am going to scan the hard drive to make sure its working properly, if the drive isn’t function properly then this could be the root cause of the problem. So there are two great options for testing the hard drive. The first is SMART, luckily the hard drive is SMART capable. The second is badblocks, a program that is called E/2/3/4/fsprogs (you can download the program from sourceforge if it is not installed).

If you do not know what type of hard drive you have in your system you can run the following command:

fdisk -l

Because the hard drive in this server is SMART compatible I can run the following command which will output drive information for a particular drive: (PLEASE NOTE THAT THIS EXAMPLE WAS PERFORMED ON A RED HAT BASED SYSTEM)

smartctl -a /dev/HDD_DEVICE

This command will run a LONG test of your hard drive:

smartctl -t long /dev/HDD_DEVICE

Now to view the status of your test run this command(please note that the time it takes to test your hard drive will very depending on the capacity):

smartctl -l selftest /dev/HDD_DEVICE

If you don’t have a SMART capable hard drive you can use the E/2/3/4/fsprogs to check your hard drive. By running the following command you will initiate a scan of the hard drive:

badblocks -n -v /dev/HDD_DEVICE

Here is what I would run if I were you:

badblocks -n /dev/HDD_DEVICE -o outputfile &

This will output any bad blocks to the outputfile (you name it whatever you want) and the “&” runs the program in the background. For more information on E/2/3/4/fsprogs click the link!

Alternatively you can also use GOOGLE to help solve your problems! I also used this wonderful site to help me with hardware diagnostics.

How To: Bash Backup Script

Alright so here is my simple version of a bash backup script… Feel free to comment, if I miss something or you think something should be added please let me know. For this example I assume that you have the proper user access and have some minimal command line experience!

First you should know that I am using several basic commands like “cp” to copy files and “tar” to compress files. You will also need to know how to use command line text editors, I am using “emacs” but “vi,”  “view” or whatever text editor you use will work.

Any line beginning with the number sign # and has text colored in green indicates a comment. Please note that I do not take responsibility for any issues you may cause when using my backup method, I do recommend testing the backup method on a directory that does not have important contents (so create a test directory with test files and try backing it up first). However I highly doubt the method will cause problems unless you severely screw up on my instructions…


1) The first thing we need to do is make a backup directory on the Linux box:

## Change to the / (root) directory (again I am assuming you have proper access to your system - as root)
cd /

## make your backup directory and create a folder for your backups
mkdir -p /backup/my-backup

2) Now we need to create the script:

# Change to the home directory (remember you are root so you may have to change permissions later)
cd ~

## now lets create the bash file for our backup script using emacs
emacs my-backup.bsh

## at the start/top of the file please add the following, note the number sign which looks like a comment, this allows your system check the file and run it as bash script

## save the bash file and change its permissions so that the script can be executed
chmod +x my-backup.bsh

## now go back into the backup bash file and start the code
emacs my-backup.bsh

3) Now we write the script:

# This is my backup file - created by <your-name-here>

# here I am setting a time stamp variable which I like to use for logging
TIMESTAMP=`date +%Y%m%d.%H%M`

# here I am setting up the backup directory as a variable

# here I am setting up the directory in which I want to backup, again another variable

# let's create a variable for the backup file name file

# let's create a variable for the log file, let's also name the log file with the filename and timestamp it

# start the backup, create a log file which will record any messages run by this script
echo -e "Starting backup of <user-name-here> $SRC_DIR directory" >> ${LOG}

# compress the directory and files, direct the tar.gz file to your destination directory
tar -vczf ${DEST_DIR}/${FNAME}-${TIMESTAMP}.tar.gz ${SRC_DIR} >> ${LOG}

# end the backup, append to log file created by this script
echo -e "Ending backup of <user-name-here> $SRC_DIR" >> ${LOG}

The backup is now complete, we have created a compressed copy of the /home/<user-name>/Documents directory in the /backup/my-backup directory. If there were any errors with backup process the log file we created in /home/<user-name>/log will tell us what the error may be. Normally you don’t have to create variables to do a backup but if you wanted to backup another directory all you need to do is duplicate this script and change the SOURCE DIRECTORY, DESTINATION DIRECTORY, LOG-FILE (location) and FILE-NAME to the additional backup directory.

Advanced Settings: This backup script is a great way to backup your files but you should really consider moving your files off the same drive (computer) to an alternate location. If you do not have an off-site location perhaps you have another local Linux box or NAS device which will allow you to preform backups via scp (secure copy) or rsync. Finally the last thing you should do is set this script to run on a regular basis. To do this you need to create a cronjob using your systems crontab.

See my other How To’s:


The perfect Window XP Setup, Part 4: backup your windows xp installation

Once you have completed your installation, customization, system tweaks, etc of Windows XP you should create an image. This image can be used in the event of a hardware failure or if you just want to start from a clean plate (as mentioned earlier on in this document). In order to create a backup image you will need a program like Norton Ghost or Acronis True Image (there are several programs out there to do this).

Windows XP does have a built in recovery method but in order to do this you must have a floppy drive and disk. The built in ASR (Automate System Recovery) is not installed by default so you will require the Windows XP installation media.

  1. Load the Windows XP installation media into your CD/DVD drive
  2. Open the Start Menu and select RUN
  3. In the RUN box type the following: “d:\i386\winnt32.exe /cmdcons”
    ( be sure to remove the quotes, your CD/DVD drive letter may be different )
  4. Once the installation is complete you can now access the ASR from the built NTBACKUP.

There are several ways to access NTBACKUP but I use the following: Open the Start Menu and select RUN, type in “NTBACKUP” (again without the quotes). The NTBACKUP Wizard will start, select the Automated System Recovery Wizard option and follow the instructions (this is where you will need a floppy disk).

Good luck and if you have any questions or comments please post them. Feel free to contact me using the contact form on my contact page.

The perfect Window XP Setup, Part 3: optimizing your windows xp installation

– Depending on your computer’s hardware configuration you may want to disable the graphic effects of Windows XP. By disabling these graphics affect you reserve the system resources for other tasks.

  • To modify your Windows XP graphics settings “Right Click My Computer >> Select the Advanced Tab >>in the Performance section select the Settings button” no adjust your settings (I recommend Adjust for best performance if you have limited hardware)

– Decrease the storage size of your recycling bin

  • Right click the Recycling Bin Icon and select properties, now decrease the size to 1% and click ok

– Internet Explorer

  • Disable third part cookies, always accept trusted
  • Empty temporary internet files upon exit (close) of IE
  • Reduce cache size
  • Set your home page to about:blank or Google (by selecting no page or a website with minimal content your web browser will load faster… I personally load Google)

– Change the amount of virtual memory your computer can use, the general rule is 1.5 – 2.5 more than the physical RAM you have in your machine

– Disable non system critical start-up programs (as mentioned before in Customize you Windows XP installation steps…)

The perfect Window XP Setup, Part 2: customize your windows xp installation

– Before doing anything install an Anti-Virus program, if you are on a budget you can install the free version of Microsoft Security Essentials (this is a really great program, at the time of writing this document it is actually one of the top 3 reviews by I personally use and recommend Norton Anti-Virus, Norton Internet Security 2009 or newer. The older versions of Norton are not very good as they leave a heavy footprint on the operating system (meaning the older versions used to make your computer run slower).

– Confirm if you have the latest Service Pack for Windows XP, depending on the installation media you may have an older Service Pack. At the time of writing this document the following service packs were available: SP1, SP2 and SP3

– I use the following programs: (there are many more programs out there but these are the ones I prefer)

  • CCleaner (system clean-up tool, temp files, registry, etc)
  • 7 Zip (compression/decompression tool, 32 and 64 bit versions)
  • Firefox (I use the following add-ons:  fireftp, xmarks)
  • Winamp (multimedia tool, music, video, etc)
  • CPU-Z, GPU-Z and Speecy (system information tools: CPU, RAM, HDD, GRAPHICS)
  • OpenOffice (free Office tools, if a person can’t afford Microsoft Office this is a great alternative)
  • Thunderbird (great email client and its free! Alternative to Outlook Express)

– After installing all of the above programs and system updates you should run CCleaner to remove and registry issues and temporary files. CCleaner also allows you to control which start-up programs you want enabled or disabled on boot. Alternatively you can use the “msconfig” command but I do not recommend this unless you know what you are doing (you can really mess up a system by turning off the wrong service). Things you should turn off:

  • Any third party program, HP imaging device, Apple’s iPhone helper, QuickTime, Adobe Speed Launcher, etc. The reason you want to turn these programs off is because you aren’t accessing/using them all at once. For example, if you want to Skype open it from the All Programs list. By removing these from the start-up you will save much needed system resources which allows your computer to run much faster. A user should only use what they need, eliminate what they don’t.