Prakash Sawarkar: Kernel 3.8 Released, how to Compile in Redhat, CenOS and Fedora..

Kernel 3.8 Released, how to Compile in Redhat, CentOS and Fedora.

Saturday, 22 October 2011

How to create & convert Linux File Systems Ext2, Ext3 & Ext4

ext2,ext3 and ext4 are all filesystems created for Linux.

High level difference between these filesystems.
How to create these filesystems.
How to convert from one filesystem type to another.

I converted from ext2 to ext3, ext3 to ext4 and ext2 to ext4 file systems successfully. By following this guide anyone can convert their file systems smartly, but still I like to WARN you’ll before doing this, because the following task required skilled administrative practices and make sure you must take important backup of your files before doing this. If in case something goes wrong at least you can revert to back with your backup data.
File system is divided in two segments called User Data and Metadata. In this article I am trying to explore how to create and convert various Linux file systems and high level difference amongst Ext2, Ext3 and Ext4 file systems. Before moving further readings, let me introduce a brief about Linux file systems.

Ext2:- Stands for second extended file system.
It was introduced in 1993. Developed by Rémy Card.
This was developed to overcome the limitation of the original ext file system.
Ext2 does not have journaling feature.
On flash drives, usb drives, ext2 is recommended, as it doesn’t need to do the over head of journaling.
Maximum individual file size can be from 16 GB to 2 TB
Overall ext2 file system size can be from 2 TB to 32 TB

Ext3:- Stands for third extended file system.
It was introduced in 2001. Developed by Stephen Tweedie.
Starting from Linux Kernel 2.4.15 ext3 was available.
The main benefit of ext3 is that it allows journaling.
Journaling has a dedicated area in the file system, where all the changes are tracked. When the system crashes, the possibility of file system corruption is less because of journaling.
Maximum individual file size can be from 16 GB to 2 TB
Overall ext3 file system size can be from 2 TB to 32 TB
There are three types of journaling available in ext3 file system.
Journal – Metadata and content are saved in the journal.
Ordered – Only metadata is saved in the journal. Metadata are journaled only after writing the content to disk. This is the default.
Writeback – Only metadata is saved in the journal. Metadata might be journaled either before or after the content is written to the disk.
You can convert a ext2 file system to ext3 file system directly (without backup/restore).

Ext4:- Stands for fourth extended file system.
It was introduced in 2008.
Starting from Linux Kernel 2.6.19 ext4 was available.
Supports huge individual file size and overall file system size.
Maximum individual file size can be from 16 GB to 16 TB
Overall maximum ext4 file system size is 1 EB (exabyte). 1 EB = 1024 PB (petabyte). 1 PB = 1024 TB (terabyte).
Directory can contain a maximum of 64,000 subdirectories (as opposed to 32,000 in ext3)
You can also mount an existing ext3 fs as ext4 fs (without having to upgrade it).
Several other new features are introduced in ext4: multiblock allocation, delayed allocation, journal checksum. fast fsck, etc. All you need to know is that these new features have improved the performance and reliability of the filesystem when compared to ext3.
In ext4, you also have the option of turning the journaling feature “off”.

Creating an ext2, or ext3, or ext4 filesystem

Once you’ve partitioned your hard disk using fdisk command, use mke2fs to create either ext2, ext3, or ext4 file system.

Creating Ext2 File System

#  mke2fs /dev/sdXX

Creating Ext3 File System

#  mke2fs –j  /dev/sdXX

-j option is used for journaling.

Creating Ext4 File System

# mke2fs -t ext4 /dev/sdXX

-t option to specify the file system type.

Converting an Ext2, or Ext3, or Ext4 File Systems

If you are upgrading /dev/sda2 that is mounted as /home, from ext2 to ext3, do the following.

Converting Ext2 to Ext3

#  umount /dev/sda2
#  tune2fs -j /dev/sda2
#  mount /dev/sda2 /home

You really don’t need to umount and mount it, as ext2 to ext3 conversion can happen on a live file system. But, I feel better doing the conversion offline.

Converting Ext3 to Ext4

#  umount /dev/sda2
#  tune2fs -O extents,uninit_bg,dir_index /dev/sda2
#  e2fsck -pf /dev/sda2
#  mount /dev/sda2 /home

-p option automatically repairs the file system.
-f option force checking file system even it seems clean.
WARNING: You cannot revert or mount back to ext3 filesystem once you run above command.

Converting Ext2 to Ext4

To convert from old ext2 to new ext4 file system with latest journaling feature. Run the following command.

#  umount /dev/sdxx
#  tune2fs -O dir_index,has_journal,uninit_bg /dev/sdxx
#  e2fsck -pf /dev/sdXX
#  mount /dev/sdxx /home

Note: all of the above commands only on a test Linux server, where you can afford to lose all your data.

Wednesday, 20 July 2011

Secure your RHEL/CentOS Server Prevent from DoS and Bruteforce (Intrusion Prevention)

Prevent from DoS and Bruteforce attack.

Bruteforce and Denial Of Service are both automated attacks that you can prevent by using tools specially made for this purpose.

Fail2ban is an open source free intrusion prevention framework developed in python programming language. Fail2ban operates by monitoring log files such as /var/log/pwdfail, /var/log/auth.log, /var/log/secure etc. and bans the IP address after too many password failure attempts. It used to update iptable firewall rules to reject the IP address for a specified amount of time.
              Fail2ban is designed to ban users which fail to login correctly on your server, its main purpose is to prevent malicious users to bruteforce your password.

Before heading up for installation and configuration of Fail2Ban, I would like to tell you that most of the attackers trying to gain root access via SSH. So, I recommend you to pay close attention to things such as disable ssh root logins and use pair of ssh keys for authentication etc.

Step 1-Installing Fail2Ban in RHEL, CentOS and Fedora.
By default Fail2Ban is not available under Linux systems, so you will need to add and enable third party RPMForge repository or EPEL repository in your Linux box. Once you’ve added repository, install it using following YUM command.

# rpm -ivh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarc...
# rpm –import https://fedoraproject.org/static/0608B895.txt
# yum install fail2ban
Step 2- Configuring Default section for Fail2Ban.

The master Fail2Ban configuration file is located under /etc/fail2ban/jail.conf. So, open it using VI editor or any editor that you feel comfortable.
Then edit the configuration file as you wish :

# vi /etc/fail2ban/jail.conf

Now, you will see default section with some basic rules that are followed by fail2ban itself. If you want to add some extra layer of protection to your server, then you can customize the each rule section as per your needs.
# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space separator.
 as follows :














Step 3 -Restarting Fail2Ban Service

Once you’ve made the changes to the fail2ban config file, then always make sure to restart Fail2Ban service.

# chkconfig --level 23 fail2ban on
# service fail2ban start
  Starting fail2ban:                                         [  OK  ]

Step 4- DDOS Deflate

DDos Deflate automatically detects and blocks denial of service attempts. Switch to a folder where you will download the DDoS Deflate script:

# wget http://www.inetbase.com/scripts/ddos/install.sh

# chmod 0700 install.sh
# ./install.sh

A ddos.conf configuration file has been created under /usr/local/ddos/ddos.conf, have a look inside, it's commented well. A software cron job is installed and will regurlarly to the DoS checking.

#  ls -l /etc/cron.d

-rw-r--r--. 1 root root 113 Jul 19  2011 0hourly
-rw-r--r--. 1 root root  74 Apr  1 12:37 ddos.cron
-rw-r--r--. 1 root root 108 Dec  6 21:41 raid-check

# /usr/local/ddos/ddos.sh --help
DDoS-Deflate version 0.6

Usage: ddos.sh [OPTIONS] [N]
N : number of tcp/udp   connections (default 150)
OPTIONS:
-h | --help: Show       this help screen
-c | --cron: Create cron job to run this script regularly (default 1 mins)
-k | --kill: Block the offending ip making more than N connections

Watch Failed SSH login attempts

To see the current ssh failed login attempts, run the following command it will display a list of failed attempts attempted by hosts.

# cat /var/log/secure | grep 'Failed password' |  sort | uniq -c 


Wednesday, 29 June 2011

How to Kill a SSH User Shell Session

As Administrator, when you do a notice that you will some of your users have idle and active ssh session. The idle ssh session could be be due to the hanged ssh session. So the question is how to remove the individual session without killing the active and genuine session.

First thing first, do
#  w
You may get some information like this
18:00:35 up 143 days, 19:57,  3 user,  load average: 0.03, 0.01, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT 
user1   pts/31   :24.0            08Oct11 22days  0.05s  0.05s -bash
user2   pts/24   :30              02Jan11  2days  0.66s  0.66s -bash
user3   pts/55   :17              12Nov10 59days  0.01s  0.01s -bash
To get process id (PID) of the idle session, do the command 
#  ps -aux | grep 'pts/31'
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
root     33541  0.0  0.0  61172   776 pts/1    S+   00:41   0:00 grep pts/31
523      33678  0.0  0.0  64188  1516 pts/31   Ss+   2012   0:00 -bash
Kill the Process
#  kill -9 33678
The idle ssh session has been removed. You can verify with the command "w"

Friday, 17 June 2011

25 Facts About GNU/Linux

Linux is a land of excavation, the more you excavate the more you find treasure lies within it. This article tries to uncover some of the lesser known facts about Linux. To keep things simple, easy to read, easy to remember and easy to refer this article will be presented in point-wise fashion.

1. Linux is not an OS, but it is the kernel, GNU Linux is the OS and it comes in several hundred flavours.
2. Linux Kernel was written by a 21 year finnish college student as a part of his hobby. Yup! His name is Linus Torvalds.
3. Torvalds created Linux based on GNU General Public License (GPL). Perhaps Torvalds would have never written his own kernel if GPL would be having it’s own kernel and driver.
4. Major part of today’s Linux kernel is written in C programming language and assembly language and only 2% of today’s kernel contains code written by Torvalds.
5. A Standard Linux Kernel of today has over 10 Million lines of code and it grows at the rate of 10% every year. About 4500 lines of codes are added and 1500 lines of code are changed everyday. Initially in 1991, Linux kernel version 0.01 was released with 10239 lines of code.
6. A guy named William Della Croce Jr. registered the name Linux and demanded royalty for using its name and mark. However he agreed to handover the trademark to Linus, later.
7. The Linux kernel’s official mascot is a penguin named Tux, abbreviation of tuxedo. The idea that Linux had a pet penguin comes from Linus Torvalds himself.
8. The first commercial distribution of GNU / Linux was Yggdrasil (http://en.wikipedia.org/wiki/Yggdrasil_Linux/GNU/X) and was launched in CD format in 1992. Red Hat was one of the first distributions to settle within companies and data centers in 1999.
9. Debian was one of the first GNU / Linux that was constituted and organized as a community of developers. Debian v. 4.0′s source code contains 283 million lines of code, $7.37 billion: projected cost to produce that amount of code in a commercial environment. Debian’s code base remains the foundation for other distros such as Ubuntu, Knoppix and Xandros.
10. 90% of the world’s most powerful supercomputers are using GNU/Linux. Top ten of supercomputers use Linux. 33.8% of the world runs on Linux servers compared to 7.3% running Microsoft Windows operating system.
11. Linux Torvalds has been honoured by naming an astroid after his name.
12. There are over 300 distributions GNU / Linux activities ranging from the well known Debian or Fedora distributions through governmental or educational level. And this list seems to grow with regional and personal distros being added frequently.
13. OK, Now the area of application of Linux – U.S. Department of Defense, U.S. Navy Submarine Fleet, Federal Aviation Administration, Tamil Nadu for education purpose, Japan’s bullet trains, traffic control of San Francisco, the New York Stock Exchange, CERN, many air traffic control systems or control of nuclear reactors of submarines and ships, Russia, Brazil and Venezuela for interoperable management , cost efficient and technologically independence, Google, Cisco, Facebook, Twitter, Linked in, Toyota, TiVo, etc, server hosting the website of the White House (Drupal), federal government of Brazil favours Linux operating systems over all others in its PCs. Is Not Linux kernel the most widely ported operating system, running on a great variety of operating systems.
14. For those who think Linux can’t do Animation – Oscar-winning visual effects of the Titanic by James Cameron came from machines with Linux and Avatar was the last movie completely developed in 3D Applications on Linux platform using Foss Software. Exclaimed!
15. Believe it or not – In 2002, Microsoft had accumulated a $ 421 million cost of fighting the spread of Linux, according to The Register.
16. According to a study funded by the European Union, the estimated cost to redevelop the most recent kernel versions would be at $1.14 billion USD – Amazed.
17. Microsoft Windows and the Linux kernel can run simultaneously in parallel on the same machine using a software called Cooperative Linux (coLinux).
18. IBM choose Linux for what is expected to be the world’s most powerful supercomputer, Sequoia, due in 2011.
19. An unmodified version of the Linux kernel is called – ''Vanilla Kernel''
20. Last year, 75% of Linux code was developed by programmers working for corporations. GOOGLE has contributed about 1.1% of the code in the current Linux kernel.
21. Linux has a strong following in Smart Phones – Palm’s WebOS, Google’s Android and Nokia’s Maemo smart phone operating systems are built on top of the Linux kernel.
22. Android’s Operating System is based off of Linux. The operating system is primarily based off of Linux kernel and Google has made several changes to make it go above and beyond the original basis of Linux kernel. The first Android Smart phone was launched by HTC! Though Samsung has captured much of the Android smart phone sector with its Galaxy series of devices.
23. Google names the code names of Android versions in alphabetical order. These names are not random but names of desserts. Can you guess the next versions of Android now? Android 5.0 K………..?!, Android 6.0 L………….?!!
24. Android mascot was stolen! Google didn’t originally create that mascot. The mascot was adopted from a character named Android! from a game called Gauntlet.
25. As of January 2010, Linux still only has a 1.02% market share within desktops.
This is not the end. You could tell us any other interesting fact about this wonderful project, if you know. Nevertheless you comments are highly appreciated. I will be coming with another article, very soon which you will love to read. Stay Tuned.

Saturday, 19 February 2011

Backup for /etc/passwd , /etc/group , /etc/shadow

/etc/passwd /etc/group /etc/shadow are very essential file systems for Linux. You should not be surprised that linux does do a backup of the /etc/passwd /etc/group /etc/shadow. They are represented by

#  /etc/passwd-
#  /etc/group-
#  /etc/shadow-

So in case your any of your /etc/passwd /etc/group /etc/shadow are corrupted, just do a copy and replace

Note: listed with the appropriate access permissions
  File:             Owner:  Group:  Permissions:
/etc/passwd      root     root   rw- r-- r--
/etc/group root     root   rw- r-- r--
/etc/shadow root     root   rw- --- ---

Sunday, 23 January 2011

KVM Virtual Machine Renaming

Renaming KVM  Virtual Guest Running on Centos 
This below docs covers how to rename  any of the guest  running on  CentOS 5.6 and later KVM+libvirt Host Log in as root on the Host because Most of below virsh  commands require root privileges to run due to the communications channels used to talk to the hypervisor. Running as non root will return an error.
Then run the virsh - management user interface  tool from  the command line
What is virsh?
The virsh program is the main interface for managing virsh guest domains. The program can be used to create, pause, and shutdown domains.
The basic structure of most virsh usage is:
virsh <command> <domain-id> [OPTIONS]
Where command is one of the commands listed below, domain-id is the numeric domain id, or the domain name (which will be internally translated to domain id), and OPTIONS are command specific options. 
The virsh program can be used either to run one command at a time by giving the command as an argument on the command line, or as a shell if no command is given in the command line, it will then start a minimal interpreter waiting for your commands and the quit command will then exit the program.
 After execute the "list" command  it will list all the running guest with Name is the name of the domain.  ID the domain numeric id.  State is the run state .  If you want to list all the guest run "list --all" inside a virsh shell 
 In our next step  we are going to  select the guest we wish to rename in our case its Centos6-prakash with the ID 14 and its in running state.
[root@prakash ~]# virsh 
Welcome to virsh, the virtualization interactive terminal.
Type:  'help' for help with commands
       'quit' to quit
virsh # list 
 Id Name                 State
----------------------------------
  4 RHEVM2.2-Win2k8R2    running
 14 Centos6-prakash            running

virsh # list --all
 Id Name                 State
----------------------------------
  4 RHEVM2.2-Win2k8R2    running
 14 Centos6-prakash           running
  - Win2k3            shut off
  - RHEL-WEB             shut off
virsh # edit 14        (it will open the guest xml file in vi  editor modify the name and save it)
<domain type='kvm'>
  <name>Centos6-prakash</name>        --->change the name from  Centos6-prakash to RHEL6-X86_64_prakash and save it
  <uuid>3a0a2cb7-095a-8ad9-624c-5163cf52692a</uuid>
  <memory>1048576</memory>
  <currentMemory>1048576</currentMemory>
virsh # edit 14
error: operation failed: domain 'Centos6-prakash' is already defined with uuid 3a0a2cb7-095a-8ad9-624c-5163cf52692a
The above error is exactly the expected behavior.  virsh edit does not support changing the name or UUID.  If you want to change either of those, you'll need to the following.
Shut down the vm using the virsh command line or using virt-manager
#virsh shutdown Centos6-prakash
Change to the directory
# cd /etc/libvirt/qemu/
 An easy way to obtain the definition of a pre-existing guest is by using dumpxml command.
# virsh  dumpxml Centos6-prakash  >  CentOS6-X86_64_Prakash.xml
Now Undefine the configuration for an inactive guest (Centos6-prakash)
[root@prakash qemu]# virsh  undefine Centos6-prakash
Domain Centos6-prakash has been undefined
Now edit the new xml file and save it
[root@prakash qemu]# vi Centos6-X86_64_prakash.xml
<domain type='kvm'>
  <name>CentOS6-X86_64_prakash</name>  --> Centos6-prakash was replaced by Centos6-X86_64_prakash
  <uuid>3a0a2cb7-095a-8ad9-624c-5163cf52692a</uuid>
Once you saved it  Define a new  domain from an XML (Centos6-X86_64_Prakash.xml) 
  [root@prakash qemu]# virsh define Centos6-X86_64_prakash.xml
Domain Centos6-X86_64_prakash defined from Centos6-X86_64_prakash.xml
Now go to virt-manager or visrh command line and start the renamed guest.
# virsh start Centos6-X86_64_prakash
[root@prakash qemu]# virsh  list --all
 Id Name                   State
----------------------------------
  4 RHEVM2.2-Win2k8R2          running
  5 Centos6-X86_64_Prakash     running
----------------------------------

Friday, 14 January 2011

Setting up RHEL /CentOS Virtio Drivers for Windows Guest on KVM

Installing VirtIO  Block drivers on Windows Guest System Boot disk on KVM
Virt IO block driver can be used either as a system (boot) or non-system disk. In this section we are going to see how to attach virtio disk for system boot disk new  windows 2008 virtual machine we are going to create on top of RHEL6 KVM Host.
Install the RHEL6 and select Only "Virtual Host" during the Package Selection during the Installation it will  install all the necessary kvm packages to create and manage virtual machines 
Then Register the host With RHN Satellite and subscribe to  RHEL Server Supplementary  Child channel and install the virtio-win using yum.
# yum install virtio-win
or
Even you can download the  virtio-win-1.1.16-0.el6.noarch and install it manually  on the host .
Once you installed you will find all the drivers under /usr/share/virtio-win/ diretcory and you can check it using the simple rpm comand line by typing .
rpm -ql virtio-win-1.1.16-0.el6.noarch.
# ls /usr/share/virtio-win/

drivers/      virtio-win-1.1.16.vfd  virtio-win.vfd  virtio-win-1.1.16.iso  virtio-win.iso
You can Now attach this file virtio-win.iso using cdrom to the windows guest using virt-manager to install either disk or network virt drivers  after the Operating syste installation.
If you want to make your system boot disk to use virtio then you are suppose to use virtio-win-1.1.16.vfd file as a floopy drive and proceed the installation . Installing the tools after the Operating system installation is very straight forward we will see how to use  virtual floppy  drive to load the virtio disk driver during the windows guest installation .
Start the Virt-manager from  the command line or from system tools  .
Create a new virtual machine lets call its as win2k8R2 and Select Media as per you Local Infrastructure , We are using an Local ISO Install image and Select Forward.
Browse the Local ISO Image and Select the Os type to Windows and Version to Microsoft Windows 2008
Select the Required Storage Disk size for your Virtual Machine



Select the Memory and Cpu as per your requirement and Click Forward


You can Expand the Advanced Button to change the Network and MAC Settings and Select "Customize Configuration Before Install " on the final screen and Click Finish.


Click on Add Hardware-->Select Storage-->Forward-->Select Managed or Existing Storage-->Browse for the /usr/share/virtio-win/virtio-win-1.1.16.vfd and Change the Device Type to Floppy 
Disk and Leave Cache Mode to default and Finish.


Now Remove the IDE  disk we attached during the Virtual machine creation 
Add the New storage Disk by selecting Add Hardware and give the disk size and select Device Type to  virtio Disk instead of IDE.
Now we have virtual Floppy disk attached and even we added a New Virtio disk for  windows guest system boot disk .Now it time to close the custom windows , Once you close it your new windows guest installation screen will Pop Up .
Follow the On screen Instruction of windows installation , after you select the Custom Install you will get a below screen to Load drivers for the Virtio Disk .Now Select Load Drivers-->Browse or Rescan , you will find all the drivers attached from the virtual floppy for this windows guest.
Select Red Hat Virtio for Scsi Controller for windows 2008 and Click Next , then you Proceed your windows guest  installation as per on screen instruction.