Checking disks for errors using the badblocks command

April 11, 2008 by devenix

For better or worse I’ve been needing to check drives for errors quite a bit recently and have been using the badblocks command to do it. It’s definitely a command that people should become familiar with. Where fsck checks the file system for problems, badblocks attempts to ascertain the status of physical media which can include hard disks, usb drives, and other usb devices such as media players. I’ve compiled a detailed list of commands I’ve been using.

Read-only Test

This is a non-destructive read-only test which can be run on disk even if it contains a mounted filesystem. It simply verifies that each block can be read; it does not test for write errors.

  • sudo badblocks -s -v -c 10240 /dev/sdx
    • -s = show progress
    • -v = verbose mode
    • -c 10240 - check 10K blocks at a time

Read-write Test

This test is non-destructive read-write test which reads each block, writes it, then verifies it. It should not be used on block devices with mounted filesystems as it can lead to filesystem corruption.

  • sudo badblocks -n -s -v -c 10240 /dev/sdx
    • -n = non-destructive read-write mode
    • -s = show progress
    • -v = verbose mode
    • -c 10240 - check 10K blocks at a time

Write-mode Test

Using this command will erase all data on the device so only use it if that is what you want. This will write a few patterns to each block, verifying that each one is written and read correctly.

  • sudo badblocks -w -s -v -c 10240 /dev/sdx
    • -w = destructive write-mode test
    • -s = show progress
    • -v = verbose mode
    • -c 10240 - check 10K blocks at a time

Prepare a disk for encryption

The command will completely erase the data on a disk and replace it with random data. This is often a preferred way to prepare a disk for encryption as it is faster than other methods of filling a disk with random data and serves the purpose of checking the disk for errors before the encryption process.

  • sudo badblocks -w -t random -s -v -c 10240 /dev/sdx
    • -w = destructive write-mode test
    • -t random = write random data onto the disk
    • -s = show progress
    • -v = verbose mode
    • -c 10240 - check 10K blocks at a time

Convert -File System- ext2 to ext3

March 26, 2008 by devenix

Hi all,

The tune2fs program can add a journal to an existing ext2 file system without altering the data already on the partition. If the file system is already mounted while it is being transitioned, the journal will be visible as the file .journal in the root directory of the file system. If the file system is not mounted, the journal will be hidden and will not appear in the file system at all.

To convert an ext2 file system to ext3, log in as root and type:

tune2fs -j /dev/xxx

This will create ext3 file system in the partition specified. Once this is over “without any errors” you should change the “file system type” in /etc/fstab and make it ext3. Then do a

mount -a

To check whether its mounted properly and the file system type, do

mount

A nice article by Swami Vivekananda….

March 17, 2008 by devenix

I once had a friend who grew to be very close to me. Once when we were sitting at the edge of a swimming pool, she filled the palm of her hand with some water and held it before me, and said this:

“You see this water carefully contained on my hand? It symbolizes Love.”

This was how I saw it:

As long as you keep your hand caringly open and allow it to remain there, it will always be there. However, if you attempt to close your fingers round it and try to posses it, it will spill through the first cracks it find. This is the greatest mistake that people do when they meet love…they try to posses it, they demand, they expect… and just like the water spilling out of your hand, love will retrieve from you. For love is meant to be free, you cannot change its nature. If there are people you love, allow them to be free beings.

Give and don’t expect.
Advise, but don’t order.
Ask, but never demand.

It might sound simple, but it is a lesson that may take a lifetime to truly practice. It is the secret to true love. To truly practice it, you must sincerely feel no expectations from those who you love, and yet an unconditional caring.” Passing thought… Life is not measured by the number of breaths we take; but by the moments that take our breath away…..

Installing and setting TFTPD in Ubuntu

March 11, 2008 by devenix
1. Install tftpd and related packages.
$ sudo apt-get install xinetd tftpd tftp

2. Create /etc/xinetd.d/tftp and put this entry:

service tftp
{
protocol        = udp
port            = 69
socket_type     = dgram
wait            = yes
user            = nobody
server          = /usr/sbin/in.tftpd
server_args     = /tftpboot
disable         = no
}

3. Make /tftpboot directory

$ sudo mkdir /tftpboot
$ sudo chmod -R 777 /tftpboot
$ sudo chown -R nobody /tftpboot

4. Start tftpd through xinetd

$ sudo /etc/init.d/xinetd start

5. Testing. Tranfering file hda.txt from 192.168.1.100 (Client using tftp) to 192.168.1.100 (Server 192.168.1.100). Get an example file to transfer (eg. hda.txt)

$ touch /tftpboot/hda.txt
$ chmod 777 /tftpboot/hda.txt
$ ls -l /tftpboot/
total 0
-rwxrwxrwx  1 deven deven 0 2006-03-27 23:04 hda.txt
$ tftp 192.168.1.100
tftp> put hda.txt
Sent 722 bytes in 0.0 seconds
tftp> quit
$ ls -l /tftpboot/
total 4
-rwxrwxrwx  1 deven deven 707 2006-03-27 23:07 hda.txt

PostgreSQL error (FATAL: invalid value for parameter “lc_monetary”: “en_US”)

February 14, 2008 by devenix

Hi ,

m back after a long vacation.

If u get some error like this after installing postgresql

(Note m using a ubuntu Linux )

* Restarting PostgreSQL 8.1 database server  * The PostgreSQL server failed to start. Please check the log output:
FATAL:  invalid value for parameter “lc_monetary”: “en_US”  [fail]
Check which locales u are using.

for a unix system u can check it with this command

root@mail:/home/devenix# locale

Output wat i got is

LANG=en_US.UTF-8
LC_CTYPE=”en_US.UTF-8″
LC_NUMERIC=”en_US.UTF-8″
LC_TIME=”en_US.UTF-8″
LC_COLLATE=”en_US.UTF-8″
LC_MONETARY=”en_US.UTF-8″
LC_MESSAGES=”en_US.UTF-8″
LC_PAPER=”en_US.UTF-8″
LC_NAME=”en_US.UTF-8″
LC_ADDRESS=”en_US.UTF-8″
LC_TELEPHONE=”en_US.UTF-8″
LC_MEASUREMENT=”en_US.UTF-8″
LC_IDENTIFICATION=”en_US.UTF-8″
LC_ALL=

so with this u got wat locale u are using

after that copy the locale and paste in ur postgresql  config file at defined locations

File Path: /etc/postgresql/8.1/main/postgresql.conf

change following entries with the locale wat u got

lc_messages = ‘en_US.UTF-8′                     # locale for system error message
# strings
lc_monetary = ‘en_US.UTF-8′                     # locale for monetary formatting
lc_numeric = ‘en_US.UTF-8′                      # locale for number formatting
lc_time = ‘en_US.UTF-8′

and restart postgresql and check .

Howto base64 encode and decode with C and OpenSSL

January 18, 2008 by devenix

The first here is how to base64 encode a chunk of memory using OpenSSL.

#include <string.h>#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>char *base64(const unsigned char *input, int length);

int main(int argc, char **argv)
{
char *output = base64(“YOYO!”, sizeof(“YOYO!”));
printf(“Base64: *%s*\n, output);
free(output);
}

char *base64(const unsigned char *input, int length)
{
BIO *bmem, *b64;
BUF_MEM *bptr;

b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_write(b64, input, length);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);

char *buff = (char *)malloc(bptr->length);
memcpy(buff, bptr->data, bptr->length-1);
buff[bptr->length-1] = 0;

BIO_free_all(b64);

return buff;
}


base64 decode goes here:

#include <string.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
char *unbase64(unsigned char *input, int length);int main(int argc, char **argv)
{
char *output = unbase64(“WU9ZTyEA\n, strlen(“WU9ZTyEA\n));
printf(“Unbase64: *%s*\n, output);
free(output);
}

char *unbase64(unsigned char *input, int length)
{
BIO *b64, *bmem;

char *buffer = (char *)malloc(length);
memset(buffer, 0, length);

b64 = BIO_new(BIO_f_base64());
bmem = BIO_new_mem_buf(input, length);
bmem = BIO_push(b64, bmem);

BIO_read(bmem, buffer, length);

BIO_free_all(bmem);

return buffer;
}

words of Swami Vivekananda

January 4, 2008 by devenix

Be a hero. Always say, “I have no fear.” Tell this to everyone — “Have no fear.”. Fear is death, fear is sin, fear is hell, fear is unrighteousness, fear is wrong life. All the negative thoughts and ideas that are in the world have proceeded from this evil spirit of fear.

These words can help you in realizing your potential.

Bye

windows vista backuppc and samba problem

December 27, 2007 by devenix

Hi,

m back with one more issue.

if u have windows vista as one of your client machines and you want to back up it using Backuppc software.  U may get some problems. As  Windows Vista does not work with all versions of smbclient.

So if check ur smbclient and samba-common version installed in ur computer. if they are less that 3.0.25 , then u can get problems with acessing ur vista shared drive.

Some errors like  session setup failed: NT_STATUS_LOGON_FAILURE can be encountered.

Fiirst check if u can  access the vista share using following command.

smbclient  //ip-of-the-machine/shared-partition -U vista-user-name

if u can access the vista share , u are very lucky. if not upgrade to newer samba-common and smbclient packages as i mentioned earlier.

Second imp thing to do is:

from http://forums.windowsvistamagazine.com/forums/2111/ShowThread.aspx

To get Vista to work with Samba follow the simple instructions below:

Run secpol.msc

Go to: Local Policies > Security Options

Find “Network Security: LAN Manager authentication level”

Change Setting from “Send NTLMv2 response only”
to
“Send LM & NTLM - use NTLMv2 session security if negotiated”

Not a lot of use in my case as I have Vista Home Premium that does not have secpol.msc which is only found in Business an Ultimate. A little more looking revealed:

If you’re running a version of Vista that cannot use secpol.msc, you can edit the registry instead. Just change the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\LMCompatibilityLevel from a 3 to a 1.

Then I started thinking (dangerous thing probably triggered by an aversion to registry edits) if Vista wants you to use NTLMv2, it is probably because LAN manager is inherently less secure than NTLMv2. Therefore would it not be better to enable this in Samba that is supposed to support it in version 3?

 now if u can smbclient to that vista machine without any problems then u can easily use backuppc with any vista share.

moving your filesystem to a new hard drive

December 11, 2007 by devenix

Hi,

M back again after many days , i was facing a problem of moving my working partition to other HDD. Searched a lot (of course on Google) and found a very nice solution.

U just require two commands under your belt to make it possible.

Copying the / filesystem is as follows (assuming for the example the new drive is mounted at /media/temp):

find / -xdev -print0 | cpio -pa0V /media/temp

When you run this command, it will recursively copy everything on the / filesystem, without crossing over into other mounted partitions. It will properly handle any special files, and it will completely preserve permissions.

You simply would mount each of the new partition you want to copy onto and repeat this above operation for each of those. Upon execution, you will see a series of dots fly across the screen. Each dot represents a file that is being copied.

Bye For Now.

Enable GTALK from Gaim in Linux

December 2, 2007 by devenix

Gaim is what you probably use if you use Linux and want to connect to Yahoo or MSN. Lately google talk has been steadily becoming popular among people. Not many know that you can use Gaim to connect to the google talk servers and chat with your gtalk friends! Here’s how you go about it -

1.Click Accounts > Add (At the main login screen)
2.From the protocol dropdown select Jabber
3.Your screen name will be your gmail address except @gmail.com Example: If your address is abc@gmail.com then your screen name will be abc
4.Change the server from jabber.org to gmail.com
5.Password will be the same password that you use for Gmail
6.Click show more options
7.“Use TLS is available” should be checked
8.The connect server should be “talk.gmail.com”