Monday 31 March 2008

How to recover damaged Superblock in Linux

If a filesystem check fails and returns the error message “Damaged Superblock”
Solution:

There are backups of the superblock located on several positions and we can restore them with a simple command. 

Backup locations are: 8193, 32768, 98304, 163840, 229376 and 294912. 
( 8193 in many cases only on older systems, 32768 is the most current position for the first backup )

Now, suppose you get a ¨Damaged Superblock¨ error message at filesystem check ( after a power failure ) and you get a root-prompt in a recovery console,
then you give the command:
# e2fsck -b 32768 /dev/hda5

System will then check the filesystem with the information stored in that backup superblock and if the check was successful it will restore the backup to position 0.

If this is not working try using the other copy of Superblock located at the above mention location in your HD.

Tuesday 18 March 2008

How to crash Linux?

As root, you can do whatever you want.
Try this command, as root (reconsider if you really want to crash):
# cp /dev/zero /dev/men
As root, you can even erase all the files on your system with a similarly innocuously looking one-liner (don’t do it):
# rm -rf /

This is not to say that Linux is easy to crash, but that the system administrator (”root”) has the complete power over the system so think before when working on Linux as “root” user.

Monday 17 March 2008

Create Linux Filesystem From An Ordinary File

Under Linux, you can create a regular file, format it as an ext2, ext3, or reiser filesystem, and then mount it just like a physical drive. It's then possible to read and write files to this newly-mounted device. You can also copy the complete filesystem, since it is just a file, to another computer.

First, you want to create a 20MB file or any size you want by executing the following command:
      $ dd if=/dev/zero of=disk-image count=40960
     40960+0 records in
     40960+0 records out
Next, to format this as an ext3 filesystem, you just execute the following command:
      $ /sbin/mkfs -t ext3 -q disk-image
     mke2fs 1.32 (09-Nov-2002)
     disk-image is not a block special device.
     Proceed anyway? (y,n) y
You are asked whether to proceed because this is a file, and not a block device. That is OK.

Next, you need to create a directory that will serve as a mount point for the loopback device.
      $ mkdir fs
You must do the next command as root, or with an account that has superuser privileges.
      # mount -o loop=/dev/loop0 disk-image fs
You can now create new files, write to them, read them, and do everything you normally would do on a disk drive. To make normal user to use this filesystem you need to give valid permission to the directory holding this filesystem.

Sunday 16 March 2008

Mounting an ISO Image as a Filesystem in Linux

This is great, if you don’t have the DVD hardware, but need to get the data.
The following show an example of mounting the Fedora core 7 DVD as a file.

# mkdir /iso
# mount -o loop -t iso9660 /FC7-i386-DVD.iso /iso

Or to mount automatically at boot, add the following to “/etc/fstab

/FC7-i386-DVD.iso /iso iso9660 ro,loop 0 0

Saturday 15 March 2008

Repair a Corrupt MBR and boot into Linux (fedora)

There are times when you inadvertently overwrite your Master Boot Record. The end result being that you are unable to boot into Linux. This is especially true when you are dual booting between windows and Linux OSes. Once when I was working in Windows XP, I accidentally clicked the hibernate button instead of shutdown. And windows somehow overwrote my MBR which housed the GRUB boot loader. At such times, it pays to have this cool tip at hand.

This is what you do to restore the GRUB boot loader when faced with the above problem. First you need a Linux distribution CD. If you are using Fedora (RedHat) then the first CD is sufficient. But you may also use any of the live CDs like Knoppix, Ubuntu Live CD and so on.
With Fedora CD
Boot your computer with the first CD of Fedora in your CD drive (You have to enable your PC to boot from the cdrom, which you can set in the BIOS settings). At the installation boot prompt that you get, enter the following command:
boot: linux rescue

… and press Enter. The installer will ask you a few questions like the language you would like to use, the type of keyboard etc. Then, if you have linux previously installed on your machine, the Fedora installer will automatically detect it and mount it in the /mnt/sysimage directory. Once the linux partition is mounted, you are dropped into the command shell prompt. The next step is to make your newly mounted directory the root (or parent) directory. This you do by running the chroot command as follows:
# chroot /mnt/sysimage

Now you are in the shell with respect to the parent directory which is the linux partition on your harddisk.
From here, the steps needed depends on which bootloader you are using. You have to have a fair idea what is the device node of your harddisk partition housing your MBR. In most cases, it is /dev/hda if you have an IDE harddisk. But if you have a SCSI harddisk, it will be /dev/sda.

Restoring GRUB
Execute the following command :
# grub-install /dev/hda

… to install GRUB boot loader on to your MBR. And then type exit to reboot the machine. Now your GRUB boot loader is fixed.

Friday 14 March 2008

Repair Corrupt RPM Database in Linux

Strange things sometimes happen, 
one of them is a corrupt rpm database. 
This means that the computer tells you something is installed and it really is not.

Here is how to solve this problem.

First backup and then delete by doing the following command:
$ su
# cp /var/lib/rpm/__db.001 /home/nikesh
# rm /var/lib/rpm/__db.001
# cp /var/lib/rpm/__db.002 /home/nikesh
# rm /var/lib/rpm/ __db.002
# rpm –rebuilddb

Thursday 13 March 2008

Erase the Content of Disk Drive in Linux

After unmounting the disk drive’s partitions, issue the following command (while logged in as root): 

# badblocks -ws
 
This will absolutely erase the drive and no tool can retrieve the data after.

Wednesday 12 March 2008

How to scan a host in Linux

You can use nmap to determine all the TCP/IP ports on which a remote server is listening. It isn’t usually an important tool in the home environment, but it can be used in a corporate environment to detect vulnerabilities in your network, such as servers running unauthorized network applications. It is a favorite tool of malicious surfers and therefore should be used to test external as well as internal servers under your control.

Here is an example of trying to do a scan using valid TCP connections (-sT) in the extremely slow “insane” mode (-T 5) from ports 1 to 5000.

# nmap -sT -T 5 -p 1-5000 192.168.1.153

Tuesday 11 March 2008

Setup Quotas in Linux

1) Enter Single user Mode:
# init 1

2) Edit your /etc/fstab file
The /etc/fstab file lists all the partitions that need to be auto-mounted when the system boots. Edit and add “usrquota” option to the partition that you want to have quota enable
LABEL=/home       /home          ext3    defaults,usrquota  1 2

3) Remount your partition
# mount -o remount /home

4) Come out of single user mode
# Exit

5) Create quota file
The uppermost directory of the filesystem needs to have an aquota.user file (defines quotas by user) and an aquota.group file (defines quotas by group), or both.
# touch /home/aquota.user
# chmod 600 /home/aquota.user

5) Initialize the user quota
# quotacheck -vagum

6) Edit the quota for a user
# edquota -u sohail
The command will invoke the vi editor.
Disk quotas for user sohail (uid 501):
 Filesystem  blocks       soft       hard     inodes     soft     hard
 /dev/hda3       24          0          0          7        0        0

Monday 10 March 2008

Recover lost root password

1) Reboot your system.
2) When GRUB comes up type e .
3) Now select entry that begins with kernel.
4) Add then end of the kernel entry type either s or single, now hit enter.
5) Type b, the box will boot up and now you can type in the cmd prompt passwd root.
This will reset the password to whatever you like.

Sunday 9 March 2008

What to do if Linux refuses to boot after a power failure?

SolutionThere are a few things that you can try to get Linux back on track..
1. While rebooting, Linux may print a message saying that there is a problem with the filesystem and it might force a check. It would do this for all Linux partitions. If the checks (they generally take around 30-60 seconds..also displays a rotating indicator) are successful then you are lucky. Linux should mostly continue booting and you should be back in business soon. If this is what happens then you may be under an impression that a direct switch off of a Linux machine leads to no problems. Please note that you were just lucky that you got away without any major problems.
2. While rebooting, Linux may not be successful in any of the filesystem checks. In this case the booting stops abruptly with a message stating that you should run fsck manually without a few parameters. Once you reach the bash prompt (#) then run the fsck command as mentioned (fsck -a -p /dev/hdaX). The fsck command requires the partition which it has to check. So if you have installed linux on /dev/hda1 then you have to run fsck as follows : fsck -a -p /dev/hda1 When you run fsck it would mostly find some inode problems and ask you whether you want to fix them, Select the default option (yes). It would do so for all the problems found. Once this is over you can restart the machine using either “Ctlr+Alt+Del” or “shutdown -r 0″, whichever works. Now this time your Linux machine should boot properly.
3. It has so happened that once when the power failed, Linux simple failed to boot on my machine. It gave no errors at all, but the init process would just not get initiated. It would find my partitions, mount the ext2 filesystem as read only and then would simply display a prompt. Even with this prompt I wasn’t able to do a lot. Also I noticed that a few of the default directories were missing on the native partition. The only solution that I found to this was to Reinstall Linux.

Note
: While reinstalling, the best and safest way for the above problem would be to insert the installation media (Redhat Linux 6.1 CD). And instead of selecting to install the OS once again, select to upgrade the existing installation. This would effectively replace all the damages areas of the OS and would also retain all your personal data and configurations in Linux (This should work in almost all cases).
Hence I would always advice an upgrade to the same version (If you originally had Redhat Linux 6.1 , insert the CD and once again select to upgrade to Redhat Linux 6.1 itself). If the upgrade option doesn’t fix the problem, then you would have to do a reinstall after a reformat of the Linux partitions.
4.
In one case when Linux refused to boot I noticed that a few of the main files / directories were missing. I found that the /sbin directory (which is a very important directory) wasn’t there in the root directory. I performed a search for this directory and found it to be within another directory. After some discussion I realised that my friend has accidently moved this directory within his GUI when he was working in superuser mode. As long as he was working a few commands didn’t work but he did not bother about finding out why they didn’t work. Once he rebooted his machine the abscence of this directory hung the booting process. So I suggest that you never work in superuser mode unless absolutely necessary. Even within the superuser mode prefer the shell, since you can hardly ever do anything accidently in the shell. In my friend’s case I simply moved that directory back within the root directory and Linux booted without any problems.

Saturday 8 March 2008

Installing Xfce on Ubuntu

Paste this command in terminal
sudo aptitude update && sudo aptitude install xubuntu-desktop

To use Xfce after you’ve installed it:
1) Log out
2) Under “Session”, select “Xfce”
3) Log back in again.

Friday 7 March 2008

Tune your ext3 filesystem

All examples use /dev/sda1, but you can change it to whatever you want
tune2fs command can be run on mounted ext3 volumes.
Journals
Ext3 has 3 journal modes, Journal, Ordered, and Writeback (slowest to fastest)
All it takes is a command by tune2fs.
Example:
Code: tune2fs -o journal_data_writeback /dev/sda1
This added journal_data_writeback to the default ext3 mount options for that partition. So if ext3 is mounted without options saying otherwise, or specifically with the option ‘defaults’ (rebuildfstab adds this), it will use writeback.
To get rid of that option, just add ^ before the option
Code: tune2fs -o ^journal_data_writeback /dev/sda1
Just remember not to have two journal options as default.
Note: the writeback journal is not very reliable and you may lose important data in a power outage. Check the man page of tune2fs for more information.
Reserved blocks percentage
According to the manual, reserved blocks are designed to keep your system from failing when you run out of space. Its reserves space for privileged processes such as daemons that start during init 3 and the reserved space can also prevent the filesystem from fragmenting as it fills up. On large partitions such as 300gb, however, the default 5% reserved space can be 15gb, which is quite a lot of space.
You can use the following command to reduce it to 3%, which is a bit more logical on larger filesystems.
Code: tune2fs -m3 /dev/sda1
Remember, you don’t want to remove the reserved blocks entirely, just reduce it to gain back unused space for unprivileged data.
dir_index: Use hashed b-trees to speed up lookups in large directories.
You can enable it with this command.
Code: tune2fs -O dir_index /dev/sda1
Thats not enough however, you much run e2fsck on the partition with the -D parameter to optimize the directories for dir_index.
To do this, you must unmount it, or remount as read only. If you are using the partition and can’t unmount it, switch to init 1 and run
Code: umount /dev/sda1
This will remount it as read only. You can then proceed to running
Code: fsck -Df /dev/sda1
and then
Code: reboot
fsck timers
Ext3 disk checks are long and usually uneventful. By default ext3 is scheduled for a full disk check quite often (about 32 mounts or a few weeks).
Time dependent fsck flags generally are less reliable, you can reset your CMOS on your bios or a power outage might mess with it. Its just really easy to change the time.
To disable time dependent fscking, you would run something like this:
Code: tune2fs -i0 /dev/sda1
# of mounts is more accurate, so there is no need to change the defaults (32), but if you did, this would be an example for 100 mounts.
Code: tune2fs -c100 /dev/sda1

Thursday 6 March 2008

Install Extra Applications in Fedora

Install Email Client (Mozilla Thunderbird)
yum -y install thunderbird
Applications -> Internet -> Thunderbird Mail Client

Install Newsreader (Pan)
yum -y install pan

Install CHM viewer (GnoCHM)
yum -y –enablerepo=dries install gnochm
Applications -> Accessories -> CHM Viewer

Install Web Authoring System (bluefish)
yum -y install bluefish
Applications –> Programming –> Bluefish Editor

Install CD/DVD Burning Application (GnomeBaker)
yum -y install gnomebaker
Applications -> Sound & Video -> GnomeBaker

Install Partition Editor (GParted)
yum -y install gparted
Applications -> System Tools -> GParted

Install Firewall (Firestarter)
yum -y install firestarter
Applications -> System Tools -> Firestarter

Install Extra Fonts
yum -y install xfonts-arabic
yum -y install xfonts-chinese
yum -y install xfonts-gujarati
yum -y install xfonts-hebrew
yum -y install xfonts-hindi
yum -y install xfonts-japanese
yum -y install xfonts-xorg-truetype
rpm -ivh msttcorefonts-1.3-4.noarch.rpm

Install Desktop Applets (gDesklets)
yum -y install gdesklets
Applications -> Accessories -> gDesklets

Install XFCE
yum -y groupinstall XFCE
/etc/init.d/xfs restart

Wednesday 5 March 2008

How to enable the root account in Ubuntu

As you have noticed during the Ubuntu installation there was no question about the root password, as you might have been used to see during other Linux distribution installation process. 
This is why the root account is inactive and can’t be used (no password configured) until we will setup a proper password for it. 

To do this, we simply need to run:
sudo passwd root
 
This will ask for a new root password and once you confirm it, you can start using the root account to login.

In case you will want to disable back the root account, 
just lock the root account by running:
sudo passwd -l root

Tuesday 4 March 2008

Install MP3 Support in Fedora 7

Follow these instructions to get mp3 support on your Fedora Core 7.

Open a terminal and become root, then run this command:
# wget http://rpm.livna.org/fedora/7/i386/livna-release-7-2.noarch.rpm
# rpm -ivh livna-release-7-2.noarch.rpm

Install all other plug ins..
# yum -y install gstreamer-plugins-bad gstreamer-plugins-ugly xine-lib-extras-nonfree

Monday 3 March 2008

Multimedia support in OpenSuse 10.3 (MP3, DiVX, etc.)

If you are using KDE - Download and run (execute) this
If you are using Gnome - Download and execute this
This will enable you to have:
  • Flash
  • Java
  • Latest Amarok (with MP3 Support) for KDE, or Helix-Banshee for GNOME users
  • Encrypted DVD (libdvdcss)
  • Extra XINE Codecs, for DivX/Xvid etc. (libxine1)
  • K3b with MP3 Support (k3b-codecs)
  • Win 32 Codecs (w32codec-all)

Sunday 2 March 2008

Protect yourself from getting hacked!!!!!!


Before writing more about hacking, i was thinking to let the innocent people know about hacking and how hackers perform their hacking operation to get your accounts. So that you can protect yourself from getting hacked!!!!!!



I am giving here Tips that ' what you should not to do' with explanation that ' why not to do'.





Tip 1. Use Strong Passwords: 


  • Always use passwords that hard to guess (Mix of digits + letters in Upper case and lower case both) for your all accounts. the longer your password, the better.
  •  Never use any common word, your name, spouse, parents, birthdate etc.

Explanation 1: 


  • Week Passwords and be easily  hacked using a Brute Force method which do combination of numbers and letters until the real password comes.
  • Common passwords containing name, birthdate can be easily guessed by your friends, any known to you.


Tip 2. Carefully Click on Links: 


  • Always Check the links carefully before clicking on that.
Explanation 2:
  •  To explain the this tip,I am taking to examples. Read the examples carefully. 
    • Ex. 1: Please verify your Account....login here "http://okrut.com
    • Ex. 2:" we are upgrading our system. please verify your name, mail id, password etc. etc. before date blah blah...  here "http://yahoo.com/"  
    • Ex. 3: check this image... this screen shot i hv taken from a forum in Orkut.

Did you get what is Wrong here in these 2 Examples.hmmmm??? Ok let me explain you.

  • In Ex. 1: check the spelling of Orkut carefully in that link. It can take you on a Fake Orkut Login page. that is called Phishing attack. As soon as you login through that fake login page the hacker get the login name, password or complete information of your account. 
  • In Ex. 2: is there anything wrong???? All the spellings are correct... dear ones, just click on the link, you will understand whats wrong. Don't afraid to click... you r safe... Its just a tutorial to let you learn the things. So click the link......
    • hmmm.... Got my Point in ex. 2, Its showing you the link of yahoo. but as you click on it, It redirect you to this site. So Always check the link carefully. I recommend you to use "link preview addon" for your browser. 
  • In Ex. 3: check the link carefully..... in last the extension is html... but just before html its written exe..... html is written here just to make you fool. so that you click on link. but as soon as you will click, an executable file will be installed into ur system. 



Tip 3: Never Open Email Attachments without scanning:
  • Don't open any email attachment from any unknown person. And if the person is known then also first scan the email attachment before open or download it.
Explanation 3:
  • Email Attachments can contain Executable Virus files, that can harm your system. These files usually comes with extension .vbs, .bat, .exe.
  • image files with extension .Jpeg or .gif can also contain virus. Beware, Virus can be integrated with those jpeg files that are also auto executable. As soon as you open the virus infected picture, the virus will be install into your system.
  • Sometimes the file extensions are hided to make you fool.you can get an attachment with .txt extension(as txt files never contain executables) But in actual extension could be .vbs, .exe, .bat etc... check here for eg:http://en.wikipedia.org/wiki/ILOVEYOU
  • Word files, Excel Files can also contail macro viruses, that are very harmfull.


Tip 4. Never  get Trapped into attractive ads....Download only from reputed Sites.  
  • Attractive ads like:
    • Jackpot...."You have won $100000" , "You are the lucky member today", "Free recharge",
    • Free screen-savers, Free wallpaper, Free Mouse Icons, Free Smiles
    • Free computer scan  
    • Free Software
  • Don't download Any software or anything else from just anywhere. Always check for reputed sites then download.
Explanation 4:
  • These ads are simply a  way to attract you to steal your identity and personal information. As soon as you click on it, the stealers get into your computer.
  •  Stealers are that which store all the matter you type including your username, password and send the information to the Hacker. The worst thing is these stealers are not come into notice by your antivirus.   

Tip 5: Surf Internet From a limited User Account.
  • Create a limited user account on your system that does not have administrator rights. and surf web only from that limited account.
Explanation 5: 
  • As limited Account does not have administrators right. So if anything does get into your system, will cannot change any main functions of your system.  

Tip 6: Don't tell Your IP to unknowns.

Explanation 6: 
  • If you tell your IP to anyone then there may be chance that they can see Files in your system.


Tip 7: Turn off all java and java scripting by default
  • Turn of java scripting for your browser by default and only enable it for sites that you know you can trust.
Explanation 7:
  • This can change your account details, passwords, and can simply hack you.
  • Recently "Free Recharge Trick" on orkut is an Example of java script. It changes the victims complete profile, join unnecessary communities, leave scrap and comments on pictures of friends, and start a new community topic in forums congaing the Free Recharge trick's link, to get more people into this trap.  See Profile of my one friend on orkut after using java script...... 


Tip 8: Never read an unsolicited e-mail
  •  Do spam unsolicited emails immediately without opening.
Explanation 9: 
  • Coz just by opening mail, the sender can know your IP and probably can hack u!!!


Tip 9: Always use different different passwords
  •  Keep Password different  for some important account like paypal or any online banking account, other then your social account's passwords 
  • Try to use different passwords for your all accounts.




Tip 10: Keep your Antivirus Up to date.

Explanation 5: 
  • Antivirus updates contains the definitions of Viruses till date. So if you don't  Update it regularly, then there can be chance to get infected your system from a latest coming Virus.


Be safe :)

Saturday 1 March 2008

Make your start menu email Link point to Hotmail email

By default when you open your start menu there will be a link to a default email program. This link usually points to either Microsoft Outlook or Windows Mail. If you do not use either of these programs then you can make that Email icon link to some other email client like Thunderbird or even Windows Live which is Hotmail. 

Here’s how to make your start menu email Link point to Hotmail email:

For this example we will presume that your link in the start menu is pointing to Microsoft Office Outlook E-mail and you would like it to link to Windows Live Mail (Hotmail). See in the screenshot below. The link clearly says Microsoft Office Outlook underneath it.
Change start menu email link
  • Right click your mouse on the start button in the bottom left corner and a menu will pop up. This works for Windows XP also, but the start menu just looks a bit different.
  • Choose Properties from the menu. See the screenshot below.
  • The taskbar and start menu properties will appear. Make sure you are on the Start Menu tab.
  • Click on the Customize button.
customize start menu - email link in menu
  • The customize start menu box will open. Go down to where it says E-mail Link and place a tick in the box.
  • Then click the drop down arrow to see your choices of email programs to link to. As you can see I am going to choose Windows Live mail which is hotmail. See the screenshot below.
change email link to hotmail windows live mail
  • Select the one you want and click OK. That box will disappear.
  • Click OK on the next box also.
See the result below. Now when I click on the link to open email it will take me to the Hotmail Windows Live email homepage. That is a lot easier than opening an internet browser, then finding the hotmail webpage and then checking your email.
result - changed the email link to hotmail in the start menu
Next previous home