Category Archives: Linux

50 Most Frequently Used UNIX / Linux Commands (With Examples)

This article provides practical examples for 50 most frequently used commands in Linux / UNIX.

This is not a comprehensive list by any means, but this should give you a jumpstart on some of the common Linux commands. Bookmark this article for your future reference.

Did I miss any frequently used Linux commands? Leave a comment and let me know.

1. tar command examples

Create a new tar archive.

$ tar cvf archive_name.tar dirname/
Extract from an existing tar archive.

$ tar xvf archive_name.tar
View an existing tar archive.

$ tar tvf archive_name.tar
More tar examples: The Ultimate Tar Command Tutorial with 10 Practical Examples

2. grep command examples

Search for a given string in a file (case in-sensitive search).

$ grep -i “the” demo_file
Print the matched line, along with the 3 lines after it.

$ grep -A 3 -i “example” demo_text
Search for a given string in all files recursively

$ grep -r “ramesh” *
More grep examples: Get a Grip on the Grep! – 15 Practical Grep Command Examples

3. find command examples

Find files using file-name ( case in-sensitve find)

# find -iname “MyCProgram.c”
Execute commands on files found by the find command

$ find -iname “MyCProgram.c” -exec md5sum {} \;
Find all empty files in home directory

# find ~ -empty
More find examples: Mommy, I found it! — 15 Practical Linux Find Command Examples

4. ssh command examples

Login to remote host

ssh -l jsmith remotehost.example.com
Debug ssh client

ssh -v -l jsmith remotehost.example.com
Display ssh client version

$ ssh -V
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
More ssh examples: 5 Basic Linux SSH Client Commands

5. sed command examples

When you copy a DOS file to Unix, you could find \r\n in the end of each line. This example converts the DOS file format to Unix file format using sed command.

$sed ‘s/.$//’ filename
Print file content in reverse order

$ sed -n ’1!G;h;$p’ thegeekstuff.txt
Add line number for all non-empty-lines in a file

$ sed ‘/./=’ thegeekstuff.txt | sed ‘N; s/\n/ /’
More sed examples: Advanced Sed Substitution Examples

6. awk command examples

Remove duplicate lines using awk

$ awk ‘!($0 in array) { array[$0]; print }’ temp
Print all lines from /etc/passwd that has the same uid and gid

$awk -F ‘:’ ‘$3==$4′ passwd.txt
Print only specific field from a file.

$ awk ‘{print $2,$5;}’ employee.txt
More awk examples: 8 Powerful Awk Built-in Variables – FS, OFS, RS, ORS, NR, NF, FILENAME, FNR

7. vim command examples

Go to the 143rd line of file

$ vim +143 filename.txt
Go to the first match of the specified

$ vim +/search-term filename.txt
Open the file in read only mode.

$ vim -R /etc/passwd
More vim examples: How To Record and Play in Vim Editor

8. diff command examples

Ignore white space while comparing.

# diff -w name_list.txt name_list_new.txt

2c2,3
< John Doe — > John M Doe
> Jason Bourne
More diff examples: Top 4 File Difference Tools on UNIX / Linux – Diff, Colordiff, Wdiff, Vimdiff

9. sort command examples

Sort a file in ascending order

$ sort names.txt
Sort a file in descending order

$ sort -r names.txt
Sort passwd file by 3rd field.

$ sort -t: -k 3n /etc/passwd | more
10. export command examples

To view oracle related environment variables.

$ export | grep ORACLE
declare -x ORACLE_BASE=”/u01/app/oracle”
declare -x ORACLE_HOME=”/u01/app/oracle/product/10.2.0″
declare -x ORACLE_SID=”med”
declare -x ORACLE_TERM=”xterm”
To export an environment variable:

$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0
11. xargs command examples

Copy all images to external hard-drive

# ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory
Search all jpg images in the system and archive it.

# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
Download all the URLs mentioned in the url-list.txt file

# cat url-list.txt | xargs wget –c
12. ls command examples

Display filesize in human readable format (e.g. KB, MB etc.,)

$ ls -lh
-rw-r—– 1 ramesh team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz
Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr

$ ls -ltr
Visual Classification of Files With Special Characters Using ls -F

$ ls -F
More ls examples: Unix LS Command: 15 Practical Examples

13. pwd command

pwd is Print working directory. What else can be said about the good old pwd who has been printing the current directory name for ages.

14. cd command examples

Use “cd -” to toggle between the last two directories

Use “shopt -s cdspell” to automatically correct mistyped directory names on cd

More cd examples: 6 Awesome Linux cd command Hacks

15. gzip command examples

To create a *.gz compressed file:

$ gzip test.txt
To uncompress a *.gz file:

$ gzip -d test.txt.gz
Display compression ratio of the compressed file using gzip -l

$ gzip -l *.gz
compressed uncompressed ratio uncompressed_name
23709 97975 75.8% asp-patch-rpms.txt
16. bzip2 command examples

To create a *.bz2 compressed file:

$ bzip2 test.txt
To uncompress a *.bz2 file:

bzip2 -d test.txt.bz2
More bzip2 examples: BZ is Eazy! bzip2, bzgrep, bzcmp, bzdiff, bzcat, bzless, bzmore examples

17. unzip command examples

To extract a *.zip compressed file:

$ unzip test.zip
View the contents of *.zip file (Without unzipping it):

$ unzip -l jasper.zip
Archive: jasper.zip
Length Date Time Name
——– —- —- —-
40995 11-30-98 23:50 META-INF/MANIFEST.MF
32169 08-25-98 21:07 classes_
15964 08-25-98 21:07 classes_names
10542 08-25-98 21:07 classes_ncomp
18. shutdown command examples

Shutdown the system and turn the power off immediately.

# shutdown -h now
Shutdown the system after 10 minutes.

# shutdown -h +10
Reboot the system using shutdown command.

# shutdown -r now
Force the filesystem check during reboot.

# shutdown -Fr now
19. ftp command examples

Both ftp and secure ftp (sftp) has similar commands. To connect to a remote server and download multiple files, do the following.

$ ftp IP/hostname
ftp> mget *.html
To view the file names located on the remote server before downloading, mls ftp command as shown below.

ftp> mls *.html -
/ftptest/features.html
/ftptest/index.html
/ftptest/othertools.html
/ftptest/samplereport.html
/ftptest/usage.html
More ftp examples: FTP and SFTP Beginners Guide with 10 Examples

20. crontab command examples

View crontab entry for a specific user

# crontab -u john -l
Schedule a cron job every 10 minutes.

*/10 * * * * /home/ramesh/check-disk-space
More crontab examples: Linux Crontab: 15 Awesome Cron Job Examples

21. service command examples

Service command is used to run the system V init scripts. i.e Instead of calling the scripts located in the /etc/init.d/ directory with their full path, you can use the service command.

Check the status of a service:

# service ssh status
Check the steatus of all the services.

service –status-all
Restart a service.

# service ssh restart
22. ps command examples

ps command is used to display information about the processes that are running in the system.

While there are lot of arguments that could be passed to a ps command, following are some of the common ones.

To view current running processes.

$ ps -ef | more
To view current running processes in a tree structure. H option stands for process hierarchy.

$ ps -efH | more
23. free command examples

This command is used to display the free, used, swap memory available in the system.

Typical free command output. The output is displayed in bytes.

$ free
total used free shared buffers cached
Mem: 3566408 1580220 1986188 0 203988 902960
-/+ buffers/cache: 473272 3093136
Swap: 4000176 0 4000176
If you want to quickly check how many GB of RAM your system has use the -g option. -b option displays in bytes, -k in kilo bytes, -m in mega bytes.

$ free -g
total used free shared buffers cached
Mem: 3 1 1 0 0 0
-/+ buffers/cache: 0 2
Swap: 3 0 3
If you want to see a total memory ( including the swap), use the -t switch, which will display a total line as shown below.

ramesh@ramesh-laptop:~$ free -t
total used free shared buffers cached
Mem: 3566408 1592148 1974260 0 204260 912556
-/+ buffers/cache: 475332 3091076
Swap: 4000176 0 4000176
Total: 7566584 1592148 5974436
24. top command examples

top command displays the top processes in the system ( by default sorted by cpu usage ). To sort top output by any column, Press O (upper-case O) , which will display all the possible columns that you can sort by as shown below.

Current Sort Field: P for window 1:Def
Select sort field via field letter, type any other key to return

a: PID = Process Id v: nDRT = Dirty Pages count
d: UID = User Id y: WCHAN = Sleeping in Function
e: USER = User Name z: Flags = Task Flags
……..
To displays only the processes that belong to a particular user use -u option. The following will show only the top processes that belongs to oracle user.

$ top -u oracle
More top examples: Can You Top This? 15 Practical Linux Top Command Examples

25. df command examples

Displays the file system disk space usage. By default df -k displays output in bytes.

$ df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 29530400 3233104 24797232 12% /
/dev/sda2 120367992 50171596 64082060 44% /home
df -h displays output in human readable form. i.e size will be displayed in GB’s.

ramesh@ramesh-laptop:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 29G 3.1G 24G 12% /
/dev/sda2 115G 48G 62G 44% /home
Use -T option to display what type of file system.

ramesh@ramesh-laptop:~$ df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda1 ext4 29530400 3233120 24797216 12% /
/dev/sda2 ext4 120367992 50171596 64082060 44% /home
26. kill command examples

Use kill command to terminate a process. First get the process id using ps -ef command, then use kill -9 to kill the running Linux process as shown below. You can also use killall, pkill, xkill to terminate a unix process.

$ ps -ef | grep vim
ramesh 7243 7222 9 22:43 pts/2 00:00:00 vim

$ kill -9 7243
More kill examples: 4 Ways to Kill a Process – kill, killall, pkill, xkill

27. rm command examples

Get confirmation before removing the file.

$ rm -i filename.txt
It is very useful while giving shell metacharacters in the file name argument.

Print the filename and get confirmation before removing the file.

$ rm -i file*
Following example recursively removes all files and directories under the example directory. This also removes the example directory itself.

$ rm -r example
28. cp command examples

Copy file1 to file2 preserving the mode, ownership and timestamp.

$ cp -p file1 file2
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.

$ cp -i file1 file2
29. mv command examples

Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.

$ mv -i file1 file2
Note: mv -f is just the opposite, which will overwrite file2 without prompting.

mv -v will print what is happening during file rename, which is useful while specifying shell metacharacters in the file name argument.

$ mv -v file1 file2
30. cat command examples

You can view multiple files at the same time. Following example prints the content of file1 followed by file2 to stdout.

$ cat file1 file2
While displaying the file, following cat -n command will prepend the line number to each line of the output.

$ cat -n /etc/logrotate.conf
1 /var/log/btmp {
2 missingok
3 monthly
4 create 0660 root utmp
5 rotate 1
6 }
31. mount command examples

To mount a file system, you should first create a directory and mount it as shown below.

# mkdir /u01

# mount /dev/sdb1 /u01
You can also add this to the fstab for automatic mounting. i.e Anytime system is restarted, the filesystem will be mounted.

/dev/sdb1 /u01 ext2 defaults 0 2
32. chmod command examples

chmod command is used to change the permissions for a file or directory.

Give full access to user and group (i.e read, write and execute ) on a specific file.

$ chmod ug+rwx file.txt
Revoke all access for the group (i.e read, write and execute ) on a specific file.

$ chmod g-rwx file.txt
Apply the file permissions recursively to all the files in the sub-directories.

$ chmod -R ug+rwx file.txt
More chmod examples: 7 Chmod Command Examples for Beginners

33. chown command examples

chown command is used to change the owner and group of a file. \

To change owner to oracle and group to db on a file. i.e Change both owner and group at the same time.

$ chown oracle:dba dbora.sh
Use -R to change the ownership recursively.

$ chown -R oracle:dba /home/oracle
34. passwd command examples

Change your password from command line using passwd. This will prompt for the old password followed by the new password.

$ passwd
Super user can use passwd command to reset others password. This will not prompt for current password of the user.

# passwd USERNAME
Remove password for a specific user. Root user can disable password for a specific user. Once the password is disabled, the user can login without entering the password.

# passwd -d USERNAME
35. mkdir command examples

Following example creates a directory called temp under your home directory.

$ mkdir ~/temp
Create nested directories using one mkdir command. If any of these directories exist already, it will not display any error. If any of these directories doesn’t exist, it will create them.

$ mkdir -p dir1/dir2/dir3/dir4/
36. ifconfig command examples

Use ifconfig command to view or configure a network interface on the Linux system.

View all the interfaces along with status.

$ ifconfig -a
Start or stop a specific interface using up and down command as shown below.

$ ifconfig eth0 up

$ ifconfig eth0 down
More ifconfig examples: Ifconfig: 7 Examples To Configure Network Interface

37. uname command examples

Uname command displays important information about the system such as — Kernel name, Host name, Kernel release number,
Processor type, etc.,

Sample uname output from a Ubuntu laptop is shown below.

$ uname -a
Linux john-laptop 2.6.32-24-generic #41-Ubuntu SMP Thu Aug 19 01:12:52 UTC 2010 i686 GNU/Linux
38. whereis command examples

When you want to find out where a specific Unix command exists (for example, where does ls command exists?), you can execute the following command.

$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
When you want to search an executable from a path other than the whereis default path, you can use -B option and give path as argument to it. This searches for the executable lsmk in the /tmp directory, and displays it, if it is available.

$ whereis -u -B /tmp -f lsmk
lsmk: /tmp/lsmk
39. whatis command examples

Whatis command displays a single line description about a command.

$ whatis ls
ls (1) – list directory contents

$ whatis ifconfig
ifconfig (8) – configure a network interface
40. locate command examples

Using locate command you can quickly search for the location of a specific file (or group of files). Locate command uses the database created by updatedb.

The example below shows all files in the system that contains the word crontab in it.

$ locate crontab
/etc/anacrontab
/etc/crontab
/usr/bin/crontab
/usr/share/doc/cron/examples/crontab2english.pl.gz
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man5/anacrontab.5.gz
/usr/share/man/man5/crontab.5.gz
/usr/share/vim/vim72/syntax/crontab.vim
41. man command examples

Display the man page of a specific command.

$ man crontab
When a man page for a command is located under more than one section, you can view the man page for that command from a specific section as shown below.

$ man SECTION-NUMBER commandname
Following 8 sections are available in the man page.

General commands
System calls
C library functions
Special files (usually devices, those found in /dev) and drivers
File formats and conventions
Games and screensavers
Miscellaneous
System administration commands and daemons
For example, when you do whatis crontab, you’ll notice that crontab has two man pages (section 1 and section 5). To view section 5 of crontab man page, do the following.

$ whatis crontab
crontab (1) – maintain crontab files for individual users (V3)
crontab (5) – tables for driving cron

$ man 5 crontab
42. tail command examples

Print the last 10 lines of a file by default.

$ tail filename.txt
Print N number of lines from the file named filename.txt

$ tail -n N filename.txt
View the content of the file in real time using tail -f. This is useful to view the log files, that keeps growing. The command can be terminated using CTRL-C.

$ tail -f log-file
More tail examples: 3 Methods To View tail -f output of Multiple Log Files in One Terminal

43. less command examples

less is very efficient while viewing huge log files, as it doesn’t need to load the full file while opening.

$ less huge-log-file.log
One you open a file using less command, following two keys are very helpful.

CTRL+F – forward one window
CTRL+B – backward one window
More less examples: Unix Less Command: 10 Tips for Effective Navigation

44. su command examples

Switch to a different user account using su command. Super user can switch to any other user without entering their password.

$ su – USERNAME
Execute a single command from a different account name. In the following example, john can execute the ls command as raj username. Once the command is executed, it will come back to john’s account.

[john@dev-server]$ su – raj -c ‘ls’

[john@dev-server]$
Login to a specified user account, and execute the specified shell instead of the default shell.

$ su -s ‘SHELLNAME’ USERNAME
45. mysql command examples

mysql is probably the most widely used open source database on Linux. Even if you don’t run a mysql database on your server, you might end-up using the mysql command ( client ) to connect to a mysql database running on the remote server.

To connect to a remote mysql database. This will prompt for a password.

$ mysql -u root -p -h 192.168.1.2
To connect to a local mysql database.

$ mysql -u root -p
If you want to specify the mysql root password in the command line itself, enter it immediately after -p (without any space).

46. yum command examples

To install apache using yum.

$ yum install httpd
To upgrade apache using yum.

$ yum update httpd
To uninstall/remove apache using yum.

$ yum remove httpd
47. rpm command examples

To install apache using rpm.

# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm
To upgrade apache using rpm.

# rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm
To uninstall/remove apache using rpm.

# rpm -ev httpd
More rpm examples: RPM Command: 15 Examples to Install, Uninstall, Upgrade, Query RPM Packages

48. ping command examples

Ping a remote host by sending only 5 packets.

$ ping -c 5 gmail.com
More ping examples: Ping Tutorial: 15 Effective Ping Command Examples

49. date command examples

Set the system date:

# date -s “01/31/2010 23:59:53″
Once you’ve changed the system date, you should syncronize the hardware clock with the system date as shown below.

# hwclock –systohc

# hwclock –systohc –utc
50. wget command examples

The quick and effective method to download software, music, video from internet is using wget command.

$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
Download and store it with a different name.

$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701
More wget examples: The Ultimate Wget Download Guide With 15 Awesome Examples

Did I miss any frequently used Linux commands? Leave a comment and let me know.

Linux Directory Structure (File System Structure) Explained with Examples

Have you wondered why certain programs are located under /bin, or /sbin, or /usr/bin, or /usr/sbin?

For example, less command is located under /usr/bin directory. Why not /bin, or /sbin, or /usr/sbin? What is the different between all these directories?

In this article, let us review the Linux filesystem structures and understand the meaning of individual high-level directories.
filesystem

1. / – Root

Every single file and directory starts from the root directory.
Only root user has write privilege under this directory.
Please note that /root is root user’s home directory, which is not same as /.
2. /bin – User Binaries

Contains binary executables.
Common linux commands you need to use in single-user modes are located under this directory.
Commands used by all the users of the system are located here.
For example: ps, ls, ping, grep, cp.
3. /sbin – System Binaries

Just like /bin, /sbin also contains binary executables.
But, the linux commands located under this directory are used typically by system aministrator, for system maintenance purpose.
For example: iptables, reboot, fdisk, ifconfig, swapon
4. /etc – Configuration Files

Contains configuration files required by all programs.
This also contains startup and shutdown shell scripts used to start/stop individual programs.
For example: /etc/resolv.conf, /etc/logrotate.conf
5. /dev – Device Files

Contains device files.
These include terminal devices, usb, or any device attached to the system.
For example: /dev/tty1, /dev/usbmon0
6. /proc – Process Information

Contains information about system process.
This is a pseudo filesystem contains information about running process. For example: /proc/{pid} directory contains information about the process with that particular pid.
This is a virtual filesystem with text information about system resources. For example: /proc/uptime
7. /var – Variable Files

var stands for variable files.
Content of the files that are expected to grow can be found under this directory.
This includes — system log files (/var/log); packages and database files (/var/lib); emails (/var/mail); print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp);
8. /tmp – Temporary Files

Directory that contains temporary files created by system and users.
Files under this directory are deleted when system is rebooted.
9. /usr – User Programs

Contains binaries, libraries, documentation, and source-code for second level programs.
/usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp
/usr/sbin contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel
/usr/lib contains libraries for /usr/bin and /usr/sbin
/usr/local contains users programs that you install from source. For example, when you install apache from source, it goes under /usr/local/apache2
10. /home – Home Directories

Home directories for all users to store their personal files.
For example: /home/john, /home/nikita
11. /boot – Boot Loader Files

Contains boot loader related files.
Kernel initrd, vmlinux, grub files are located under /boot
For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic
12. /lib – System Libraries

Contains library files that supports the binaries located under /bin and /sbin
Library filenames are either ld* or lib*.so.*
For example: ld-2.11.1.so, libncurses.so.5.7
13. /opt – Optional add-on Applications

opt stands for optional.
Contains add-on applications from individual vendors.
add-on applications should be installed under either /opt/ or /opt/ sub-directory.
14. /mnt – Mount Directory

Temporary mount directory where sysadmins can mount filesystems.
15. /media – Removable Media Devices

Temporary mount directory for removable devices.
For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer
16. /srv – Service Data

srv stands for service.
Contains server specific services related data.
For example, /srv/cvs contains CVS related data.

RAID 2, RAID 3, RAID 4, RAID 6 Explained with Diagram

In most critical production servers, you will be using either RAID 5 or RAID 10.

However there are several non-standard raids, which are not used except in some rare situations. It is good to know what they are.

This article explains with a simple diagram how RAID 2, RAID 3, RAID 4, and RAID 6 works.

RAID 2
raid2

This uses bit level striping. i.e Instead of striping the blocks across the disks, it stripes the bits across the disks.
In the above diagram b1, b2, b3 are bits. E1, E2, E3 are error correction codes.
You need two groups of disks. One group of disks are used to write the data, another group is used to write the error correction codes.
This uses Hamming error correction code (ECC), and stores this information in the redundancy disks.
When data is written to the disks, it calculates the ECC code for the data on the fly, and stripes the data bits to the data-disks, and writes the ECC code to the redundancy disks.
When data is read from the disks, it also reads the corresponding ECC code from the redundancy disks, and checks whether the data is consistent. If required, it makes appropriate corrections on the fly.
This uses lot of disks and can be configured in different disk configuration. Some valid configurations are 1) 10 disks for data and 4 disks for ECC 2) 4 disks for data and 3 disks for ECC
This is not used anymore. This is expensive and implementing it in a RAID controller is complex, and ECC is redundant now-a-days, as the hard disk themselves can do this.
RAID 3
raid3

This uses byte level striping. i.e Instead of striping the blocks across the disks, it stripes the bits across the disks.
In the above diagram B1, B2, B3 are bytes. p1, p2, p3 are parities.
Uses multiple data disks, and a dedicated disk to store parity.
The disks have to spin in sync to get to the data.
Sequential read and write will have good performance.
Random read and write will have worst performance.
This is not commonly used.
RAID 4
raid4

This uses block level striping.
In the above diagram B1, B2, B3 are blocks. p1, p2, p3 are parities.
Uses multiple data disks, and a dedicated disk to store parity.
Minimum of 3 disks (2 disks for data and 1 for parity)
Good random reads, as the data blocks are striped.
Bad random writes, as for every write, it has to write to the single parity disk.
It is somewhat similar to RAID 3 and 5, but little different.
This is just like RAID 3 in having the dedicated parity disk, but this stripes blocks.
This is just like RAID 5 in striping the blocks across the data disks, but this has only one parity disk.
This is not commonly used.
RAID 6
raid6

Just like RAID 5, this does block level striping. However, it uses dual parity.
In the above diagram A, B, C are blocks. p1, p2, p3 are parities.
This creates two parity blocks for each data block.
Can handle two disk failure
This RAID configuration is complex to implement in a RAID controller, as it has to calculate two parity data for each data block.

RAID 0, RAID 1, RAID 5, RAID 10 Explained with Diagrams

RAID stands for Redundant Array of Inexpensive (Independent) Disks.

On most situations you will be using one of the following four levels of RAIDs.

RAID 0
RAID 1
RAID 5
RAID 10 (also known as RAID 1+0)

This article explains the main difference between these raid levels along with an easy to understand diagram.

In all the diagrams mentioned below:

A, B, C, D, E and F – represents blocks
p1, p2, and p3 – represents parity
RAID LEVEL 0
raid1

Following are the key points to remember for RAID level 0.

Minimum 2 disks.
Excellent performance ( as blocks are striped ).
No redundancy ( no mirror, no parity ).
Don’t use this for any critical system.
RAID LEVEL 1
raidl1

Following are the key points to remember for RAID level 1.

Minimum 2 disks.
Good performance ( no striping. no parity ).
Excellent redundancy ( as blocks are mirrored ).
RAID LEVEL 5
raid5

Following are the key points to remember for RAID level 5.

Minimum 3 disks.
Good performance ( as blocks are striped ).
Good redundancy ( distributed parity ).
Best cost effective option providing both performance and redundancy. Use this for DB that is heavily read oriented. Write operations will be slow.
RAID LEVEL 10
raid10

Following are the key points to remember for RAID level 10.

Minimum 4 disks.
This is also called as “stripe of mirrors”
Excellent redundancy ( as blocks are mirrored )
Excellent performance ( as blocks are striped )
If you can afford the dollar, this is the BEST option for any mission critical applications (especially databases).

6 Stages of Linux Boot Process (Start-up Sequence)

Press the power button on your system, and after few moments you see the Linux login prompt.

Have you ever wondered what happens behind the scenes from the time you press the power button until the Linux login prompt appears?

The following are the 6 high level stages of a typical Linux boot process.
linux boot process

1. BIOS

BIOS stands for Basic Input/Output System
Performs some system integrity checks
Searches, loads, and executes the boot loader program.
It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
So, in simple terms BIOS loads and executes the MBR boot loader.
2. MBR

MBR stands for Master Boot Record.
It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
It contains information about GRUB (or LILO in old systems).
So, in simple terms MBR loads and executes the GRUB boot loader.
3. GRUB

GRUB stands for Grand Unified Bootloader.
If you have multiple kernel images installed on your system, you can choose which one to be executed.
GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
initrd /boot/initrd-2.6.18-194.el5PAE.img
As you notice from the above info, it contains kernel and initrd image.
So, in simple terms GRUB just loads and executes Kernel and initrd images.
4. Kernel

Mounts the root file system as specified in the “root=” in grub.conf
Kernel executes the /sbin/init program
Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
initrd stands for Initial RAM Disk.
initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.
5. Init

Looks at the /etc/inittab file to decide the Linux run level.
Following are the available run levels
0 – halt
1 – Single user mode
2 – Multiuser, without NFS
3 – Full multiuser mode
4 – unused
5 – X11
6 – reboot
Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
Typically you would set the default run level to either 3 or 5.
6. Runlevel programs

When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
Depending on your default init level setting, the system will execute the programs from one of the following directories.
Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 2 – /etc/rc.d/rc2.d/
Run level 3 – /etc/rc.d/rc3.d/
Run level 4 – /etc/rc.d/rc4.d/
Run level 5 – /etc/rc.d/rc5.d/
Run level 6 – /etc/rc.d/rc6.d/
Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
Programs starts with S are used during startup. S for startup.
Programs starts with K are used during shutdown. K for kill.
There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.
There you have it. That is what happens during the Linux boot process.

How to Samba Network Recycle-Bin?

Samba uses VFS (Virtual File System) Module for network recycle bin.
Various modules VFS modules that samba can use are located at “/usr/lib/samba/vfs”.
For Recycle purpose we are using recycle.so module.
Use VFS object to the Shares for which Recycle-Bin is required as below:
/etc/samba/smb.conf
#==========================================================
[SecAudi-RD]
path = /Apps/Scripts
public = yes
writable = yes
browsable = yes
valid users = user1 user2 user3
vfs object = recycle
recycle:repository = .RecycleBin/%U
recycle:keeptree = Yes
recycle:touch = Yes
recycle:versions = Yes
recycle:maxsize = 0
recycle:exclude = *.tmp
recycle:exclude_dir = /tmp
recycle:noversions = *.ppt
#====================================================
The recycle configuration is only valid for the Directory Path defined in a Share,
i.e. “path = /Apps/Scripts”. Add the configuration to all the share for which
Recycle-Bin is required.
Options are as below:
1. recycle:repository = .RecycleBin/%U
This option defines where deleted files will be stored.
.RecycleBin is the directory where deleted stuff will be moved within a shared path.
%U is user name of the person currently browsing the share.
So a sub-directory will be created under .RecycleBin by the name of the user who is
deleting the files.
Eg. If user1 is browsing the share and deleted any file. The file will moved to .RecycleBin/user1
2. recycle:keeptree = Yes
Specifies whether the directory structure should be kept or if the files in the directory that is being deleted should be ke
pt separately in the recycle bin.
3. recycle:touch = Yes
Specifies whether a file’s access date should be touched when the file is moved to the recycle bin.
4. recycle:versions = Yes
If this option is set, two files with the same name that are deleted will both be kept in the recycle bin. Newer deleted ver
sions of a file will be called “Copy #x of filename”.
5. recycle:maxsize = 0
Files that are larger than the number of bytes specified by this parameter will not be put into the recycle bin.
6. recycle:exclude = *.tmp
List of files that should not be put into the recycle bin when deleted, but deleted in the regular way.
7. recycle:exclude_dir = /tmp
Contains a list of directories. When files from these directories are deleted, they are not put into the recycle bin but are deleted in the regular way.
8. recycle:noversions = *.ppt
Specifies a list of paths (wildcards such as * and ? are supported) for which no versioning should be used. Only useful when recycle:versions is enabled.

”Changing Web Server Identity”

The basic principle of launching an attack against any website is to first get maximum information about the website regarding the web server used at the backend or the modules that have been compiled along with it or something else.This process particularly known as web server fingerprinting or banner grabbing is the basic test module that is run by most of the crawlers or vulnerability scanners based on which it identifies the vulnerabilities.So to secure the websites at the very first end , this article of mine helps to hide the server identity if the web server being used is apache.

What is Web Server Fingerprinting ?

As explained earlier, Web Server Fingerprinting is the process of knowing the basic details about the webserver and other essential options passed along with it during compilation.The information revealed can be helpful to website hackers in the way that through the knowledge of web server and its version being run , they can search for the vulnerabilities that do exist in these web servers and corresponding versions.These vulnerabilities can be easily found on the internet over the websites like www.secunia.com , cve.mitre.org and many more.Having said that much , lets come to the point of hiding the necessary information from being getting revealed.How this server and version informatin is obtained has been explained below:

secaudimachine# telnet localhost 80

HEAD / HTTP/1.0

After you telnet on port 80 of your local machine type the above and press two times enter.You would be getting the server along with version and much more.If you don’t get anything try with any of the following:

secaudimachine#telnet localhost 80
HEAD / HTTP /1.1

or

secaudimachine#telnet localhost 80

OPTIONS / HTTP/1.0

This example using the OPTIONS method even provides you the methods allowed on the web server and on the basis of this , many crawlers or scanners give the vulnerability of TRACE and TRACK method being enabled on the web server.

If you need to know the web server of some other website , just replace localhost with the name of the website.Even if you don’t want to do all this but still need to know the webserver or the version being run on the website , there are websites like www.netcraft.com which give you this basic information.

How to hide ?

Well there are many methods to do the same depending in which environment you feel comfortable making changes on your web server.Just to hide the very basic information play with the ServerTokens and ServerSignature directives , the information for which can be obtained from apache’s official website www.apache.org. However changes made in these directives have information revealed regarding web server used and its version through error pages and definitely through the telnet method explained below. So lets play with source code directly.

1. If you have been configuring any new server installing apache over it , then before compiling it just make the following changes:

For apache 1: In file httpd.h

Change the values of the following macros:

#define SERVER_BASEVENDOR “Apache Group”
#define SERVER_BASEPRODUCT “Apache”
#define SERVER_BASEREVISION “1.3.29″
#define SERVER_BASEVERSION SERVER_BASEPRODUCT “/” SERVER_BASEREVISION
#define SERVER_PRODUCT SERVER_BASEPRODUCT
#define SERVER_REVISION SERVER_BASEREVISION
#define SERVER_VERSION SERVER_PRODUCT “/” SERVER_REVISION

Make changes as you desire.For instance to get the name of webserver as SUMI on scanning ,just change the macro SERVER_BASEPRODUCT value to “SUMI” instead of “APACHE”. Similar for others.

For apache 2: In file ap_release.h

If you don’t want to change the identity in this manner ,then the another method is to make changes in a particular function which is :

For Apache 1 : ap_set_version() function in file http_main.c

static void ap_set_version(void)
{
/* set the server name */
ap_add_version_component(”Microsoft-IIS/5.0″);
/* do not allow other modules to add to it */
version_locked++;
}
Change the server name to whatever you desire

For Apache 2 : ap_set_version in file core.c

static void ap_set_version(apr_pool_t *pconf)
{
/* set the server name */
ap_add_version_component(pconf, “Microsoft-IIS/5.0″);
/* do not allow other modules to add to it */
version_locked++;
}
2. For those who have alredy thier web servers in running state and can’t afford the downtime involved in the above method , this method gonna work for them.

Through mod_securitymodule,the same information can be changed in runtime.The modules can be easily compiled in runtime using apxs binary and if you have already given the DSO functionality during compilation.As talked earlier about ServerTokens, this method requires its value to be set to Full , thus allowing full information from being revealed. Now what mod_security actually does is that it searches for the whole information in the memory and replaces it with the corresponding information provided by us.The ServerTokens when set to Full causes the webserver to allocate enough space for the name , giving mod_security enough space to make its changes later. Hence enter the following in the configuration file after the mod_security module has been loaded :

ServerTokens Full

SecServerSignature “Fogi”

All the product information is getting revealed since ServerTokens has been set to Full.But because of mod_security module , this value kept in the memory is replaced by the information provided in the SecServerSignature directive. Its simply that easy.

All the methods have been explained to hide the webserver identity.So go for the method which suits best for your web environment.

How to use Linux as Novell-Netware Client

IPX Protocol: IPX stands for Internetwork Packet Exchange. It is a networking protocol used by the Novell NetWare operating systems. Like UDP, IPX is a datagram protocol used for connectionless communications.

The IPX protocol stack is supported by Novell’s NetWare network operating system. Because of Netware’s popularity through the late 1980s into the mid 1990s, IPX became a popular internetworking protocol. Novell derived IPX from Xerox Network Services’ IDP protocol.

IPX Addressing: Logical networks are assigned a unique 32-bit hexadecimal address in the range of 0×1 – 0xFFFFFFFE.

Hosts have a 48-bit node address which by default is set to the network interface card’s MAC address. The node address is appended to the network address to create a unique identifier for the host on the network.

Similarities wih IP: The IPX network address is conceptually identical to the network part of the IP address (the parts with netmask bits set to 1); the node address then has the same meaning as the bits of IP address with netmask bits set to 0. As the node address is usually identical to the MAC address of the network adapter, the Address Resolution Protocol is not needed.

For routing, the entries in the IPX routing table are similar to IP routing tables; routing is done by network address, and for each network address a network:node of the next router is specified in a similar fashion an IP address/netmask is specified in IP routing tables.

IPX over Ethernet

IPX can be transmitted over Ethernet using one of the following 4 encapsulation types:

802.3 (raw)

802.2 (Novell)

802.2 (SNAP)

Ethernet II

For Linux to work as Novel Client we need a Kernel with IPX support. I have used kernel-2.6.20 but many previous versions have IPX support.

For IPX protocol we need ipx utilities to be installed on our Linux system. These utilities can be installed using rpm named “ipxutils”. I have used “ipxutils-2.2.6-7”.

NCPFS

Ncpfs is a filesystem which understands the Novell NetWare(TM) NCP protocol. Functionally, NCP is used for NetWare the way NFS is used in the TCP/IP world

For ncpfs functionality on Linux we need rpm named “ncpfs”. I have used “ncpfs-2.2.6-7”.

Configure the IPX network software

There are two ways of configuring the IPX network software. You can manually configure all of your IPX network information or you can choose to let the software determine for itself some reasonable settings using the command:

# ipx_configure –auto_interface=on –auto_primary=on
After your IPX network is configured you should be able to use the slist command to see a list of all of the Novell fileserver on your network:

# slist
If the slist command displays a message like: ncp_connect: Invalid argument then your kernel probably does not support IPX. In this case patch-up your kernel for IPX support or Install new kernal with IPX support. When you boot with kernel having IPX support you should see messages about ‘IPX‘ and ‘ncpfs‘ in the system startup messages.

If the slist command does not list all of your fileservers then you may need to use the manual network configuration method.

Or

Have a look at output of “ifconfig” command

eth1 Link encap:Ethernet HWaddr 00:C0:26:32:A2:11

inet addr:10.0.0.123 Bcast:10.0.0.255 Mask:255.255.255.0

inet6 addr: fe80::2c0:26ff:fe32:a211/64 Scope:Link

IPX/Ethernet 802.3 addr:00C02632A211

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:8538 errors:0 dropped:0 overruns:0 frame:0

TX packets:4622 errors:0 dropped:0 overruns:0 carrier:0

collisions:3 txqueuelen:1000

RX bytes:1347923 (1.2 MiB) TX bytes:4959973 (4.7 MiB)

Interrupt:20 Base address:0xdc00

Mount a Novell(TM) Volume

If your IPX network software is configured properly, you should now be able to mount a Novell volume into your Linux filesystem. The ncpmount command is used for this purpose you have to specify following information:

The fileserver name
The fileserver directory to mount (Optional)

The fileserver User id. If it is protected with a password then Password is also required.

The mount point. This will be an existing directory on your machine.

There is an equivalent ncpumount command to unmount a mounted NCP filesystem.

Various options of ncpmount command are as follows:

usage: ncpmount [options] mount-point

-S server Server name to be used

-A dns_name DNS server name to be used when mounting over TCP or UDP

-U username Username sent to server

-V volume Volume to mount, for NFS re-export

-u uid uid the mounted files get

-g gid gid the mounted files get

-f mode permission the files get (octal notation)

-d mode permission the dirs get (octal notation)

-c uid uid to identify the connection to mount on Only makes sense for root

-t time_out Waiting time (in 1/100s) to wait for an answer from the server. Default: 60

-r retry_count Number of retry attempts. Default: 5

-C Don’t convert password to uppercase

-P password Use this password

-n Do not use any password

If neither -P nor -n are given, you are asked for a password.

-s Enable renaming/deletion of read-only files

-h print this help text

-v print ncpfs version number

-b Force bindery login to NDS servers

-i level Signature level, 0=never, 1=supported, 2=preferred, 3=required

-m Allow multiple logins to server

-N os2,nfs Do not use specified namespaces on mounted volume

-y charset character set used for input and display

-p codepage codepage used on volume, including letters `cp’

Example:

Example command to mount fileserver SUMI_WEB, with a login id of “guest” with no password, under the “/mnt/web” directory

# ncpmount -S SUMI_WEB /mnt/web -U guest -n
Example command to mount fileserver SUMI_DEV, with a login id of “rdeep” with password, “secret” under the “/mnt/dev” directory

# ncpmount -S SUMI_DEV /mnt/dev -U rdeep -P secret
Configure mounts to be automatically performed
Make the following entries in file “/etc/rc.local”
————————————————–
# configure the IPX network
ipx_configure –auto_interface=on –auto_primary=on
# guest login to the Accounting fileserver
ncpmount -S SUMI_WEB /mnt/web -U guest -n

Website Traffic Statistics for Multiple virtual Hosts

This article of mine is dedicated towards the log processing for multiple virtual hosts (Name Based Sites). As we know almost every hosting server is having at least one hosting control panel installed on it, to control hosting services. Which will make all the jobs easy for maintaining each site on the server, including the per site based logging. But what if there is no control panel on the server and site owner is demanding for individual traffic statistics of its site.
There are different ways of doing that, but simplest one is configuring webalizer for multiple virtual hos. Let us design a simple scenario to proceed:
Assume that we have some virtual hosts (Name based sites)
1. alpha.secaudi.com with server access log file /var/log/httpd/access_log_alpha
2. beta.secaudi.com with server access log file /var/log/httpd/access_log_beta
3. gama.secaudi.com with server access log file /var/log/httpd/access_log_gama
and required is the individual traffic statistics for all these sites.
Create a centralized folder for webalizer configuration
# mkdir /etc/webalizer
Create individual webalizer configuration files for each site using sample configuration file
# cp /etc/webalizer.conf /etc/webalizer/alpha.secaudi.com.conf
# cp /etc/webalizer.conf /etc/webalizer/beta.secaudi.com.conf
# cp /etc/webalizer.conf /etc/webalizer/gama.secaudi.com.conf
Now create individual directories for usage for each site
# mkdir -p /var/www/usage/{alpha,beta,gama}
Modify individual webalizer configuration file for each site, for example: alpha.secaudi.com.conf
LogFile /var/log/httpd/access_log_alpha
OutputDir /var/www/usage/alpha
HostName alpha.secaudi.com
Similarly modify files for the other sites.
Run the following command to process webalizer statistics for each site
# webalizer -c alpha.secaudi.com
# webalizer -c beta.secaudi.com
# webalizer -c gama.secaudi.com
Required output will be in
/var/www/usage/alpha for alpha.secaudi.com
/var/www/usage/beta for beta.secaudi.com
/var/www/usage/gama for gama.secaudi.com
You can simplify this task if you are having large number of sites on your server
Write a small script named webstats.sh
# vi webstats.sh
for x in /etc/webalizer/*.conf
do
webalizer -c $x
done
required you should have configured webalizer configuration file for each virtual host.
Now you have to provide the URL to website owner by making soft link of usage directory in the DocumentRoot of that particular site.
For example: For alpha.secaudi.com, DocumentRoot is /var/www/html/aplha.secaudi.com
# ln -s /var/www/usage/alpha /var/www/html/aplha.secaudi.com/stats
So the usage URL is http://alpha.secaudi.com/stats
Do it for other virtual hosts accordingly.
!!! AND YOU HAVE DONE IT !!!

RPM compilation (step by step)

(A) Environment:

We are here taking the example of freetype, php and memory cache rpm packages:

Old specs:

freetype-2.2.1-21.el5_3

php-5.2.13-1.virt (and all the packages related of same version)

php-xcache-1.3.0-1.virt & php-pecl-memcache-2.2.5-2.virt

Updated(expected) Specs:

freetype-2.3.12-21.2.virt

php-5.2.14-2.virt (and all the packages related of same version)

php-xcache-1.3.0-2.virt & php-pecl-memcache-2.2.5-2.virt

(B) Procedure & Precautions:

1) The source packages should be from genuine regional sites.

e.g I downloaded freetype-2.2.21.src.rpm from Centos regional site (http://centos.mirrors.skynet.be/pub/centos/5.5/os/SRPMS/).

2) After extracting the src rpm packages, you will see respective tar packages (e.g freetype-2.2.1.tar.gz, freetype-devel-2.2.1.tar.gz etc.). Just replace that particular package with updated one.

3) Afterwards, extract every package (say freetype-2.2.1.tar.gz) and patch all the files with exact destination specified in .spec file in the root directory. Then exclude all the patch files out which have failed or shown confliction (either not compatible to this updated package or they are already patched). Then delete all the extracted packages (say freetype-2.2.1)

This spec file is basically the file that tells the rpm program where everything is, where to put everything, and any other scripts or commands that need to be run.

4)* *Place all the genuine patch files and the unpatched tar packages separately.

5)* *If you receive any ‘rpath_error’ related error then execute the rpm build command with QA_RPATHS=$[ 0x0001|howto:0x0010 ] prefix:

# QA_RPATHS=$[ 0x0001|howto:0x0010 ] rpmbuild -ba freetype.spec

6)* *Always remember whenever you are about to update some package then firstly check how many packages interact with this particular package and how severe its impact on environment after updation. I mean after this updation, other co-related packages might need upgradation or recompilation such that they could become compatible to updated version.

NOTE: Don’t ever perform anything forcefully because sometimes you usually unaware of its future effect.

(C) Common commands:

1) To extract a src rpm:

# rpm2cpio freetype-2.2.1-21.el5_2.src.rpm | cpio -idmv

2) How to install rpm-build utility (vital): # yum groupinstall “Development Tools”
# yum install rpmdevtools

# useradd makerpm

3) How to setup directory hierarchy to build rpms:

su – makerpm
rpmdev-setuptree
(It create five folders under rpmbuild folder which is locate at home directory) SPEC: contain spec file (manual).
SOURCES: * *contain packages, patches etc. except spec file (manual).

BUILD: is the directory where all building occurs by rpm-build command (after execution).

RPMS: is where RPM will put all binary RPMs when built (after execution).

SRPMS: is where all source RPMs will be put (after execution).

4) To build a rpm:

# su – makerpm

# cd rpmbuild/SPECS

# rpmbuild –ba freetype.spec

Note: There shouldn’t be any type of error during execution.

5) *To customize your .spec file:*

You can modify the spec file to behave the build according to your requirement (ie if you want gd support in freetype and in spec file gd support is disabled then you can modify to –enable-gd depending upon the package standards).

Although there are some certain changes:

i) You need to increase the release no. in every modification.

ii) You need to update the package “Version”.

iii) And most important, remove the entries of excludes patches.

(D) Steps for updating freetype:

a) First of all get the src rpm package and extract it.

b) Then replace the tar packages with desired updated packages. And extract them.

c) Now, perform the patch import process on the account of spec file and exclude the corrupted as well as the duplicate one.

d) Remove the extracted packages such that only legitimate patches as well as the intact tar packages should lie inside the directory.

e) Now move the modified spec file to “/home/makerpm/rpmbuild/SPECS” and rest of the content to “/home/makerpm/rpmbuild/SOURCES”

f) Now to produce your coveted rpm package, execute the “rpmbuild –ba freetype.spec” at “/home/makerpm/rpmbuild/SPECS”

g) Consequently, you can get the output rpm packages at “/home/makerpm/rpmbuild/RPMS” and srpms at “/home/makerpm/rpmbuild/RPMS”.

h)* *Now you should have all the freetype packages with updated versions (in my case it is “2.3.12-21.2.virt”)

(E) Steps for updating PHP:

a) Remove the build root directory after storing the RPMS and SRPMS folder:

# rm –rf /home/makerpm/rpmbuild

b) Perform [howto:(D) a-g ] steps and get the updated rpm packages.

c)* *Now you should have all the PHP packages with updated versions (in my case it is “5.2.14-2.virt”)

(F) Steps for updating dependent packages:

a) Repeat [howto:(E) a-b] steps.

Now you should have all the above rpms dependent packages with updated versions (in my case “php-xcache-1.3.0-2.virt” and “php-pecl-memcache-2.2.5-2.virt”)

(G) Updating all the build rpm packages at client end:

a) Execute this command:

rpm –Uvh php*.rpm

(A) Environment:

We are here taking the example of freetype, php and memory cache rpm packages:

Old specs:

freetype-2.2.1-21.el5_3

php-5.2.13-1.virt (and all the packages related of same version)

php-xcache-1.3.0-1.virt & php-pecl-memcache-2.2.5-2.virt

Updated(expected) Specs:

freetype-2.3.12-21.2.virt

php-5.2.14-2.virt (and all the packages related of same version)

php-xcache-1.3.0-2.virt & php-pecl-memcache-2.2.5-2.virt

(B) Procedure & Precautions:

1) The source packages should be from genuine regional sites.

e.g I downloaded freetype-2.2.21.src.rpm from Centos regional site (http://centos.mirrors.skynet.be/pub/centos/5.5/os/SRPMS/).

2) After extracting the src rpm packages, you will see respective tar packages (e.g freetype-2.2.1.tar.gz, freetype-devel-2.2.1.tar.gz etc.). Just replace that particular package with updated one.

3) Afterwards, extract every package (say freetype-2.2.1.tar.gz) and patch all the files with exact destination specified in .spec file in the root directory. Then exclude all the patch files out which have failed or shown confliction (either not compatible to this updated package or they are already patched). Then delete all the extracted packages (say freetype-2.2.1)

This spec file is basically the file that tells the rpm program where everything is, where to put everything, and any other scripts or commands that need to be run.

4)* *Place all the genuine patch files and the unpatched tar packages separately.

5)* *If you receive any ‘rpath_error’ related error then execute the rpm build command with QA_RPATHS=$[ 0x0001|howto:0x0010 ] prefix:

# QA_RPATHS=$[ 0x0001|0x0010 ] rpmbuild -ba freetype.spec

6)* *Always remember whenever you are about to update some package then firstly check how many packages interact with this particular package and how severe its impact on environment after updation. I mean after this updation, other co-related packages might need upgradation or recompilation such that they could become compatible to updated version.

NOTE: Don’t ever perform anything forcefully because sometimes you usually unaware of its future effect.

(C) Common commands:

1) To extract a src rpm:

# rpm2cpio freetype-2.2.1-21.el5_2.src.rpm | cpio –idmv

2) How to install rpm-build utility (vital): # yum groupinstall “Development Tools”
# yum groupinstall “Development Tools”
# useradd makerpm

3) How to setup directory hierarchy to build rpms:

su – makerpm
rpmdev-setuptree
(It create five folders under rpmbuild folder which is locate at home directory) SPEC: contain spec file (manual).
SOURCES: * *contain packages, patches etc. except spec file (manual).

BUILD: is the directory where all building occurs by rpm-build command (after execution).

RPMS: is where RPM will put all binary RPMs when built (after execution).

SRPMS: is where all source RPMs will be put (after execution).

4) To build a rpm:

# su – makerpm

# cd rpmbuild/SPECS

# rpmbuild –ba freetype.spec

Note: There shouldn’t be any type of error during execution.

5) *To customize your .spec file:*

You can modify the spec file to behave the build according to your requirement (ie if you want gd support in freetype and in spec file gd support is disabled then you can modify to –enable-gd depending upon the package standards).

Although there are some certain changes:

i) You need to increase the release no. in every modification.

ii) You need to update the package “Version”.

iii) And most important, remove the entries of excludes patches.

(D) Steps for updating freetype:

a) First of all get the src rpm package and extract it.

b) Then replace the tar packages with desired updated packages. And extract them.

c) Now, perform the patch import process on the account of spec file and exclude the corrupted as well as the duplicate one.

d) Remove the extracted packages such that only legitimate patches as well as the intact tar packages should lie inside the directory.

e) Now move the modified spec file to “/home/makerpm/rpmbuild/SPECS” and rest of the content to “/home/makerpm/rpmbuild/SOURCES”

f) Now to produce your coveted rpm package, execute the “rpmbuild –ba freetype.spec” at “/home/makerpm/rpmbuild/SPECS”

g) Consequently, you can get the output rpm packages at “/home/makerpm/rpmbuild/RPMS” and srpms at “/home/makerpm/rpmbuild/RPMS”.

h)* *Now you should have all the freetype packages with updated versions (in my case it is “2.3.12-21.2.virt”)

(E) Steps for updating PHP:

a) Remove the build root directory after storing the RPMS and SRPMS folder:

# rm –rf /home/makerpm/rpmbuild

b) Perform [howto:(D) a-g ] steps and get the updated rpm packages.

c)* *Now you should have all the PHP packages with updated versions (in my case it is “5.2.14-2.virt”)

(F) Steps for updating dependent packages:

a) Repeat [howto:(E) a-b] steps.

Now you should have all the above rpms dependent packages with updated versions (in my case “php-xcache-1.3.0-2.virt” and “php-pecl-memcache-2.2.5-2.virt”)

(G) Updating all the build rpm packages at client end:

a) Execute this command:

rpm –Uvh php*.rpm